juas.dev 1.1.1 → 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 +1 -1
- package/src/commands/list.js +26 -11
- package/src/commands/search.js +29 -14
- package/src/lib/supabase.js +28 -5
package/package.json
CHANGED
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/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
|
});
|