@mearl/preset 3.0.0-beta.3 → 3.0.0-beta.5

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.
@@ -11,7 +11,6 @@ export interface InstallationConfig {
11
11
  schemaVersion: 1;
12
12
  guide?: InstallationGuide;
13
13
  presets?: Record<string, InstallationPreset>;
14
- legacyPreset?: string;
15
14
  }
16
15
  /** One validated catalog is used by the website and extension; parameters cannot add install sources. */
17
16
  export declare function parseInstallationConfig(value: unknown, publicOrigin: string): InstallationConfig;
@@ -22,3 +21,8 @@ export declare function matchesInstallationOrigin(scope: string, target: URL): b
22
21
  export declare const INSTALLATION_CONFIG_MAX_BYTES = 65536;
23
22
  export declare function readInstallationJson(response: Response, maxBytes: number): Promise<unknown>;
24
23
  export declare function loadInstallationConfig(url: string | URL, publicOrigin: string, signal?: AbortSignal): Promise<InstallationConfig>;
24
+ export declare const PRESET_UPDATE_INTERVAL_MS: number;
25
+ export declare const PRESET_UPDATE_RETRY_MS: number;
26
+ export declare function trustedInstallationPreset(config: InstallationConfig, id: string | undefined, source: string | undefined): InstallationPreset | undefined;
27
+ /** An exact scope can be covered by a broader catalog scope, never the reverse. */
28
+ export declare function installationOriginCovered(origin: string, scopes: readonly string[]): boolean;
@@ -14,7 +14,7 @@ function httpsUrl(value) {
14
14
  }
15
15
  /** One validated catalog is used by the website and extension; parameters cannot add install sources. */
16
16
  export function parseInstallationConfig(value, publicOrigin) {
17
- const input = record(value, ['schemaVersion', 'guide', 'presets', 'legacyPreset']);
17
+ const input = record(value, ['schemaVersion', 'guide', 'presets']);
18
18
  if (input.schemaVersion !== 1)
19
19
  throw new Error('Invalid installation schema');
20
20
  const result = { schemaVersion: 1 };
@@ -47,11 +47,6 @@ export function parseInstallationConfig(value, publicOrigin) {
47
47
  return [id, { label: entry.label, source, origins }];
48
48
  }));
49
49
  }
50
- if (input.legacyPreset !== undefined) {
51
- if (typeof input.legacyPreset !== 'string' || !Object.hasOwn(result.presets ?? {}, input.legacyPreset))
52
- throw new Error('Invalid legacy installation preset');
53
- result.legacyPreset = input.legacyPreset;
54
- }
55
50
  return result;
56
51
  }
57
52
  /** Explicit host scopes retain their selected schemes; download sources remain HTTPS. */
@@ -114,3 +109,21 @@ export async function loadInstallationConfig(url, publicOrigin, signal) {
114
109
  throw new Error('Installation configuration unavailable');
115
110
  return parseInstallationConfig(await readInstallationJson(response, INSTALLATION_CONFIG_MAX_BYTES), publicOrigin);
116
111
  }
112
+ export const PRESET_UPDATE_INTERVAL_MS = 12 * 60 * 60_000;
113
+ export const PRESET_UPDATE_RETRY_MS = 60 * 60_000;
114
+ export function trustedInstallationPreset(config, id, source) {
115
+ return id && source && Object.hasOwn(config.presets ?? {}, id) && config.presets[id].source === source ? config.presets[id] : undefined;
116
+ }
117
+ /** An exact scope can be covered by a broader catalog scope, never the reverse. */
118
+ export function installationOriginCovered(origin, scopes) {
119
+ const target = validateInstallationOrigin(origin);
120
+ const wildcard = /^(?:https?|\*):\/\/\*\./.test(target);
121
+ const schemes = target.startsWith('*:') ? ['http:', 'https:'] : [target.slice(0, target.indexOf(':') + 1)];
122
+ return scopes.some(scope => {
123
+ const candidate = validateInstallationOrigin(scope);
124
+ if (wildcard && !/^(?:https?|\*):\/\/\*\./.test(candidate))
125
+ return false;
126
+ const base = target.replace(/^\*:/, 'https:').replace(/^(https?:\/\/)\*\./, '$1');
127
+ return schemes.every(scheme => { const url = new URL(base); url.protocol = scheme; return matchesInstallationOrigin(candidate, url); });
128
+ });
129
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "url": "https://f-loat.github.io/mearl/",
3
+ "extensionId": "aoehhjnofngknnjefamjbplchbolghkm"
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearl/preset",
3
- "version": "3.0.0-beta.3",
3
+ "version": "3.0.0-beta.5",
4
4
  "description": "Browser-compatible preset validation, inheritance and capability resolution for Mearl",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -18,11 +18,13 @@
18
18
  "./installation": {
19
19
  "types": "./dist/installation.d.ts",
20
20
  "import": "./dist/installation.js"
21
- }
21
+ },
22
+ "./installation-site.json": "./installation-site.json"
22
23
  },
23
24
  "files": [
24
25
  "dist",
25
- "!dist/**/*.map"
26
+ "!dist/**/*.map",
27
+ "installation-site.json"
26
28
  ],
27
29
  "dependencies": {
28
30
  "semver": "^7.8.5"