@xbrowser/cli 0.14.0 → 0.14.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/dist/{chunk-VUJDJCIN.js → chunk-ITKPSIP7.js} +93 -4
- package/dist/cli.js +512 -305
- package/dist/daemon-main.js +172 -80
- package/dist/{human-interaction-QPHNDD76.js → human-interaction-W753RVJB.js} +1 -2
- package/dist/index.d.ts +7 -68
- package/dist/index.js +407 -271
- package/dist/screenshot-CWAWMXVA.js +28 -0
- package/dist/screenshot-MB6R7RSS.js +26 -0
- package/package.json +1 -1
- package/dist/admin-6UTU2RZ2.js +0 -281
- package/dist/admin-MDGF4CET.js +0 -285
- package/dist/admin-RPJJ5CAF.js +0 -282
- package/dist/chunk-43VX3TYN.js +0 -83
- package/dist/chunk-DESA2KMG.js +0 -77
- package/dist/chunk-FF5WHQHN.js +0 -135
- package/dist/chunk-HINTG75P.js +0 -77
- package/dist/chunk-KTSQU4QT.js +0 -29
- package/dist/chunk-M7CMBPCA.js +0 -100
- package/dist/chunk-NFGO7J2I.js +0 -29
- package/dist/chunk-OLB6UJ25.js +0 -438
- package/dist/chunk-VEKPHQBR.js +0 -47
- package/dist/chunk-YEN2ODUI.js +0 -14
- package/dist/marketplace-FCVN5OTZ.js +0 -706
- package/dist/marketplace-FPT5YLKB.js +0 -351
- package/dist/marketplace-W545W4FR.js +0 -706
package/dist/admin-RPJJ5CAF.js
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
loadAuth
|
|
3
|
-
} from "./chunk-NFGO7J2I.js";
|
|
4
|
-
import {
|
|
5
|
-
ensureProxyFetch,
|
|
6
|
-
getRegistryUrl
|
|
7
|
-
} from "./chunk-FF5WHQHN.js";
|
|
8
|
-
|
|
9
|
-
// src/plugin/builtins/admin.ts
|
|
10
|
-
import { z } from "zod";
|
|
11
|
-
var adminResult = z.object({
|
|
12
|
-
success: z.boolean(),
|
|
13
|
-
data: z.record(z.unknown()).optional(),
|
|
14
|
-
message: z.string().optional()
|
|
15
|
-
});
|
|
16
|
-
function requireAuth(options) {
|
|
17
|
-
const auth = loadAuth();
|
|
18
|
-
if (!auth?.token) {
|
|
19
|
-
throw new Error("Not logged in. Run: xbrowser marketplace login");
|
|
20
|
-
}
|
|
21
|
-
const registryUrl = getRegistryUrl(options, auth.registry);
|
|
22
|
-
return { token: auth.token, registryUrl };
|
|
23
|
-
}
|
|
24
|
-
async function adminFetch(url, token, init) {
|
|
25
|
-
await ensureProxyFetch();
|
|
26
|
-
const res = await fetch(url, {
|
|
27
|
-
...init,
|
|
28
|
-
headers: {
|
|
29
|
-
Authorization: `Bearer ${token}`,
|
|
30
|
-
...init?.headers
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
if (res.status === 403) {
|
|
34
|
-
throw new Error("Forbidden: admin access required");
|
|
35
|
-
}
|
|
36
|
-
if (!res.ok) {
|
|
37
|
-
const errBody = await res.json().catch(() => ({}));
|
|
38
|
-
throw new Error(
|
|
39
|
-
`Request failed (${res.status}): ${errBody.error || errBody.message || res.statusText}`
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
return await res.json();
|
|
43
|
-
}
|
|
44
|
-
function formatPluginRow(p) {
|
|
45
|
-
const name = p.name || "?";
|
|
46
|
-
const slug = p.slug || "?";
|
|
47
|
-
const status = p.status || "?";
|
|
48
|
-
const version = p.version || "?";
|
|
49
|
-
const featured = p.featured ? " [featured]" : "";
|
|
50
|
-
const author = p.author || p.developer || "";
|
|
51
|
-
return ` ${slug.padEnd(25)} ${name.padEnd(30)} v${version.padEnd(10)} ${status}${featured}${author ? ` by ${author}` : ""}`;
|
|
52
|
-
}
|
|
53
|
-
function setupAdminPlugin(xcli) {
|
|
54
|
-
const site = xcli.createSite({
|
|
55
|
-
name: "admin",
|
|
56
|
-
url: "https://xbrowser.dev",
|
|
57
|
-
description: "xbrowser marketplace admin tools"
|
|
58
|
-
});
|
|
59
|
-
const cmd = (name, config) => site.command(name, config);
|
|
60
|
-
cmd("pending", {
|
|
61
|
-
description: "List pending plugins",
|
|
62
|
-
scope: "global",
|
|
63
|
-
parameters: z.object({
|
|
64
|
-
registry: z.string().optional().describe("Custom registry URL")
|
|
65
|
-
}),
|
|
66
|
-
result: adminResult,
|
|
67
|
-
handler: async (params) => {
|
|
68
|
-
const { token, registryUrl } = requireAuth(params);
|
|
69
|
-
const body = await adminFetch(`${registryUrl}/api/admin/plugins/pending`, token);
|
|
70
|
-
const plugins = body.data || [];
|
|
71
|
-
const lines = [];
|
|
72
|
-
if (plugins.length === 0) {
|
|
73
|
-
lines.push("No pending plugins");
|
|
74
|
-
} else {
|
|
75
|
-
lines.push(`
|
|
76
|
-
Pending plugins (${plugins.length}):
|
|
77
|
-
`);
|
|
78
|
-
for (const p of plugins) {
|
|
79
|
-
lines.push(formatPluginRow(p));
|
|
80
|
-
if (p.description) lines.push(` ${p.description}`);
|
|
81
|
-
}
|
|
82
|
-
lines.push("");
|
|
83
|
-
}
|
|
84
|
-
return { success: true, data: { plugins, total: plugins.length, text: lines.join("\n") } };
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
cmd("approve", {
|
|
88
|
-
description: "Approve a plugin",
|
|
89
|
-
scope: "global",
|
|
90
|
-
parameters: z.object({
|
|
91
|
-
slug: z.string().describe("Plugin slug to approve"),
|
|
92
|
-
registry: z.string().optional().describe("Custom registry URL")
|
|
93
|
-
}),
|
|
94
|
-
result: adminResult,
|
|
95
|
-
handler: async (params) => {
|
|
96
|
-
const slug = params.slug;
|
|
97
|
-
const { token, registryUrl } = requireAuth(params);
|
|
98
|
-
const body = await adminFetch(`${registryUrl}/api/admin/plugins/${slug}/approve`, token, { method: "PUT" });
|
|
99
|
-
const data = body.data;
|
|
100
|
-
const text = `Approved: ${slug}${data?.name ? `
|
|
101
|
-
Name: ${data.name}` : ""}`;
|
|
102
|
-
return { success: true, data: { ok: true, slug, ...data, text } };
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
cmd("reject", {
|
|
106
|
-
description: "Reject a plugin",
|
|
107
|
-
scope: "global",
|
|
108
|
-
parameters: z.object({
|
|
109
|
-
slug: z.string().describe("Plugin slug to reject"),
|
|
110
|
-
reason: z.string().optional().describe("Rejection reason"),
|
|
111
|
-
registry: z.string().optional().describe("Custom registry URL")
|
|
112
|
-
}),
|
|
113
|
-
result: adminResult,
|
|
114
|
-
handler: async (params) => {
|
|
115
|
-
const slug = params.slug;
|
|
116
|
-
const reason = params.reason;
|
|
117
|
-
const { token, registryUrl } = requireAuth(params);
|
|
118
|
-
const body = await adminFetch(`${registryUrl}/api/admin/plugins/${slug}/reject`, token, {
|
|
119
|
-
method: "PUT",
|
|
120
|
-
headers: { "Content-Type": "application/json" },
|
|
121
|
-
body: JSON.stringify({ reason })
|
|
122
|
-
});
|
|
123
|
-
const data = body.data;
|
|
124
|
-
const text = `Rejected: ${slug}${reason ? `
|
|
125
|
-
Reason: ${reason}` : ""}`;
|
|
126
|
-
return { success: true, data: { ok: true, slug, ...data, text } };
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
cmd("feature", {
|
|
130
|
-
description: "Toggle featured status",
|
|
131
|
-
scope: "global",
|
|
132
|
-
parameters: z.object({
|
|
133
|
-
slug: z.string().describe("Plugin slug"),
|
|
134
|
-
registry: z.string().optional().describe("Custom registry URL")
|
|
135
|
-
}),
|
|
136
|
-
result: adminResult,
|
|
137
|
-
handler: async (params) => {
|
|
138
|
-
const slug = params.slug;
|
|
139
|
-
const { token, registryUrl } = requireAuth(params);
|
|
140
|
-
const body = await adminFetch(`${registryUrl}/api/admin/plugins/${slug}/feature`, token, { method: "PUT" });
|
|
141
|
-
const data = body.data;
|
|
142
|
-
const featured = data?.featured ? "featured" : "unfeatured";
|
|
143
|
-
const text = `Toggled featured: ${slug} -> ${featured}`;
|
|
144
|
-
return { success: true, data: { ok: true, slug, ...data, text } };
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
cmd("remove", {
|
|
148
|
-
description: "Remove a plugin",
|
|
149
|
-
scope: "global",
|
|
150
|
-
parameters: z.object({
|
|
151
|
-
slug: z.string().describe("Plugin slug to remove"),
|
|
152
|
-
registry: z.string().optional().describe("Custom registry URL")
|
|
153
|
-
}),
|
|
154
|
-
result: adminResult,
|
|
155
|
-
handler: async (params) => {
|
|
156
|
-
const slug = params.slug;
|
|
157
|
-
const { token, registryUrl } = requireAuth(params);
|
|
158
|
-
await adminFetch(`${registryUrl}/api/admin/plugins/${slug}`, token, { method: "DELETE" });
|
|
159
|
-
return { success: true, data: { ok: true, slug, text: `Removed: ${slug}` } };
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
cmd("stats", {
|
|
163
|
-
description: "Dashboard stats",
|
|
164
|
-
scope: "global",
|
|
165
|
-
parameters: z.object({
|
|
166
|
-
registry: z.string().optional().describe("Custom registry URL")
|
|
167
|
-
}),
|
|
168
|
-
result: adminResult,
|
|
169
|
-
handler: async (params) => {
|
|
170
|
-
const { token, registryUrl } = requireAuth(params);
|
|
171
|
-
const body = await adminFetch(`${registryUrl}/api/admin/stats/dashboard`, token);
|
|
172
|
-
const data = body.data;
|
|
173
|
-
const lines = ["\nDashboard Stats:\n"];
|
|
174
|
-
if (data) {
|
|
175
|
-
for (const [k, v] of Object.entries(data)) {
|
|
176
|
-
lines.push(` ${k}: ${typeof v === "object" ? JSON.stringify(v) : v}`);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
lines.push("");
|
|
180
|
-
return { success: true, data: { ...data, text: lines.join("\n") } };
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
cmd("inventory", {
|
|
184
|
-
description: "Full plugin inventory",
|
|
185
|
-
scope: "global",
|
|
186
|
-
parameters: z.object({
|
|
187
|
-
registry: z.string().optional().describe("Custom registry URL")
|
|
188
|
-
}),
|
|
189
|
-
result: adminResult,
|
|
190
|
-
handler: async (params) => {
|
|
191
|
-
const { token, registryUrl } = requireAuth(params);
|
|
192
|
-
const body = await adminFetch(`${registryUrl}/api/admin/stats/inventory`, token);
|
|
193
|
-
const plugins = body.data || [];
|
|
194
|
-
const lines = [];
|
|
195
|
-
if (plugins.length === 0) {
|
|
196
|
-
lines.push("No plugins in inventory");
|
|
197
|
-
} else {
|
|
198
|
-
lines.push(`
|
|
199
|
-
Plugin Inventory (${plugins.length}):
|
|
200
|
-
`);
|
|
201
|
-
for (const p of plugins) lines.push(formatPluginRow(p));
|
|
202
|
-
lines.push("");
|
|
203
|
-
}
|
|
204
|
-
return { success: true, data: { plugins, total: plugins.length, text: lines.join("\n") } };
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
cmd("list", {
|
|
208
|
-
description: "List all plugins",
|
|
209
|
-
scope: "global",
|
|
210
|
-
parameters: z.object({
|
|
211
|
-
status: z.string().optional().describe("Filter by status"),
|
|
212
|
-
registry: z.string().optional().describe("Custom registry URL")
|
|
213
|
-
}),
|
|
214
|
-
result: adminResult,
|
|
215
|
-
handler: async (params) => {
|
|
216
|
-
const status = params.status;
|
|
217
|
-
const { token, registryUrl } = requireAuth(params);
|
|
218
|
-
const url = new URL(`${registryUrl}/api/admin/plugins`);
|
|
219
|
-
if (status) url.searchParams.set("status", status);
|
|
220
|
-
const body = await adminFetch(url.toString(), token);
|
|
221
|
-
const plugins = body.data || [];
|
|
222
|
-
const lines = [];
|
|
223
|
-
if (plugins.length === 0) {
|
|
224
|
-
lines.push(status ? `No plugins with status "${status}"` : "No plugins");
|
|
225
|
-
} else {
|
|
226
|
-
lines.push(`
|
|
227
|
-
Plugins${status ? ` [${status}]` : ""} (${plugins.length}):
|
|
228
|
-
`);
|
|
229
|
-
for (const p of plugins) lines.push(formatPluginRow(p));
|
|
230
|
-
lines.push("");
|
|
231
|
-
}
|
|
232
|
-
return { success: true, data: { plugins, total: plugins.length, status, text: lines.join("\n") } };
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
cmd("bulk-approve", {
|
|
236
|
-
description: "Bulk approve plugins",
|
|
237
|
-
scope: "global",
|
|
238
|
-
parameters: z.object({
|
|
239
|
-
slugs: z.union([z.string(), z.array(z.string())]).describe("Plugin slugs to approve"),
|
|
240
|
-
registry: z.string().optional().describe("Custom registry URL")
|
|
241
|
-
}),
|
|
242
|
-
result: adminResult,
|
|
243
|
-
handler: async (params) => {
|
|
244
|
-
const slugs = Array.isArray(params.slugs) ? params.slugs : [params.slugs];
|
|
245
|
-
if (slugs.length === 0) {
|
|
246
|
-
return { success: false, message: "Usage: xbrowser admin bulk-approve <slug1> <slug2> ..." };
|
|
247
|
-
}
|
|
248
|
-
const { token, registryUrl } = requireAuth(params);
|
|
249
|
-
const body = await adminFetch(`${registryUrl}/api/admin/plugins/bulk-approve`, token, {
|
|
250
|
-
method: "POST",
|
|
251
|
-
headers: { "Content-Type": "application/json" },
|
|
252
|
-
body: JSON.stringify({ slugs })
|
|
253
|
-
});
|
|
254
|
-
const data = body.data;
|
|
255
|
-
const approved = data?.approved || slugs;
|
|
256
|
-
const lines = [`Bulk approved ${approved.length} plugins:`];
|
|
257
|
-
for (const s of approved) lines.push(` - ${s}`);
|
|
258
|
-
return { success: true, data: { ok: true, slugs, ...data, text: lines.join("\n") } };
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
cmd("cleanup", {
|
|
262
|
-
description: "Reset fake data / cleanup database",
|
|
263
|
-
scope: "global",
|
|
264
|
-
parameters: z.object({
|
|
265
|
-
registry: z.string().optional().describe("Custom registry URL")
|
|
266
|
-
}),
|
|
267
|
-
result: adminResult,
|
|
268
|
-
handler: async (params) => {
|
|
269
|
-
const { token, registryUrl } = requireAuth(params);
|
|
270
|
-
const body = await adminFetch(`${registryUrl}/api/admin/db/cleanup`, token, { method: "POST" });
|
|
271
|
-
const data = body.data;
|
|
272
|
-
const lines = ["Cleanup completed"];
|
|
273
|
-
if (data) {
|
|
274
|
-
for (const [k, v] of Object.entries(data)) lines.push(` ${k}: ${v}`);
|
|
275
|
-
}
|
|
276
|
-
return { success: true, data: { ok: true, ...data, text: lines.join("\n") } };
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
export {
|
|
281
|
-
setupAdminPlugin as default
|
|
282
|
-
};
|
package/dist/chunk-43VX3TYN.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
readJsonFile
|
|
3
|
-
} from "./chunk-YEN2ODUI.js";
|
|
4
|
-
|
|
5
|
-
// src/config.ts
|
|
6
|
-
var DEFAULT_REGISTRY_URL = "https://xbrowser.dev";
|
|
7
|
-
var NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
8
|
-
function getRegistryUrl(options = {}, fallbackRegistry) {
|
|
9
|
-
return options["registry"] || process.env.XBROWSER_REGISTRY || fallbackRegistry || DEFAULT_REGISTRY_URL;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// src/plugin/builtins/shared.ts
|
|
13
|
-
import { existsSync, writeFileSync, mkdirSync } from "fs";
|
|
14
|
-
import { resolve } from "path";
|
|
15
|
-
import { homedir } from "os";
|
|
16
|
-
function getAuthDir() {
|
|
17
|
-
return resolve(homedir(), ".xbrowser");
|
|
18
|
-
}
|
|
19
|
-
function getAuthFile() {
|
|
20
|
-
return resolve(getAuthDir(), "auth.json");
|
|
21
|
-
}
|
|
22
|
-
function loadAuth() {
|
|
23
|
-
const authFile = getAuthFile();
|
|
24
|
-
if (!existsSync(authFile)) return null;
|
|
25
|
-
return readJsonFile(authFile, null);
|
|
26
|
-
}
|
|
27
|
-
function saveAuth(config) {
|
|
28
|
-
const dir = getAuthDir();
|
|
29
|
-
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
30
|
-
writeFileSync(getAuthFile(), JSON.stringify(config, null, 2), "utf-8");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/utils/proxy-fetch.ts
|
|
34
|
-
var patched = false;
|
|
35
|
-
async function ensureProxyFetch() {
|
|
36
|
-
if (patched) return;
|
|
37
|
-
patched = true;
|
|
38
|
-
if (process.env.https_proxy && !process.env.HTTPS_PROXY) {
|
|
39
|
-
process.env.HTTPS_PROXY = process.env.https_proxy;
|
|
40
|
-
}
|
|
41
|
-
if (process.env.http_proxy && !process.env.HTTP_PROXY) {
|
|
42
|
-
process.env.HTTP_PROXY = process.env.http_proxy;
|
|
43
|
-
}
|
|
44
|
-
if (process.env.all_proxy && !process.env.ALL_PROXY) {
|
|
45
|
-
process.env.ALL_PROXY = process.env.all_proxy;
|
|
46
|
-
}
|
|
47
|
-
const proxyUrl = process.env.https_proxy || process.env.HTTPS_PROXY || process.env.http_proxy || process.env.HTTP_PROXY || process.env.all_proxy || process.env.ALL_PROXY;
|
|
48
|
-
if (!proxyUrl) return;
|
|
49
|
-
try {
|
|
50
|
-
const undici = await import("undici");
|
|
51
|
-
const EnvHttpProxyAgent = undici.EnvHttpProxyAgent;
|
|
52
|
-
const uFetch = undici.fetch;
|
|
53
|
-
const UFormData = undici.FormData;
|
|
54
|
-
if (EnvHttpProxyAgent && uFetch && UFormData) {
|
|
55
|
-
const agent = new EnvHttpProxyAgent();
|
|
56
|
-
globalThis.fetch = ((input, init) => {
|
|
57
|
-
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
58
|
-
const body = init?.body;
|
|
59
|
-
if (body instanceof globalThis.FormData && !(body instanceof UFormData)) {
|
|
60
|
-
const ufd = new UFormData();
|
|
61
|
-
body.forEach((value, key) => {
|
|
62
|
-
if (value instanceof Blob) {
|
|
63
|
-
ufd.append(key, value, value.name || "file");
|
|
64
|
-
} else {
|
|
65
|
-
ufd.append(key, value);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
return uFetch(url, { ...init, body: ufd, dispatcher: agent });
|
|
69
|
-
}
|
|
70
|
-
return uFetch(url, { ...init, dispatcher: agent });
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
} catch {
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export {
|
|
78
|
-
NPM_REGISTRY_URL,
|
|
79
|
-
getRegistryUrl,
|
|
80
|
-
loadAuth,
|
|
81
|
-
saveAuth,
|
|
82
|
-
ensureProxyFetch
|
|
83
|
-
};
|
package/dist/chunk-DESA2KMG.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
readJsonFile
|
|
3
|
-
} from "./chunk-YEN2ODUI.js";
|
|
4
|
-
|
|
5
|
-
// src/plugin/metadata-parser.ts
|
|
6
|
-
import { existsSync } from "fs";
|
|
7
|
-
import { resolve } from "path";
|
|
8
|
-
var PluginMetadataParser = class {
|
|
9
|
-
static XBROWSER_KEYWORDS = ["xbrowser", "xbrowser-plugin"];
|
|
10
|
-
static parseFromPackageJson(pluginPath) {
|
|
11
|
-
const packageJsonPath = resolve(pluginPath, "package.json");
|
|
12
|
-
if (!existsSync(packageJsonPath)) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
const packageJson = readJsonFile(packageJsonPath, null);
|
|
16
|
-
if (!packageJson) return null;
|
|
17
|
-
if (!packageJson.xbrowser) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
const xbrowser = packageJson.xbrowser;
|
|
21
|
-
const metadata = {
|
|
22
|
-
id: xbrowser.id || packageJson.name,
|
|
23
|
-
name: xbrowser.name || packageJson.name,
|
|
24
|
-
description: xbrowser.description || packageJson.description || "",
|
|
25
|
-
version: xbrowser.version || packageJson.version || "1.0.0",
|
|
26
|
-
author: xbrowser.author || this.extractAuthor(packageJson.author),
|
|
27
|
-
homepage: xbrowser.homepage || packageJson.homepage,
|
|
28
|
-
commands: xbrowser.commands,
|
|
29
|
-
sites: xbrowser.sites,
|
|
30
|
-
tags: xbrowser.tags,
|
|
31
|
-
screenshot: xbrowser.screenshot,
|
|
32
|
-
license: xbrowser.license || packageJson.license
|
|
33
|
-
};
|
|
34
|
-
return metadata;
|
|
35
|
-
}
|
|
36
|
-
static isXBrowserPlugin(packageJson) {
|
|
37
|
-
if (packageJson.xbrowser) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
const keywords = packageJson.keywords;
|
|
41
|
-
if (!keywords) return false;
|
|
42
|
-
return this.XBROWSER_KEYWORDS.some((kw) => keywords.includes(kw));
|
|
43
|
-
}
|
|
44
|
-
static fromNPMResult(result) {
|
|
45
|
-
const author = typeof result.author === "string" ? result.author : result.author?.name || "Unknown";
|
|
46
|
-
return {
|
|
47
|
-
id: result.name,
|
|
48
|
-
name: result.name.replace(/^xbrowser-plugin-/, "").replace(/^@[^/]+\//, ""),
|
|
49
|
-
description: result.description || "",
|
|
50
|
-
version: result.version,
|
|
51
|
-
author,
|
|
52
|
-
homepage: result.homepage || result.links?.homepage,
|
|
53
|
-
tags: result.keywords,
|
|
54
|
-
license: ""
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
static extractAuthor(author) {
|
|
58
|
-
if (typeof author === "string") return author;
|
|
59
|
-
if (typeof author === "object" && author !== null) {
|
|
60
|
-
const authorObj = author;
|
|
61
|
-
return authorObj.name || "Unknown";
|
|
62
|
-
}
|
|
63
|
-
return "Unknown";
|
|
64
|
-
}
|
|
65
|
-
static validateMetadata(metadata) {
|
|
66
|
-
const errors = [];
|
|
67
|
-
if (!metadata.id) errors.push("id is required");
|
|
68
|
-
if (!metadata.name) errors.push("name is required");
|
|
69
|
-
if (!metadata.description) errors.push("description is required");
|
|
70
|
-
if (!metadata.version) errors.push("version is required");
|
|
71
|
-
return errors;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export {
|
|
76
|
-
PluginMetadataParser
|
|
77
|
-
};
|
package/dist/chunk-FF5WHQHN.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
// src/config.ts
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync as writeFileSync2 } from "fs";
|
|
3
|
-
import { join } from "path";
|
|
4
|
-
import { homedir, tmpdir } from "os";
|
|
5
|
-
|
|
6
|
-
// src/utils/json-file.ts
|
|
7
|
-
import { readFileSync, writeFileSync } from "fs";
|
|
8
|
-
function readJsonFile(filePath, defaultValue) {
|
|
9
|
-
try {
|
|
10
|
-
const content = readFileSync(filePath, "utf-8");
|
|
11
|
-
return JSON.parse(content);
|
|
12
|
-
} catch {
|
|
13
|
-
return defaultValue;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// src/config.ts
|
|
18
|
-
function getConfigFile() {
|
|
19
|
-
return join(homedir() || tmpdir(), ".xbrowser", "config.json");
|
|
20
|
-
}
|
|
21
|
-
function loadConfig() {
|
|
22
|
-
const configFile = getConfigFile();
|
|
23
|
-
if (!existsSync(configFile)) return {};
|
|
24
|
-
return readJsonFile(configFile, {});
|
|
25
|
-
}
|
|
26
|
-
function saveConfig(config) {
|
|
27
|
-
const dir = join(homedir() || tmpdir(), ".xbrowser");
|
|
28
|
-
const configFile = getConfigFile();
|
|
29
|
-
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
30
|
-
writeFileSync2(configFile, JSON.stringify(config, null, 2), "utf-8");
|
|
31
|
-
}
|
|
32
|
-
function getConfigValue(key) {
|
|
33
|
-
return loadConfig()[key];
|
|
34
|
-
}
|
|
35
|
-
function setConfigValue(key, value) {
|
|
36
|
-
const config = loadConfig();
|
|
37
|
-
config[key] = value;
|
|
38
|
-
saveConfig(config);
|
|
39
|
-
}
|
|
40
|
-
var DEFAULT_MARKETPLACE_URL = "https://marketplace.xbrowser.dev";
|
|
41
|
-
var DEFAULT_REGISTRY_URL = "https://xbrowser.dev";
|
|
42
|
-
var NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
43
|
-
var NPM_SCOPE = "@xbrowser/";
|
|
44
|
-
function getMarketplaceUrl() {
|
|
45
|
-
return process.env.XBROWSER_MARKETPLACE_URL || getConfigValue("marketplaceUrl") || DEFAULT_MARKETPLACE_URL;
|
|
46
|
-
}
|
|
47
|
-
function getRegistryUrl(options = {}, fallbackRegistry) {
|
|
48
|
-
return options["registry"] || process.env.XBROWSER_REGISTRY || fallbackRegistry || DEFAULT_REGISTRY_URL;
|
|
49
|
-
}
|
|
50
|
-
function resolveNpmPackageName(name) {
|
|
51
|
-
if (name.startsWith("@")) return name;
|
|
52
|
-
return `${NPM_SCOPE}${name}`;
|
|
53
|
-
}
|
|
54
|
-
var NPM_NAME_ALIASES = {
|
|
55
|
-
"1688": "alibaba-1688"
|
|
56
|
-
};
|
|
57
|
-
function generateNpmCandidates(name) {
|
|
58
|
-
if (name.startsWith("@")) return [name];
|
|
59
|
-
const resolved = NPM_NAME_ALIASES[name] ?? name;
|
|
60
|
-
return [
|
|
61
|
-
`${NPM_SCOPE}xbrowser-plugin-${resolved}`,
|
|
62
|
-
`${NPM_SCOPE}${resolved}`,
|
|
63
|
-
`xbrowser-plugin-${resolved}`
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
async function resolveNpmPackageWithFallback(name) {
|
|
67
|
-
const candidates = generateNpmCandidates(name);
|
|
68
|
-
for (const candidate of candidates) {
|
|
69
|
-
try {
|
|
70
|
-
const encoded = encodeURIComponent(candidate);
|
|
71
|
-
const res = await fetch(`${NPM_REGISTRY_URL}/${encoded}`);
|
|
72
|
-
if (res.ok) return candidate;
|
|
73
|
-
} catch {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return resolveNpmPackageName(name);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// src/utils/proxy-fetch.ts
|
|
81
|
-
var patched = false;
|
|
82
|
-
async function ensureProxyFetch() {
|
|
83
|
-
if (patched) return;
|
|
84
|
-
patched = true;
|
|
85
|
-
if (process.env.https_proxy && !process.env.HTTPS_PROXY) {
|
|
86
|
-
process.env.HTTPS_PROXY = process.env.https_proxy;
|
|
87
|
-
}
|
|
88
|
-
if (process.env.http_proxy && !process.env.HTTP_PROXY) {
|
|
89
|
-
process.env.HTTP_PROXY = process.env.http_proxy;
|
|
90
|
-
}
|
|
91
|
-
if (process.env.all_proxy && !process.env.ALL_PROXY) {
|
|
92
|
-
process.env.ALL_PROXY = process.env.all_proxy;
|
|
93
|
-
}
|
|
94
|
-
const proxyUrl = process.env.https_proxy || process.env.HTTPS_PROXY || process.env.http_proxy || process.env.HTTP_PROXY || process.env.all_proxy || process.env.ALL_PROXY;
|
|
95
|
-
if (!proxyUrl) return;
|
|
96
|
-
try {
|
|
97
|
-
const undici = await import("undici");
|
|
98
|
-
const EnvHttpProxyAgent = undici.EnvHttpProxyAgent;
|
|
99
|
-
const uFetch = undici.fetch;
|
|
100
|
-
const UFormData = undici.FormData;
|
|
101
|
-
if (EnvHttpProxyAgent && uFetch && UFormData) {
|
|
102
|
-
const agent = new EnvHttpProxyAgent();
|
|
103
|
-
globalThis.fetch = ((input, init) => {
|
|
104
|
-
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
105
|
-
const body = init?.body;
|
|
106
|
-
if (body instanceof globalThis.FormData && !(body instanceof UFormData)) {
|
|
107
|
-
const ufd = new UFormData();
|
|
108
|
-
body.forEach((value, key) => {
|
|
109
|
-
if (value instanceof Blob) {
|
|
110
|
-
ufd.append(key, value, value.name || "file");
|
|
111
|
-
} else {
|
|
112
|
-
ufd.append(key, value);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
return uFetch(url, { ...init, body: ufd, dispatcher: agent });
|
|
116
|
-
}
|
|
117
|
-
return uFetch(url, { ...init, dispatcher: agent });
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
} catch {
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export {
|
|
125
|
-
readJsonFile,
|
|
126
|
-
loadConfig,
|
|
127
|
-
getConfigValue,
|
|
128
|
-
setConfigValue,
|
|
129
|
-
NPM_REGISTRY_URL,
|
|
130
|
-
NPM_SCOPE,
|
|
131
|
-
getMarketplaceUrl,
|
|
132
|
-
getRegistryUrl,
|
|
133
|
-
resolveNpmPackageWithFallback,
|
|
134
|
-
ensureProxyFetch
|
|
135
|
-
};
|
package/dist/chunk-HINTG75P.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
readJsonFile
|
|
3
|
-
} from "./chunk-FF5WHQHN.js";
|
|
4
|
-
|
|
5
|
-
// src/plugin/metadata-parser.ts
|
|
6
|
-
import { existsSync } from "fs";
|
|
7
|
-
import { resolve } from "path";
|
|
8
|
-
var PluginMetadataParser = class {
|
|
9
|
-
static XBROWSER_KEYWORDS = ["xbrowser", "xbrowser-plugin"];
|
|
10
|
-
static parseFromPackageJson(pluginPath) {
|
|
11
|
-
const packageJsonPath = resolve(pluginPath, "package.json");
|
|
12
|
-
if (!existsSync(packageJsonPath)) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
const packageJson = readJsonFile(packageJsonPath, null);
|
|
16
|
-
if (!packageJson) return null;
|
|
17
|
-
if (!packageJson.xbrowser) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
const xbrowser = packageJson.xbrowser;
|
|
21
|
-
const metadata = {
|
|
22
|
-
id: xbrowser.id || packageJson.name,
|
|
23
|
-
name: xbrowser.name || packageJson.name,
|
|
24
|
-
description: xbrowser.description || packageJson.description || "",
|
|
25
|
-
version: xbrowser.version || packageJson.version || "1.0.0",
|
|
26
|
-
author: xbrowser.author || this.extractAuthor(packageJson.author),
|
|
27
|
-
homepage: xbrowser.homepage || packageJson.homepage,
|
|
28
|
-
commands: xbrowser.commands,
|
|
29
|
-
sites: xbrowser.sites,
|
|
30
|
-
tags: xbrowser.tags,
|
|
31
|
-
screenshot: xbrowser.screenshot,
|
|
32
|
-
license: xbrowser.license || packageJson.license
|
|
33
|
-
};
|
|
34
|
-
return metadata;
|
|
35
|
-
}
|
|
36
|
-
static isXBrowserPlugin(packageJson) {
|
|
37
|
-
if (packageJson.xbrowser) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
const keywords = packageJson.keywords;
|
|
41
|
-
if (!keywords) return false;
|
|
42
|
-
return this.XBROWSER_KEYWORDS.some((kw) => keywords.includes(kw));
|
|
43
|
-
}
|
|
44
|
-
static fromNPMResult(result) {
|
|
45
|
-
const author = typeof result.author === "string" ? result.author : result.author?.name || "Unknown";
|
|
46
|
-
return {
|
|
47
|
-
id: result.name,
|
|
48
|
-
name: result.name.replace(/^xbrowser-plugin-/, "").replace(/^@[^/]+\//, ""),
|
|
49
|
-
description: result.description || "",
|
|
50
|
-
version: result.version,
|
|
51
|
-
author,
|
|
52
|
-
homepage: result.homepage || result.links?.homepage,
|
|
53
|
-
tags: result.keywords,
|
|
54
|
-
license: ""
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
static extractAuthor(author) {
|
|
58
|
-
if (typeof author === "string") return author;
|
|
59
|
-
if (typeof author === "object" && author !== null) {
|
|
60
|
-
const authorObj = author;
|
|
61
|
-
return authorObj.name || "Unknown";
|
|
62
|
-
}
|
|
63
|
-
return "Unknown";
|
|
64
|
-
}
|
|
65
|
-
static validateMetadata(metadata) {
|
|
66
|
-
const errors = [];
|
|
67
|
-
if (!metadata.id) errors.push("id is required");
|
|
68
|
-
if (!metadata.name) errors.push("name is required");
|
|
69
|
-
if (!metadata.description) errors.push("description is required");
|
|
70
|
-
if (!metadata.version) errors.push("version is required");
|
|
71
|
-
return errors;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export {
|
|
76
|
-
PluginMetadataParser
|
|
77
|
-
};
|
package/dist/chunk-KTSQU4QT.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
readJsonFile
|
|
3
|
-
} from "./chunk-M7CMBPCA.js";
|
|
4
|
-
|
|
5
|
-
// src/plugin/builtins/shared.ts
|
|
6
|
-
import { existsSync, writeFileSync, mkdirSync } from "fs";
|
|
7
|
-
import { resolve } from "path";
|
|
8
|
-
import { homedir } from "os";
|
|
9
|
-
function getAuthDir() {
|
|
10
|
-
return resolve(homedir(), ".xbrowser");
|
|
11
|
-
}
|
|
12
|
-
function getAuthFile() {
|
|
13
|
-
return resolve(getAuthDir(), "auth.json");
|
|
14
|
-
}
|
|
15
|
-
function loadAuth() {
|
|
16
|
-
const authFile = getAuthFile();
|
|
17
|
-
if (!existsSync(authFile)) return null;
|
|
18
|
-
return readJsonFile(authFile, null);
|
|
19
|
-
}
|
|
20
|
-
function saveAuth(config) {
|
|
21
|
-
const dir = getAuthDir();
|
|
22
|
-
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
23
|
-
writeFileSync(getAuthFile(), JSON.stringify(config, null, 2), "utf-8");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export {
|
|
27
|
-
loadAuth,
|
|
28
|
-
saveAuth
|
|
29
|
-
};
|