juas.dev 1.1.0 → 1.1.2
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/package.json +3 -3
- package/src/commands/list.js +26 -11
- package/src/commands/login.js +69 -20
- package/src/commands/search.js +29 -14
- package/src/lib/supabase.js +28 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "juas.dev",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Official CLI for juas.dev — install beautiful UI components directly into your React project as source files.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"repository": {
|
|
46
46
|
"type": "git",
|
|
47
|
-
"url": "https://github.com/dhiluxui/juas.dev"
|
|
47
|
+
"url": "git+https://github.com/dhiluxui/juas.dev.git"
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://juas.dev"
|
|
50
|
-
}
|
|
50
|
+
}
|
package/src/commands/list.js
CHANGED
|
@@ -8,28 +8,37 @@ import pc from "picocolors";
|
|
|
8
8
|
import { logger } from "../lib/logger.js";
|
|
9
9
|
import { listComponents } from "../lib/supabase.js";
|
|
10
10
|
|
|
11
|
-
export async function cmdList(options) {
|
|
12
|
-
|
|
11
|
+
export async function cmdList(options = {}) {
|
|
12
|
+
const isJson = Boolean(options.json);
|
|
13
|
+
if (!isJson) {
|
|
14
|
+
logger.banner();
|
|
15
|
+
}
|
|
13
16
|
|
|
14
|
-
const spinner = ora("Fetching component registry…").start();
|
|
17
|
+
const spinner = isJson ? null : ora("Fetching component registry…").start();
|
|
15
18
|
|
|
16
19
|
let components;
|
|
17
20
|
try {
|
|
18
21
|
components = await listComponents({ category: options.category });
|
|
19
|
-
spinner
|
|
22
|
+
if (spinner) {
|
|
23
|
+
spinner.succeed(`${components.length} component${components.length !== 1 ? "s" : ""} found.`);
|
|
24
|
+
}
|
|
20
25
|
} catch (err) {
|
|
21
|
-
spinner.fail("Failed to fetch registry.");
|
|
22
|
-
|
|
26
|
+
if (spinner) spinner.fail("Failed to fetch registry.");
|
|
27
|
+
if (isJson) {
|
|
28
|
+
console.log(JSON.stringify({ error: err.message }, null, 2));
|
|
29
|
+
} else {
|
|
30
|
+
logger.error(err.message);
|
|
31
|
+
}
|
|
23
32
|
process.exit(1);
|
|
24
33
|
}
|
|
25
34
|
|
|
26
|
-
if (
|
|
27
|
-
|
|
35
|
+
if (isJson) {
|
|
36
|
+
console.log(JSON.stringify(components, null, 2));
|
|
28
37
|
return;
|
|
29
38
|
}
|
|
30
39
|
|
|
31
|
-
if (
|
|
32
|
-
|
|
40
|
+
if (!components.length) {
|
|
41
|
+
logger.info("No components found.");
|
|
33
42
|
return;
|
|
34
43
|
}
|
|
35
44
|
|
|
@@ -46,7 +55,13 @@ export async function cmdList(options) {
|
|
|
46
55
|
console.log(pc.bold(pc.magenta(` ${cat}`)));
|
|
47
56
|
for (const item of items) {
|
|
48
57
|
const tags = item.tags?.slice(0, 3).map((t) => pc.dim(`#${t}`)).join(" ") ?? "";
|
|
49
|
-
|
|
58
|
+
const tierBadge =
|
|
59
|
+
item.pricing_tier && item.pricing_tier !== "free"
|
|
60
|
+
? pc.yellow("[Pro]")
|
|
61
|
+
: pc.cyan("[Free]");
|
|
62
|
+
console.log(
|
|
63
|
+
` ${pc.green(item.slug.padEnd(36))} ${tierBadge} ${pc.dim("v" + (item.latest_version ?? "?"))} ${tags}`
|
|
64
|
+
);
|
|
50
65
|
}
|
|
51
66
|
logger.blank();
|
|
52
67
|
}
|
package/src/commands/login.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
// ============================================================
|
|
4
4
|
import { spawn } from "child_process";
|
|
5
5
|
import crypto from "crypto";
|
|
6
|
+
import fs from "fs";
|
|
6
7
|
import http from "http";
|
|
8
|
+
import path from "path";
|
|
7
9
|
import readline from "readline/promises";
|
|
8
10
|
import ora from "ora";
|
|
9
11
|
import pc from "picocolors";
|
|
@@ -27,33 +29,80 @@ function timingSafeStateEqual(a, b) {
|
|
|
27
29
|
return crypto.timingSafeEqual(bufA, bufB);
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
function trySpawnDetached(command, args, spawnFn = spawn) {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
let settled = false;
|
|
35
|
+
const finish = (ok) => {
|
|
36
|
+
if (settled) return;
|
|
37
|
+
settled = true;
|
|
38
|
+
resolve(ok);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const child = spawnFn(command, args, {
|
|
34
43
|
detached: true,
|
|
35
44
|
stdio: "ignore",
|
|
45
|
+
windowsHide: true,
|
|
36
46
|
});
|
|
37
|
-
child.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
child.once("error", () => finish(false));
|
|
48
|
+
child.once("spawn", () => {
|
|
49
|
+
try {
|
|
50
|
+
child.unref();
|
|
51
|
+
} catch {
|
|
52
|
+
// Ignore unref failures on mocked/exited child processes
|
|
53
|
+
}
|
|
54
|
+
finish(true);
|
|
44
55
|
});
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
} catch {
|
|
57
|
+
finish(false);
|
|
47
58
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Safely opens the Juas CLI authorization URL in the user's default browser.
|
|
64
|
+
* Always handles async `error` (e.g. ENOENT) without crashing Node, and avoids
|
|
65
|
+
* shell-splitting `&` query parameters on Windows.
|
|
66
|
+
*/
|
|
67
|
+
export async function openExternalUrl(targetUrl, options = {}) {
|
|
68
|
+
const platform = options.platform || process.platform;
|
|
69
|
+
const spawnFn = options.spawnFn || spawn;
|
|
70
|
+
const existsFn = options.existsFn || fs.existsSync;
|
|
71
|
+
|
|
72
|
+
let parsed;
|
|
73
|
+
try {
|
|
74
|
+
parsed = new URL(targetUrl);
|
|
54
75
|
} catch {
|
|
55
76
|
return false;
|
|
56
77
|
}
|
|
78
|
+
|
|
79
|
+
const isLocal =
|
|
80
|
+
parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
|
|
81
|
+
if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && isLocal)) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (platform === "win32") {
|
|
86
|
+
const systemRoot = process.env.SystemRoot || process.env.WINDIR || "C:\\Windows";
|
|
87
|
+
const rundll32 = path.join(systemRoot, "System32", "rundll32.exe");
|
|
88
|
+
if (existsFn(rundll32)) {
|
|
89
|
+
if (await trySpawnDetached(rundll32, ["url.dll,FileProtocolHandler", parsed.href], spawnFn)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const comspec = process.env.ComSpec || path.join(systemRoot, "System32", "cmd.exe");
|
|
95
|
+
const cmdExe = existsFn(comspec) ? comspec : "cmd.exe";
|
|
96
|
+
const escapedUrl = parsed.href.replace(/&/g, "^&");
|
|
97
|
+
return trySpawnDetached(cmdExe, ["/d", "/c", "start", '""', escapedUrl], spawnFn);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (platform === "darwin") {
|
|
101
|
+
const macOpen = existsFn("/usr/bin/open") ? "/usr/bin/open" : "open";
|
|
102
|
+
return trySpawnDetached(macOpen, [parsed.href], spawnFn);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return trySpawnDetached("xdg-open", [parsed.href], spawnFn);
|
|
57
106
|
}
|
|
58
107
|
|
|
59
108
|
function isAllowedLoopbackOrigin(originHeader, expectedOrigin) {
|
|
@@ -331,7 +380,7 @@ export async function cmdLogin(options = {}) {
|
|
|
331
380
|
logger.info(pc.dim(`Waiting for approval on 127.0.0.1:${listener.port} (timeout: 3m)`));
|
|
332
381
|
logger.blank();
|
|
333
382
|
|
|
334
|
-
const opened = openExternalUrl(authUrl);
|
|
383
|
+
const opened = await openExternalUrl(authUrl);
|
|
335
384
|
if (!opened) {
|
|
336
385
|
logger.warn("Could not open browser automatically. Open the URL above manually.");
|
|
337
386
|
}
|
package/src/commands/search.js
CHANGED
|
@@ -8,38 +8,53 @@ import pc from "picocolors";
|
|
|
8
8
|
import { logger } from "../lib/logger.js";
|
|
9
9
|
import { searchComponents } from "../lib/supabase.js";
|
|
10
10
|
|
|
11
|
-
export async function cmdSearch(query, options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
export async function cmdSearch(query, options = {}) {
|
|
12
|
+
const isJson = Boolean(options.json);
|
|
13
|
+
if (!isJson) {
|
|
14
|
+
logger.banner();
|
|
15
|
+
logger.info(`Searching for: ${pc.bold(query)}`);
|
|
16
|
+
logger.blank();
|
|
17
|
+
}
|
|
15
18
|
|
|
16
|
-
const spinner = ora("Searching juas.dev…").start();
|
|
19
|
+
const spinner = isJson ? null : ora("Searching juas.dev…").start();
|
|
17
20
|
|
|
18
21
|
let results;
|
|
19
22
|
try {
|
|
20
23
|
results = await searchComponents(query);
|
|
21
|
-
spinner
|
|
24
|
+
if (spinner) {
|
|
25
|
+
spinner.succeed(`${results.length} result${results.length !== 1 ? "s" : ""}`);
|
|
26
|
+
}
|
|
22
27
|
} catch (err) {
|
|
23
|
-
spinner.fail("Search failed.");
|
|
24
|
-
|
|
28
|
+
if (spinner) spinner.fail("Search failed.");
|
|
29
|
+
if (isJson) {
|
|
30
|
+
console.log(JSON.stringify({ error: err.message }, null, 2));
|
|
31
|
+
} else {
|
|
32
|
+
logger.error(err.message);
|
|
33
|
+
}
|
|
25
34
|
process.exit(1);
|
|
26
35
|
}
|
|
27
36
|
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
logger.info(`Try browsing all: ${pc.bold("npx juas.dev list")}`);
|
|
37
|
+
if (isJson) {
|
|
38
|
+
console.log(JSON.stringify(results, null, 2));
|
|
31
39
|
return;
|
|
32
40
|
}
|
|
33
41
|
|
|
34
|
-
if (
|
|
35
|
-
|
|
42
|
+
if (!results.length) {
|
|
43
|
+
logger.warn(`No components matched "${query}".`);
|
|
44
|
+
logger.info(`Try browsing all: ${pc.bold("npx juas.dev list")}`);
|
|
36
45
|
return;
|
|
37
46
|
}
|
|
38
47
|
|
|
39
48
|
logger.blank();
|
|
40
49
|
for (const item of results) {
|
|
41
50
|
const tags = item.tags?.slice(0, 4).map((t) => pc.dim(`#${t}`)).join(" ") ?? "";
|
|
42
|
-
|
|
51
|
+
const tierBadge =
|
|
52
|
+
item.pricing_tier && item.pricing_tier !== "free"
|
|
53
|
+
? pc.yellow("[Pro]")
|
|
54
|
+
: pc.cyan("[Free]");
|
|
55
|
+
console.log(
|
|
56
|
+
` ${pc.green(pc.bold(item.slug.padEnd(36)))} ${tierBadge} ${pc.dim(item.category ?? "")}`
|
|
57
|
+
);
|
|
43
58
|
if (item.description) {
|
|
44
59
|
console.log(` ${pc.dim(item.description.slice(0, 72))}`);
|
|
45
60
|
}
|
package/src/lib/supabase.js
CHANGED
|
@@ -53,28 +53,51 @@ export async function fetchComponentBySlug(slug) {
|
|
|
53
53
|
return { component, version: versions[0] ?? null };
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Strips PostgREST filter control delimiters to prevent filter injection.
|
|
58
|
+
*/
|
|
59
|
+
export function sanitizePostgrestFilterTerm(raw) {
|
|
60
|
+
return String(raw || "")
|
|
61
|
+
.trim()
|
|
62
|
+
.replace(/[(),*]/g, " ")
|
|
63
|
+
.replace(/\s+/g, " ")
|
|
64
|
+
.trim();
|
|
65
|
+
}
|
|
66
|
+
|
|
56
67
|
/**
|
|
57
68
|
* List all published components.
|
|
58
69
|
*/
|
|
59
70
|
export async function listComponents({ category } = {}) {
|
|
60
71
|
const params = {
|
|
61
72
|
status: "in.(published,featured)",
|
|
62
|
-
select: "id,name,slug,description,category,tags,tech_stack,latest_version",
|
|
73
|
+
select: "id,name,slug,description,category,tags,tech_stack,latest_version,pricing_tier",
|
|
63
74
|
order: "name.asc",
|
|
64
75
|
limit: "200",
|
|
65
76
|
};
|
|
66
|
-
|
|
77
|
+
const safeCat = sanitizePostgrestFilterTerm(category);
|
|
78
|
+
if (safeCat) params.category = `ilike.*${safeCat}*`;
|
|
67
79
|
return supabaseGet("components", params);
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
/**
|
|
71
|
-
*
|
|
83
|
+
* Builds the PostgREST `or` query expression for component search.
|
|
84
|
+
*/
|
|
85
|
+
export function buildComponentSearchOrFilter(query) {
|
|
86
|
+
const term = sanitizePostgrestFilterTerm(query);
|
|
87
|
+
if (!term) return null;
|
|
88
|
+
return `(name.ilike.*${term}*,slug.ilike.*${term}*,description.ilike.*${term}*)`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Search components by name, slug, or description.
|
|
72
93
|
*/
|
|
73
94
|
export async function searchComponents(query) {
|
|
95
|
+
const orFilter = buildComponentSearchOrFilter(query);
|
|
96
|
+
if (!orFilter) return [];
|
|
74
97
|
return supabaseGet("components", {
|
|
75
98
|
status: "in.(published,featured)",
|
|
76
|
-
or:
|
|
77
|
-
select: "id,name,slug,description,category,tags,latest_version",
|
|
99
|
+
or: orFilter,
|
|
100
|
+
select: "id,name,slug,description,category,tags,latest_version,pricing_tier",
|
|
78
101
|
order: "name.asc",
|
|
79
102
|
limit: "50",
|
|
80
103
|
});
|