dsh-crate 0.0.0-stage → 0.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.
Files changed (132) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +288 -2
  3. package/README.zh.md +263 -0
  4. package/UPDATE-API-V1.md +207 -0
  5. package/assets/logo.svg +37 -0
  6. package/client/client.js +18964 -0
  7. package/cordis.patch.yml +4 -0
  8. package/lib/accelerate.js +194 -0
  9. package/lib/agents.js +67 -0
  10. package/lib/backup.js +688 -0
  11. package/lib/body-progress.js +173 -0
  12. package/lib/catalog-local-match.js +160 -0
  13. package/lib/catalog-npm.js +180 -0
  14. package/lib/changelog.js +462 -0
  15. package/lib/channels.js +64 -0
  16. package/lib/check.js +1557 -0
  17. package/lib/compatibility.js +243 -0
  18. package/lib/crate-catalog.js +179 -0
  19. package/lib/diagnostics.js +49 -0
  20. package/lib/discovery-compatibility.js +447 -0
  21. package/lib/drain-journal.js +164 -0
  22. package/lib/drain.js +1043 -0
  23. package/lib/dsh-cli.js +1373 -0
  24. package/lib/dsh-install.js +259 -0
  25. package/lib/entry-identity.js +85 -0
  26. package/lib/gist.js +369 -0
  27. package/lib/groups.js +108 -0
  28. package/lib/home-paths.js +29 -0
  29. package/lib/host-recovery.js +187 -0
  30. package/lib/hot.js +871 -0
  31. package/lib/http.js +252 -0
  32. package/lib/index.js +394 -0
  33. package/lib/install.js +1147 -0
  34. package/lib/lifecycle.js +37 -0
  35. package/lib/log-redaction.js +24 -0
  36. package/lib/log.js +204 -0
  37. package/lib/ndjson.js +154 -0
  38. package/lib/net.js +174 -0
  39. package/lib/official-desktop.js +619 -0
  40. package/lib/order.js +284 -0
  41. package/lib/patch.js +943 -0
  42. package/lib/pending-rows.js +142 -0
  43. package/lib/pending-updates.js +346 -0
  44. package/lib/pnpm-compat.js +972 -0
  45. package/lib/presets.js +282 -0
  46. package/lib/probe-context.js +20 -0
  47. package/lib/proc-text.js +69 -0
  48. package/lib/profile.js +1978 -0
  49. package/lib/recovery.js +1059 -0
  50. package/lib/region-probe.js +93 -0
  51. package/lib/regions.js +283 -0
  52. package/lib/registry.js +308 -0
  53. package/lib/release-candidates.js +115 -0
  54. package/lib/release-updates.js +70 -0
  55. package/lib/restart.js +688 -0
  56. package/lib/routes.js +7960 -0
  57. package/lib/settings.js +164 -0
  58. package/lib/shelfry-catalog.js +179 -0
  59. package/lib/snapshot.js +506 -0
  60. package/lib/source-migration.js +164 -0
  61. package/lib/sources.js +1005 -0
  62. package/lib/state.js +38 -0
  63. package/lib/store.js +163 -0
  64. package/lib/themes.js +350 -0
  65. package/lib/trial.js +125 -0
  66. package/lib/types/accelerate.d.ts +85 -0
  67. package/lib/types/agents.d.ts +52 -0
  68. package/lib/types/backup.d.ts +171 -0
  69. package/lib/types/body-progress.d.ts +94 -0
  70. package/lib/types/catalog-local-match.d.ts +39 -0
  71. package/lib/types/catalog-npm.d.ts +77 -0
  72. package/lib/types/changelog.d.ts +131 -0
  73. package/lib/types/channels.d.ts +56 -0
  74. package/lib/types/check.d.ts +353 -0
  75. package/lib/types/compatibility.d.ts +83 -0
  76. package/lib/types/crate-catalog.d.ts +48 -0
  77. package/lib/types/diagnostics.d.ts +29 -0
  78. package/lib/types/discovery-compatibility.d.ts +145 -0
  79. package/lib/types/drain-journal.d.ts +25 -0
  80. package/lib/types/drain.d.ts +306 -0
  81. package/lib/types/dsh-cli.d.ts +481 -0
  82. package/lib/types/dsh-install.d.ts +106 -0
  83. package/lib/types/entry-identity.d.ts +68 -0
  84. package/lib/types/gist.d.ts +79 -0
  85. package/lib/types/groups.d.ts +34 -0
  86. package/lib/types/home-paths.d.ts +13 -0
  87. package/lib/types/host-recovery.d.ts +95 -0
  88. package/lib/types/hot.d.ts +405 -0
  89. package/lib/types/http.d.ts +114 -0
  90. package/lib/types/index.d.ts +52 -0
  91. package/lib/types/install.d.ts +463 -0
  92. package/lib/types/lifecycle.d.ts +14 -0
  93. package/lib/types/log-redaction.d.ts +2 -0
  94. package/lib/types/log.d.ts +43 -0
  95. package/lib/types/ndjson.d.ts +52 -0
  96. package/lib/types/net.d.ts +94 -0
  97. package/lib/types/official-desktop.d.ts +59 -0
  98. package/lib/types/order.d.ts +100 -0
  99. package/lib/types/patch.d.ts +218 -0
  100. package/lib/types/pending-rows.d.ts +81 -0
  101. package/lib/types/pending-updates.d.ts +161 -0
  102. package/lib/types/pnpm-compat.d.ts +102 -0
  103. package/lib/types/presets.d.ts +94 -0
  104. package/lib/types/probe-context.d.ts +14 -0
  105. package/lib/types/proc-text.d.ts +29 -0
  106. package/lib/types/profile.d.ts +551 -0
  107. package/lib/types/recovery.d.ts +342 -0
  108. package/lib/types/region-probe.d.ts +50 -0
  109. package/lib/types/regions.d.ts +134 -0
  110. package/lib/types/registry.d.ts +160 -0
  111. package/lib/types/release-candidates.d.ts +42 -0
  112. package/lib/types/release-updates.d.ts +15 -0
  113. package/lib/types/restart.d.ts +279 -0
  114. package/lib/types/routes.d.ts +130 -0
  115. package/lib/types/settings.d.ts +112 -0
  116. package/lib/types/shelfry-catalog.d.ts +48 -0
  117. package/lib/types/snapshot.d.ts +93 -0
  118. package/lib/types/source-migration.d.ts +100 -0
  119. package/lib/types/sources.d.ts +391 -0
  120. package/lib/types/state.d.ts +20 -0
  121. package/lib/types/store.d.ts +47 -0
  122. package/lib/types/themes.d.ts +46 -0
  123. package/lib/types/trial.d.ts +61 -0
  124. package/lib/types/update-api-v1.d.ts +83 -0
  125. package/lib/types/updates.d.ts +273 -0
  126. package/lib/types/verify.d.ts +277 -0
  127. package/lib/update-api-v1.js +273 -0
  128. package/lib/updates.js +981 -0
  129. package/lib/verify.js +904 -0
  130. package/locale/en.json +5 -0
  131. package/locale/zh.json +6 -0
  132. package/package.json +113 -4
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Deciding a download region by asking the network, once.
3
+ *
4
+ * The alternative was reading the system time zone, and it is wrong for
5
+ * exactly the people who most need this to work: someone in Shanghai behind
6
+ * a corporate proxy or a VPN reaches the official registry perfectly well
7
+ * and would be routed onto mirrors they do not need, while a Chinese-locale
8
+ * machine sitting in Singapore would be routed onto mirrors that are further
9
+ * away than the origin. A time zone says where a clock is. It does not say
10
+ * what the network can reach, which is the only question here.
11
+ *
12
+ * So the probe measures the thing itself: it asks both registries for the
13
+ * same small document and takes whichever answers first. That is
14
+ * self-correcting in a way a lookup table cannot be — the machine behind the
15
+ * proxy measures fast official access and stays global, without anyone
16
+ * having to enumerate the exceptions.
17
+ *
18
+ * It runs ONCE, when no region has ever been decided, and its answer is
19
+ * persisted as the decision. Re-probing every boot would let a market
20
+ * silently change routes between runs, which is the kind of behaviour that
21
+ * makes "it was fast yesterday" impossible to debug.
22
+ */
23
+ import { logEvent } from './log.js';
24
+ import { marketFetch } from './net.js';
25
+ import { REGIONS, routesFor } from './regions.js';
26
+ /**
27
+ * What to ask each registry for.
28
+ *
29
+ * The market's own package: present on every npm mirror worth using, and
30
+ * small — the `latest` document is a few KB, against ~320KB for the full
31
+ * packument. A probe that downloads a third of a megabyte to answer "which
32
+ * of these is closer" has spent more than the answer is worth.
33
+ */
34
+ const PROBE_PATH = 'dsh-crate/latest';
35
+ /**
36
+ * Ask every region's registry the same question; return whichever answers
37
+ * first.
38
+ *
39
+ * First-past-the-post rather than a latency comparison, deliberately. From
40
+ * inside China the official registry usually does answer eventually, so
41
+ * "did it fail" is the wrong test and "which came back first" is the right
42
+ * one. From outside, the mainland mirror is reachable but further, and the
43
+ * same rule picks global. One rule, both directions, no thresholds to tune.
44
+ *
45
+ * @param timeoutMs - how long to wait before giving up on all of them.
46
+ * @param env - environment, for the registry overrides.
47
+ * @returns the winning region, or `global` when nothing answered — an
48
+ * unreachable network is not evidence for switching routes.
49
+ */
50
+ export async function probeRegion(timeoutMs = 2500, env = process.env) {
51
+ const controller = new AbortController();
52
+ const timer = setTimeout(() => { controller.abort(); }, timeoutMs);
53
+ const ask = async (region) => {
54
+ const base = routesFor(region, env).npmRegistry;
55
+ const res = await marketFetch(`${base}/${PROBE_PATH}`, {
56
+ signal: controller.signal,
57
+ headers: { accept: 'application/json', 'user-agent': 'dsh-crate' },
58
+ });
59
+ if (!res.ok)
60
+ throw new Error(`HTTP ${String(res.status)}`);
61
+ // Read the body before declaring a winner. Headers can arrive from a
62
+ // captive portal or a proxy that then stalls, and a region chosen on a
63
+ // response that never finished would be chosen on nothing.
64
+ await res.arrayBuffer();
65
+ return region;
66
+ };
67
+ try {
68
+ return await Promise.any(REGIONS.map(ask));
69
+ }
70
+ catch {
71
+ return 'global';
72
+ }
73
+ finally {
74
+ clearTimeout(timer);
75
+ // Stop the losers. Their answer can no longer change anything, and a
76
+ // request left running past the decision is a request nobody will read.
77
+ controller.abort();
78
+ }
79
+ }
80
+ /**
81
+ * The region to run under, probing only if nothing has ever decided one.
82
+ *
83
+ * @param stored - the region already on record, or undefined.
84
+ * @returns the region, and whether this call decided it (which is what earns
85
+ * the user a one-time notice explaining the choice).
86
+ */
87
+ export async function resolveRegion(stored, timeoutMs, env) {
88
+ if (stored !== undefined)
89
+ return { region: stored, probed: false };
90
+ const region = await probeRegion(timeoutMs, env);
91
+ logEvent('info', 'region', `no region on record; network check chose ${region}`);
92
+ return { region, probed: true };
93
+ }
package/lib/regions.js ADDED
@@ -0,0 +1,283 @@
1
+ /**
2
+ * Download regions: which route the market's own network requests take.
3
+ *
4
+ * Almost every external request the market makes lands on npm's registry or
5
+ * on GitHub — the plugin catalog, update checks, package downloads, author
6
+ * avatars, README screenshots. From mainland China several of those can be
7
+ * slow, which is why this is ONE setting rather than a
8
+ * row of them: "npm mirror", "GitHub proxy" and "image proxy" are three
9
+ * spellings of a single question the user is actually being asked, which is
10
+ * where they are.
11
+ *
12
+ * The routing table is the single source of truth. Every consumer asks it
13
+ * rather than reaching for a hardcoded host, so adding a region is a table
14
+ * entry instead of a search across six modules.
15
+ *
16
+ * Each route has an environment escape hatch, following `DSHM_REGISTRY_URL`
17
+ * (src/registry.ts). The China route has service-specific public-proxy
18
+ * fallbacks; those come and go, and a user whose routes have died needs a way
19
+ * out that is not "wait for the next release".
20
+ */
21
+ /** Every region a user may pick. */
22
+ export const REGIONS = ['global', 'china'];
23
+ /** Narrow an untrusted value to a Region, or null. */
24
+ export function asRegion(value) {
25
+ return value === 'global' || value === 'china' ? value : null;
26
+ }
27
+ /**
28
+ * The npm registry the market and pnpm read, no trailing slash.
29
+ *
30
+ * Exported because callers need to tell "this region uses the default" from
31
+ * "this region names a mirror" — the difference between leaving a spawned
32
+ * pnpm's registry alone and setting it.
33
+ */
34
+ export const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org';
35
+ /**
36
+ * Default npm registry for the China download region, no trailing slash.
37
+ *
38
+ * Exported so failure classifiers can recognize this host in pnpm's output
39
+ * (#926) without duplicating the URL.
40
+ */
41
+ export const CHINA_NPM_REGISTRY = 'https://mirrors.cloud.tencent.com/npm';
42
+ const NPM_CHINA = CHINA_NPM_REGISTRY;
43
+ /**
44
+ * Second China npm mirror, used only as a catalog fallback (#1051), no
45
+ * trailing slash.
46
+ *
47
+ * The catalog list named the Tencent mirror and the origin and nothing else,
48
+ * so a network that blocks or outranks one of them lost both: a corporate
49
+ * egress proxy refusing that host (measured: HTTP 522/525) left GitHub Pages
50
+ * as the only way to the catalog, and on the China line that host is the one
51
+ * that has to be reachable. The catalog package is published to npm proper,
52
+ * and this mirror carries it, so naming it costs one request only when the
53
+ * first mirror has already failed.
54
+ */
55
+ const CHINA_NPM_FALLBACK = 'https://registry.npmmirror.com';
56
+ /**
57
+ * First public prefix used for unauthenticated GitHub reads, no trailing slash.
58
+ * Authenticated API calls and canonical codeload tarballs never use it.
59
+ *
60
+ * What this proxy accepts is a list of GitHub SERVICES, not a hostname test.
61
+ * The previous note here said it "refuses anything that is not a github.com
62
+ * hostname", which #460 by @Homplex measured as wrong in both directions —
63
+ * re-measured 2026-09-01:
64
+ *
65
+ * https://raw.githubusercontent.com/… 200 ← not a github.com hostname
66
+ * https://github.com/owner/repo 403 ← is one
67
+ * https://example.com/ 403
68
+ *
69
+ * So a plain repository page is refused while raw content is served. Do not
70
+ * reason about this proxy from the hostname; check the specific service, and
71
+ * re-measure rather than infer, because the policy is the operator's and can
72
+ * change under us. That fragility is the substance of #460's actual request
73
+ * (a mirror list and a visible setting), which is tracked separately.
74
+ */
75
+ const GITHUB_PROXY_CHINA = 'https://gh-proxy.com';
76
+ const GITHUB_PROXY_CHINA_FALLBACK = 'https://ghfast.top';
77
+ /**
78
+ * 目录的唯一公开地址:crate 的 dsh-crate.json(插件专用全量数据包)。
79
+ *
80
+ * 这份 JSON 由 crate 每次构建时随站点一起生成(与网页端同源数据),条目字段
81
+ * 与内部 Registry 不同,映射放在 src/crate-catalog.ts;这里只负责把它放在
82
+ * 哪个地区的哪个地址上。
83
+ * 它带 ETag 与 cache-control,所以 registry.ts 的 304 复用照常生效。
84
+ */
85
+ const CATALOG_OFFICIAL = 'https://dshcrate.com/data/dsh-crate.json';
86
+ const ROUTES = {
87
+ global: {
88
+ npmRegistry: DEFAULT_NPM_REGISTRY,
89
+ githubProxy: null,
90
+ githubRoutes: { git: [null], raw: [null], avatar: [null] },
91
+ catalog: [{ kind: 'url', url: CATALOG_OFFICIAL }],
92
+ },
93
+ china: {
94
+ npmRegistry: NPM_CHINA,
95
+ githubProxy: GITHUB_PROXY_CHINA,
96
+ // Filtering is service-shaped, not GitHub-shaped. Raw content commonly
97
+ // needs help while git advertisements and avatars remain reachable, so
98
+ // putting one global order on all three only trades one outage for
99
+ // needless proxy traffic on the paths that still work.
100
+ githubRoutes: {
101
+ raw: [GITHUB_PROXY_CHINA, GITHUB_PROXY_CHINA_FALLBACK, null],
102
+ git: [null, GITHUB_PROXY_CHINA, GITHUB_PROXY_CHINA_FALLBACK],
103
+ avatar: [null, GITHUB_PROXY_CHINA, GITHUB_PROXY_CHINA_FALLBACK],
104
+ },
105
+ // crate 没有把目录另发成 npm 包,所以两个地区都只有这一个地址:
106
+ // 网络到不了它,就是真的拿不到目录,不做「换一个镜像」的假动作。
107
+ catalog: [{ kind: 'url', url: CATALOG_OFFICIAL }],
108
+ },
109
+ };
110
+ /**
111
+ * 一个地区要尝试的所有目录地址。
112
+ *
113
+ * crate 只有一份公开 JSON,没有可以退到的 npm 镜像包,所以这里的候选列表
114
+ * 就是该地区自己声明的顺序;保留这个函数是为了让「列表怎么来的」只在一个
115
+ * 地方回答,调用方不必知道地区表的结构。
116
+ */
117
+ export function catalogSourcesFor(region) {
118
+ return routesFor(region).catalog.map(source => ({ ...source }));
119
+ }
120
+ /** Read an environment override, treating blank as unset. */
121
+ function override(env, name) {
122
+ const raw = env[name];
123
+ return raw !== undefined && raw.trim() !== '' ? raw.trim().replace(/\/+$/, '') : null;
124
+ }
125
+ /**
126
+ * Normalize a user-maintained prefix, or reject it.
127
+ *
128
+ * Public mirrors receive the complete destination URL in their path. Only
129
+ * HTTPS prefixes without embedded credentials or query fragments are safe to
130
+ * persist and show again in the settings UI.
131
+ */
132
+ export function normalizeGithubProxy(value) {
133
+ if (typeof value !== 'string')
134
+ return null;
135
+ const raw = value.trim();
136
+ if (raw === '' || raw.includes('\\'))
137
+ return null;
138
+ try {
139
+ const parsed = new URL(raw);
140
+ if (parsed.protocol !== 'https:' || parsed.username !== '' || parsed.password !== '')
141
+ return null;
142
+ if (parsed.search !== '' || parsed.hash !== '')
143
+ return null;
144
+ const path = parsed.pathname.replace(/\/+$/u, '');
145
+ return `${parsed.origin}${path}`;
146
+ }
147
+ catch {
148
+ return null;
149
+ }
150
+ }
151
+ let customGithubProxy = null;
152
+ const preferredGithubRoutes = new Map();
153
+ /** Apply (or clear) the persisted UI escape route. */
154
+ export function setCustomGithubProxy(proxy) {
155
+ const next = proxy === null ? null : normalizeGithubProxy(proxy);
156
+ if (next === customGithubProxy)
157
+ return;
158
+ customGithubProxy = next;
159
+ resetGithubRoutePreferences();
160
+ }
161
+ /** Whether the operator-owned environment variable disables UI changes. */
162
+ export function githubProxyManaged(env = process.env) {
163
+ return override(env, 'DSHM_GITHUB_PROXY') !== null;
164
+ }
165
+ /** Remember one verified route without changing other GitHub services. */
166
+ export function rememberGithubRoute(service, route) {
167
+ preferredGithubRoutes.set(service, route);
168
+ }
169
+ /** Forget learned winners after the configured candidates change. */
170
+ export function resetGithubRoutePreferences() {
171
+ preferredGithubRoutes.clear();
172
+ }
173
+ /**
174
+ * Put a user's own prefix in front, and keep the region's other routes (#850).
175
+ *
176
+ * Heading rather than replacing, because a public proxy dying is the whole
177
+ * reason the setting exists — the reporter's was one of these mirrors, and it
178
+ * took the rest of the chain with it: `gh-proxy.com` stopped serving on
179
+ * 2026-10-13, and every GitHub-sourced update then failed on a timeout rather
180
+ * than trying the next candidate. Replacing the list buys one attempt per
181
+ * mirror outage; heading it buys one, and then the chain that was already
182
+ * measured to work.
183
+ *
184
+ * The proxy is also dropped from the tail if it is already there, so a user
185
+ * who accepted the value the settings UI pre-suggests gets exactly the
186
+ * region's own table back rather than the same prefix twice.
187
+ *
188
+ * The direct escape is never dropped: `githubRoutes` promises every list ends
189
+ * in one, and dropping it would turn a dead mirror into an outage instead of
190
+ * a slow request.
191
+ */
192
+ function withCustomProxy(proxy, base) {
193
+ return [proxy, ...base.filter(route => route !== proxy)];
194
+ }
195
+ /**
196
+ * The routes for a region, with environment overrides applied.
197
+ *
198
+ * Overrides win over the table because they are the user's statement about
199
+ * their own network, and they are the way out when a public proxy dies.
200
+ *
201
+ * `DSHM_REGISTRY_URL` keeps its existing meaning — the catalog URL — and
202
+ * when set it REPLACES the source list rather than heading it: someone
203
+ * pointing the market at their own catalog does not want it quietly
204
+ * reverting to ours.
205
+ */
206
+ export function routesFor(region, env = process.env) {
207
+ const base = ROUTES[region];
208
+ const npmMirror = override(env, 'DSHM_NPM_MIRROR');
209
+ const githubProxy = override(env, 'DSHM_GITHUB_PROXY') ?? customGithubProxy;
210
+ const catalog = override(env, 'DSHM_REGISTRY_URL');
211
+ const registry = npmMirror ?? base.npmRegistry;
212
+ const githubRoutes = githubProxy === null
213
+ ? {
214
+ git: [...base.githubRoutes.git],
215
+ raw: [...base.githubRoutes.raw],
216
+ avatar: [...base.githubRoutes.avatar],
217
+ }
218
+ : {
219
+ git: withCustomProxy(githubProxy, base.githubRoutes.git),
220
+ raw: withCustomProxy(githubProxy, base.githubRoutes.raw),
221
+ avatar: withCustomProxy(githubProxy, base.githubRoutes.avatar),
222
+ };
223
+ return {
224
+ npmRegistry: registry,
225
+ githubProxy: githubProxy ?? base.githubProxy,
226
+ githubRoutes,
227
+ // A named catalog REPLACES the list rather than joining it. Someone
228
+ // pointing the market at their own catalog does not want it quietly
229
+ // reverting to ours when theirs is briefly unreachable — that is how a
230
+ // fixture-backed test ends up asserting against the live registry.
231
+ catalog: catalog !== null
232
+ ? [{ kind: 'url', url: catalog }]
233
+ // Rebuilt against the resolved registry, so an npm override moves the
234
+ // catalog to the same mirror it moved everything else to.
235
+ : base.catalog.map(source => (source.kind === 'npm' ? { ...source, registry } : source)),
236
+ };
237
+ }
238
+ /** Ordered candidates with this process's last verified winner first. */
239
+ export function githubRoutesFor(service, region = activeRegion(), env = process.env) {
240
+ const routes = routesFor(region, env).githubRoutes[service];
241
+ if (!preferredGithubRoutes.has(service))
242
+ return routes;
243
+ const preferred = preferredGithubRoutes.get(service);
244
+ const index = routes.findIndex(route => route === preferred);
245
+ if (index <= 0)
246
+ return routes;
247
+ return [routes[index], ...routes.slice(0, index), ...routes.slice(index + 1)];
248
+ }
249
+ /**
250
+ * The region this process is running under.
251
+ *
252
+ * One piece of module state rather than a parameter threaded through the
253
+ * catalog, the theme manager, update checks and every pnpm spawn: the region
254
+ * is a property of the running market, not of any single question asked of
255
+ * it, and the call graphs that need it are several frames deep.
256
+ *
257
+ * Consumers that must react to a CHANGE (dropping a cache gathered from the
258
+ * other registry) keep their own setter beside this one; this holds the
259
+ * answer for everyone who only needs to read it.
260
+ */
261
+ let active = 'global';
262
+ /** The region in force. */
263
+ export function activeRegion() {
264
+ return active;
265
+ }
266
+ /** Set the region in force. Callers are responsible for their own caches. */
267
+ export function setActiveRegion(region) {
268
+ active = region;
269
+ }
270
+ /**
271
+ * Wrap a github.com-family URL in a prefix proxy.
272
+ *
273
+ * The proxy takes the full absolute URL as its path (`{proxy}/{url}`) rather
274
+ * than a rewritten hostname, so the same joining rule works for every
275
+ * GitHub service a caller has explicitly allowed through public routes.
276
+ *
277
+ * @param proxy - the prefix, or null to go direct.
278
+ * @param url - an absolute https URL on a github.com-family host.
279
+ * @returns the proxied URL, or `url` unchanged when there is no proxy.
280
+ */
281
+ export function throughProxy(proxy, url) {
282
+ return proxy === null ? url : `${proxy}/${url}`;
283
+ }