dshmarket 1.77.0 → 1.78.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.
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Private npm registries, read from the same `.npmrc` files pnpm reads.
3
+ *
4
+ * pnpm already handles installs: it reads the profile's `.npmrc` and
5
+ * `~/.npmrc` itself, so nothing here touches how a package is installed. What
6
+ * pnpm cannot do is answer the market's OWN requests — update checks,
7
+ * versions, changelog, release age, compatibility — and those used to go to
8
+ * the download region's registry for every package. For `@acme/plugin` with
9
+ * `@acme:registry=https://npm.acme.internal/` in an `.npmrc`, that meant
10
+ * asking the public registry about a package it has never heard of.
11
+ *
12
+ * Two small rules fix that, and nothing else changes:
13
+ *
14
+ * - {@link registryFor}: a scoped package goes to its scope's registry; every
15
+ * other package keeps the registry the market was already using.
16
+ * - {@link authorizationFor}: a request to a registry that an `.npmrc` routes
17
+ * a scope to carries the credential the `.npmrc` holds for it.
18
+ *
19
+ * Precedence is the profile's `.npmrc` over `~/.npmrc`, per key.
20
+ *
21
+ * The unscoped `registry=` line is read from the PROFILE's `.npmrc` only. A
22
+ * profile `.npmrc` is deliberate configuration for that profile (a company
23
+ * registry for everything), so the market asks the same registry pnpm
24
+ * installs from. `~/.npmrc` is not read for it: it is the user's own file,
25
+ * shared with every other tool, and the market's default route stays the
26
+ * download region's. An administrator's policy `mirrors.npm` outranks both.
27
+ *
28
+ * Credentials are attached only to registries the profile configuration
29
+ * routes to (a scope, or that profile default), so a publish token for
30
+ * registry.npmjs.org in `~/.npmrc` is never sent by the market just because
31
+ * it exists.
32
+ *
33
+ * A credential never leaves this module except as the header value handed to
34
+ * {@link marketFetch}; nothing here logs one.
35
+ */
36
+ interface Credential {
37
+ /** Value for the Authorization header. */
38
+ header: string;
39
+ }
40
+ export interface NpmrcConfig {
41
+ /** `@scope` -> registry base URL, no trailing slash. */
42
+ scopes: Map<string, string>;
43
+ /** The unscoped `registry=`, no trailing slash; only meaningful from the profile's file. */
44
+ defaultRegistry?: string;
45
+ /** Nerf-darted registry (`//host/path/`) -> credential. */
46
+ credentials: Map<string, Credential>;
47
+ /** Variables a credential line referenced that are not set — names only. */
48
+ missingEnv: string[];
49
+ }
50
+ /** `//host[:port]/path/` form npm keys credentials by. */
51
+ export declare function nerfDart(url: string): string | null;
52
+ /**
53
+ * Parse one `.npmrc`. Lines are `key=value`; `;` and `#` start a comment line.
54
+ * `${NAME}` is expanded from `env`, as npm does; a line that needs a variable
55
+ * that is not set is dropped (and the name reported) rather than becoming an
56
+ * empty, wrong credential.
57
+ */
58
+ export declare function parseNpmrc(text: string, env?: NodeJS.ProcessEnv): NpmrcConfig;
59
+ /** The per-key union, `over` winning. */
60
+ export declare function mergeNpmrc(base: NpmrcConfig, over: NpmrcConfig): NpmrcConfig;
61
+ /** The registry for one package, given a config; `fallback` for everything else. */
62
+ export declare function registryIn(config: NpmrcConfig, name: string, fallback: string, defaultLocked?: boolean): string;
63
+ /**
64
+ * The Authorization header for a URL, or null. Only registries that some scope
65
+ * points at are eligible (see the module note), matched the way npm matches:
66
+ * the longest nerf-darted prefix of the URL.
67
+ */
68
+ export declare function authorizationIn(config: NpmrcConfig, url: string): string | null;
69
+ /** Tell this module which profile's `.npmrc` is the first one to read. */
70
+ export declare function setNpmrcProfileDir(dir: string | null): void;
71
+ /** Tests only. */
72
+ export declare function setNpmrcHome(dir: string | null): void;
73
+ /** The merged config in force: `~/.npmrc` first, the profile's over it. */
74
+ export declare function currentNpmrc(env?: NodeJS.ProcessEnv, now?: number): NpmrcConfig;
75
+ /** The registry the market should ask about `name`. */
76
+ export declare function registryFor(name: string, fallback: string): string;
77
+ /** Authorization header for a URL on a scope-routed registry, or null. */
78
+ export declare function authorizationFor(url: string): string | null;
79
+ export {};
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Offline bundles: a catalog plus the package files it lists, in one archive,
3
+ * for machines that cannot reach npm at all.
4
+ *
5
+ * Layout of a bundle (made by scripts/offline-pack.mjs):
6
+ *
7
+ * plugins.json the catalog; each entry carries `tarball: "./tarballs/<file>.tgz"`
8
+ * tarballs/<file>.tgz the package files, one per entry
9
+ *
10
+ * Importing one is the only place the market unpacks an archive it did not
11
+ * make, so the rules here are strict and boring:
12
+ *
13
+ * - Only regular files. A link, device or directory-traversal name anywhere
14
+ * in the archive refuses the whole import; nothing is half-extracted.
15
+ * - Only the two places above: `plugins.json` at the top and `*.tgz` files
16
+ * under `tarballs/`. Anything else is refused rather than ignored.
17
+ * - Size and count limits, on the way in and after decompression.
18
+ * - Extracted into a temporary directory and moved into place only when the
19
+ * whole archive passed; a failure leaves nothing behind.
20
+ *
21
+ * A tarball path in a catalog is resolved by {@link resolveBundleFile}: it must
22
+ * be that exact shape, and the file it names must be a plain file inside the
23
+ * bundle's own directory — never a link out, never an absolute path.
24
+ */
25
+ /** Where imported bundles live: `<DSH_HOME>/dsh-market/offline/<id>/`. */
26
+ export declare function offlineRoot(env?: Record<string, string | undefined>): string;
27
+ /** Whether `path` is inside the imported-bundles directory. */
28
+ export declare function isInsideOfflineRoot(path: string, env?: Record<string, string | undefined>): boolean;
29
+ export declare const MAX_BUNDLE_BYTES: number;
30
+ export declare const MAX_BUNDLE_FILES = 2000;
31
+ /**
32
+ * The absolute path a catalog entry's `tarball` names, or null when it is not
33
+ * a plain file strictly inside `baseDir`. Never trusts the string: the shape
34
+ * is fixed, and the result is checked on disk after resolving links.
35
+ */
36
+ export declare function resolveBundleFile(baseDir: string, relative: unknown): string | null;
37
+ export declare class BundleError extends Error {
38
+ readonly code: 'too-big' | 'not-archive' | 'unsafe' | 'layout' | 'empty';
39
+ readonly detail: string;
40
+ constructor(code: BundleError['code'], detail: string);
41
+ }
42
+ export interface ExtractedBundle {
43
+ id: string;
44
+ dir: string;
45
+ /** Absolute path of the catalog inside the bundle. */
46
+ catalogFile: string;
47
+ files: number;
48
+ }
49
+ /**
50
+ * Unpack a bundle into `<root>/<id>/`, or throw {@link BundleError} having
51
+ * written nothing. `id` is derived from the content, so importing the same
52
+ * bundle twice is one directory, and importing a newer one replaces it.
53
+ */
54
+ export declare function extractBundle(archive: Buffer, root?: string): ExtractedBundle;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * The organization policy file: admin-owned, read-only, never written here.
3
+ *
4
+ * Where it lives, first found wins:
5
+ * 1. `DSH_MARKET_POLICY` (an absolute path)
6
+ * 2. macOS / Linux `/etc/dsh-market/policy.json`;
7
+ * Windows `%ProgramData%\dsh-market\policy.json`
8
+ * 3. `<DSH_HOME>/dsh-market/policy.json`
9
+ *
10
+ * "Employees cannot change it" comes from file permissions on 1 and 2 (a file
11
+ * only an administrator can write). Location 3 sits in the user's own home, so
12
+ * it is for single-user setups and enforces nothing against the user.
13
+ *
14
+ * Every field is optional and an absent file means "no policy": the
15
+ * permissive {@link NO_POLICY}, which is what keeps the market exactly as it
16
+ * was for everyone who configures nothing.
17
+ *
18
+ * Adding a field later (pins, telemetry, comments, externalImages) is one
19
+ * entry in {@link readPolicyFields} and one property on {@link Policy}; the
20
+ * location, caching and failure handling below do not change.
21
+ *
22
+ * ## A policy that cannot be read
23
+ *
24
+ * An unreadable file must not quietly turn into "no policy": an administrator
25
+ * who wrote one expects it to hold. So a file that exists but is not valid
26
+ * JSON applies `allow: []` — browsing keeps working, installing is refused —
27
+ * and says so in {@link Policy.problems} so the settings list can show it.
28
+ * A single bad field is ignored on its own and reported; only `allow` fails
29
+ * closed, since a malformed allowlist read as "no allowlist" is the unsafe
30
+ * direction.
31
+ */
32
+ /** Text for the languages the market ships, with a fallback for the rest. */
33
+ export type LocalizedLabel = Record<string, string>;
34
+ /** One catalog the policy adds. Headers hold secrets: never log or send them anywhere. */
35
+ export interface PolicyCatalog {
36
+ id: string;
37
+ label: LocalizedLabel;
38
+ url?: string;
39
+ file?: string;
40
+ /** Raw, `${ENV}` still unexpanded; expand at request time with {@link expandEnv}. */
41
+ headers: Record<string, string>;
42
+ }
43
+ export interface PolicyMirrors {
44
+ catalog?: string;
45
+ npm?: string;
46
+ githubProxy?: string;
47
+ }
48
+ export interface Policy {
49
+ /** The file this came from, or null when there is no policy. */
50
+ path: string | null;
51
+ catalogs: PolicyCatalog[];
52
+ publicCatalog: boolean;
53
+ userCatalogs: boolean;
54
+ /** Glob list (`*` only); null means "anything that is listed". */
55
+ allow: string[] | null;
56
+ mirrors: PolicyMirrors;
57
+ /** npm package name -> the one version to install; updates are offered only up to it. */
58
+ pins: Record<string, string>;
59
+ /** false = the anonymous daily count is forced off and its switch locked. */
60
+ telemetry: boolean;
61
+ /** false = no comment threads (no giscus, no GitHub contact). */
62
+ comments: boolean;
63
+ /** false = no images from outside hosts (screenshots, avatars, README images, icons). */
64
+ externalImages: boolean;
65
+ /** Plain-language problems with the file, for the settings list. */
66
+ problems: PolicyProblem[];
67
+ }
68
+ /** One problem, said in both languages the file's administrator might read. */
69
+ export interface PolicyProblem {
70
+ zh: string;
71
+ en: string;
72
+ }
73
+ export declare const NO_POLICY: Policy;
74
+ export declare const CATALOG_ID_RE: RegExp;
75
+ /** The public catalog's own id: reserved, so a private source can never pose as it. */
76
+ export declare const PUBLIC_SOURCE_ID = "public";
77
+ /** Candidate policy files in precedence order. */
78
+ export declare function policyLocations(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, home?: string): string[];
79
+ /** A label is a string or a per-language object; anything else is no label. */
80
+ export declare function asLabel(value: unknown): LocalizedLabel | null;
81
+ /** The label to show for a language: that language, then English, then anything. */
82
+ export declare function pickLabel(label: LocalizedLabel, lang: string): string;
83
+ /** The exact version an administrator pinned this npm package to, if any. */
84
+ export declare function pinnedVersion(name: string | null | undefined, policy?: Policy): string | undefined;
85
+ /** Interpret a parsed policy document. Pure. */
86
+ export declare function readPolicyFields(doc: unknown, path: string): Policy;
87
+ /** Read the first policy file that exists. Pure apart from the file reads. */
88
+ export declare function loadPolicy(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, home?: string): Policy;
89
+ /**
90
+ * The policy in force, re-read when the file changes. A stat per couple of
91
+ * seconds rather than per request: the callers sit on hot paths (every
92
+ * outbound request asks for the mirrors).
93
+ */
94
+ export declare function getPolicy(env?: NodeJS.ProcessEnv, now?: number): Policy;
95
+ /** Forget the cached policy (tests, and after a deliberate re-read). */
96
+ export declare function resetPolicyCache(): void;
97
+ /**
98
+ * Expand `${NAME}` from the environment, the way npm does. Names with no value
99
+ * are reported rather than silently becoming empty, so the caller can say
100
+ * which variable is missing instead of sending a half-made credential.
101
+ */
102
+ export declare function expandEnv(text: string, env?: NodeJS.ProcessEnv): {
103
+ value: string;
104
+ missing: string[];
105
+ };
106
+ /** Glob match with `*` only, case-insensitive (npm names are lowercase). */
107
+ export declare function globMatch(pattern: string, text: string): boolean;
108
+ /**
109
+ * What the browser needs to know to reflect the policy: only the switches an
110
+ * administrator turned OFF. Empty — and so absent from the response — for
111
+ * everyone with no policy. The server enforces; the page only follows.
112
+ */
113
+ export declare function clientPolicy(policy?: Policy): {
114
+ externalImages?: false;
115
+ comments?: false;
116
+ };
@@ -108,6 +108,8 @@ export declare function catalogSourcesFor(region: Region): CatalogSource[];
108
108
  export declare function normalizeGithubProxy(value: unknown): string | null;
109
109
  /** Apply (or clear) the persisted UI escape route. */
110
110
  export declare function setCustomGithubProxy(proxy: string | null): void;
111
+ /** Whether an administrator's policy (not just the environment) fixed the GitHub route. */
112
+ export declare function githubProxyByPolicy(): boolean;
111
113
  /** Whether the operator-owned environment variable disables UI changes. */
112
114
  export declare function githubProxyManaged(env?: NodeJS.ProcessEnv): boolean;
113
115
  /** Remember one verified route without changing other GitHub services. */
@@ -3,6 +3,7 @@
3
3
  * revalidates the catalog with its source.
4
4
  */
5
5
  import { type Region } from './regions.ts';
6
+ import { type SourceInfo } from './catalogs.ts';
6
7
  export interface RegistryPlugin {
7
8
  name: string;
8
9
  owner: string;
@@ -50,6 +51,32 @@ export interface RegistryPlugin {
50
51
  icon?: string | null;
51
52
  install: string;
52
53
  added: string;
54
+ /**
55
+ * Which catalog this entry came from. Present ONLY on entries from a
56
+ * catalog the organization or the user added; the public catalog's entries
57
+ * carry none, so a plain install looks exactly as it always did. Stamped by
58
+ * the market after merging, never taken from a catalog's own text.
59
+ */
60
+ source?: {
61
+ id: string;
62
+ label: Record<string, string>;
63
+ };
64
+ /**
65
+ * Internal repository to install from (`git+https://…#ref`, `git+ssh://…`).
66
+ * Honored only on an entry from an added catalog — the market stamps
67
+ * `source` itself — and never taken from a request.
68
+ */
69
+ git?: string;
70
+ /**
71
+ * Absolute path of a package file that ships with an offline bundle. Set by
72
+ * the market while reading a file catalog, after checking it lies inside
73
+ * that catalog's own directory; a catalog's own text cannot set it.
74
+ */
75
+ offlineTarball?: string;
76
+ /** The version an administrator's policy fixed this entry to. */
77
+ pinned?: string;
78
+ /** Curated screenshot URLs. */
79
+ screenshots?: string[];
53
80
  /**
54
81
  * Catalog-side deprecation flags (#60): supplied by awesome-dsh-plugin,
55
82
  * absent for every normal entry — the market only consumes them, so a
@@ -102,6 +129,8 @@ export interface Registry {
102
129
  count: number;
103
130
  categories: Record<string, Record<string, string>>;
104
131
  plugins: RegistryPlugin[];
132
+ /** Per-source status; present only when more than the public catalog is configured. */
133
+ sources?: SourceInfo[];
105
134
  }
106
135
  /**
107
136
  * Former npm names for one catalog entry, normalized (#1012).
@@ -120,26 +149,21 @@ export declare function pluginPreviousNpm(plugin: Pick<RegistryPlugin, 'name' |
120
149
  * unconditional request. Earlier callers can still receive their own result.
121
150
  */
122
151
  export declare function forgetCatalog(): void;
152
+ /** Every source failed (or the only one did): the message for the page, and what each source said. */
153
+ export declare class CatalogLoadError extends Error {
154
+ readonly sources: SourceInfo[];
155
+ constructor(message: string, sources: SourceInfo[]);
156
+ }
123
157
  /**
124
- * The catalog, revalidated on each new load. Discovery and the update check
125
- * share a revalidation while it is in flight for the same configured sources.
126
- *
127
- * There used to be three answers here — live, a one-hour in-memory cache,
128
- * and a snapshot bundled into the npm package — and only the first was
129
- * correct. The other two were indistinguishable from it on screen, so a
130
- * machine that could not reach the registry browsed the publish-time file
131
- * (839 entries against 1367 live, and frozen forever for anyone on an older
132
- * release), while a machine that COULD reach it still saw an hour-old
133
- * listing of a catalog that grows by ~250 entries a day.
158
+ * The catalog, revalidated on each new load: the public catalog plus whatever
159
+ * the organization's policy and the user added.
134
160
  *
135
- * For a catalog, stale is not a degraded answer, it is a wrong one: a plugin
136
- * published this morning reads as "does not exist". So there is one source
137
- * now, and a failure is a failure — the caller reports it and offers a
138
- * retry, which is a state the user can act on. In particular a network
139
- * failure is NEVER answered from `served`: an origin that cannot be reached
140
- * has not confirmed anything, and quietly handing back the last catalog
141
- * would rebuild exactly the fallback this replaced.
142
- * @throws when the catalog cannot be fetched or does not look like one.
161
+ * With nothing configured this IS {@link loadPublicCatalog} — the same
162
+ * requests, the same object — which is the promise that a user with no policy
163
+ * and no extra catalogs sees no change. Otherwise every source is read on its
164
+ * own, in parallel: one that fails costs the user that source and is reported
165
+ * in `sources`, never the others.
166
+ * @throws when nothing could be loaded; {@link CatalogLoadError} carries the per-source detail.
143
167
  */
144
168
  export declare function loadRegistry(region?: Region): Promise<Registry>;
145
169
  /**
@@ -231,6 +231,9 @@ export declare function installTargetFor(entry: {
231
231
  url: string;
232
232
  npm?: unknown;
233
233
  tarball?: unknown;
234
+ source?: unknown;
235
+ git?: unknown;
236
+ offlineTarball?: unknown;
234
237
  }): string | null;
235
238
  export interface CatalogReleaseSource {
236
239
  repo: string;
@@ -244,6 +244,8 @@ export declare function latestPublishedRecently(name: string, windowMs?: number)
244
244
  */
245
245
  export declare function versionOnChannel(name: string, channel: Channel, stable: string | null): Promise<string | null>;
246
246
  export declare function fetchNpmLatest(name: string): Promise<string | null>;
247
+ /** What the registry itself calls `latest`, whatever a pin says (the desktop path checks the registry's identity against it). */
248
+ export declare function fetchRegistryLatest(name: string): Promise<string | null>;
247
249
  /**
248
250
  * The newest build above `installed` that some tag other than `latest`
249
251
  * points at, or null (#867).
package/lib/updates.js CHANGED
@@ -11,6 +11,8 @@ import { DIST_TAG } from './channels.js';
11
11
  import { resolveHeadCommit } from './accelerate.js';
12
12
  import { inProbe } from './probe-context.js';
13
13
  import { marketFetch } from './net.js';
14
+ import { registryFor } from './npmrc.js';
15
+ import { pinnedVersion } from './policy.js';
14
16
  import { publishedReleaseUpdate } from './release-updates.js';
15
17
  import { activeRegion, githubRoutesFor, rememberGithubRoute, throughProxy } from './regions.js';
16
18
  import { isNumericReleaseAgeWindow, readMinimumReleaseAgeMs } from './install.js';
@@ -213,7 +215,14 @@ export function setUpdateRegistry(base) {
213
215
  }
214
216
  /** A registry URL for `path`, on whichever registry is currently in force. */
215
217
  function npmUrl(path) {
216
- return `${registryBase}/${path}`;
218
+ // The first segment is the encoded package name. A scope an `.npmrc` routes
219
+ // to a private registry is asked there, not on the region's registry.
220
+ let name = '';
221
+ try {
222
+ name = decodeURIComponent(path.split('/')[0] ?? '');
223
+ }
224
+ catch { /* leave the default registry */ }
225
+ return `${name === '' ? registryBase : registryFor(name, registryBase)}/${path}`;
217
226
  }
218
227
  /** Read observable profile policy; do not infer effective external settings. */
219
228
  function readReleaseAgeExclusions(dir, name) {
@@ -541,6 +550,14 @@ async function tagVersion(name, tag) {
541
550
  }
542
551
  }
543
552
  export async function fetchNpmLatest(name) {
553
+ // An administrator's pin IS the newest release this machine may be offered.
554
+ const pin = pinnedVersion(name);
555
+ if (pin !== undefined)
556
+ return pin;
557
+ return await fetchRegistryLatest(name);
558
+ }
559
+ /** What the registry itself calls `latest`, whatever a pin says (the desktop path checks the registry's identity against it). */
560
+ export async function fetchRegistryLatest(name) {
544
561
  try {
545
562
  const meta = (await fetchJson(npmUrl(`${encodeURIComponent(name)}/latest`)));
546
563
  if (typeof meta.version === 'string')
@@ -942,10 +959,14 @@ options = {}) {
942
959
  }
943
960
  }
944
961
  const meta = (await fetchJson(npmUrl(`${encodeURIComponent(name)}/latest`), true));
945
- const stable = typeof meta?.version === 'string' && parseSemver(meta.version) !== null ? meta.version : null;
946
- if (meta !== undefined && stable === null)
962
+ const registryStable = typeof meta?.version === 'string' && parseSemver(meta.version) !== null ? meta.version : null;
963
+ if (meta !== undefined && registryStable === null)
947
964
  throw new Error('npm latest response has no valid version');
948
- const channel = channelFor.get(name);
965
+ // A pin from the organization's policy replaces what the registry
966
+ // calls newest, and a channel cannot go past it.
967
+ const pin = pinnedVersion(name);
968
+ const stable = pin ?? registryStable;
969
+ const channel = pin !== undefined ? undefined : channelFor.get(name);
949
970
  const latest = channel === undefined ? stable : await versionOnChannel(name, channel, stable);
950
971
  // Forwards is an update; a difference in the other direction is a
951
972
  // channel switch and is reported as one, under its own field.
@@ -974,7 +995,7 @@ options = {}) {
974
995
  && isStableReleaseVersion(version)
975
996
  && !/^https?:/i.test(spec) && !spec.includes(':') && !spec.includes('/');
976
997
  const mature = desktopStable && upgrade
977
- ? await resolveDesktopMatureUpdate(name, version, profile, activeProfileDir, stable)
998
+ ? await resolveDesktopMatureUpdate(name, version, profile, activeProfileDir, registryStable, pin)
978
999
  : null;
979
1000
  if (mature?.nextMaturityAt !== null && mature?.nextMaturityAt !== undefined) {
980
1001
  nextCandidateMaturityAt = Math.min(nextCandidateMaturityAt, mature.nextMaturityAt);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dshmarket",
3
3
  "description": "Visual plugin market inside DeepSeek Harness — browse, search, and one-click install community plugins. · DSH 可视化插件市场:逛一逛,点一下,装好。",
4
- "version": "1.77.0",
4
+ "version": "1.78.0",
5
5
  "icon": "assets/logo.svg",
6
6
  "type": "module",
7
7
  "main": "lib/index.js",