shadcn-studio-extension-cli 0.1.10 → 0.1.11

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.
@@ -7120,8 +7120,15 @@ const performLocalSearch = (blocks, query) => {
7120
7120
  return new Fuse(blocks, fuseLocalSearchOptions).search(query).map((result) => result.item);
7121
7121
  }, filterProBlocks = (blocks) => blocks.filter((block) => {
7122
7122
  var _a;
7123
- return ((_a = block.meta) == null ? void 0 : _a.isPro) === !1;
7124
- }), fetchBlocksFromAPI = async (isValidated) => {
7123
+ return ((_a = block.meta) == null ? void 0 : _a.isBasic) === !1;
7124
+ }), checkPlan$1 = async (licenseKey, email) => {
7125
+ const fetchPlanUrl = `https://shadcnstudio.com/api/ide-extension/plan-variant?email=${email}&license_key=${licenseKey}`;
7126
+ try {
7127
+ return (await (await fetch(fetchPlanUrl, { method: "GET" })).json()).plan_variant;
7128
+ } catch (error2) {
7129
+ console.error("Failed to fetch plan variant:", error2);
7130
+ }
7131
+ }, fetchBlocksFromAPI = async (isValidated, licenseKey, email) => {
7125
7132
  const fetchBlocksUrl = "https://shadcnstudio.com/r/blocks/registry.json?is_extension=true";
7126
7133
  try {
7127
7134
  const response = await fetch(fetchBlocksUrl, { method: "GET" });
@@ -7129,14 +7136,18 @@ const performLocalSearch = (blocks, query) => {
7129
7136
  return console.warn(
7130
7137
  `Failed to fetch blocks: ${response.status} ${response.statusText}`
7131
7138
  ), [];
7132
- let blocks = (await response.json()).items;
7133
- return isValidated || (blocks = filterProBlocks(blocks)), blocks;
7139
+ let blocks = (await response.json()).items, planVariant = "basic";
7140
+ return isValidated && licenseKey && email && (planVariant = await checkPlan$1(licenseKey, email)), console.log("User plan variant:", planVariant, "isValidated:", isValidated), (!isValidated || isValidated && planVariant === "basic") && (blocks = filterProBlocks(blocks)), blocks;
7134
7141
  } catch (error2) {
7135
7142
  return console.warn("Error fetching blocks:", error2), [];
7136
7143
  }
7137
- }, fetchAndSearchBlocks = async (query, isValidated) => {
7144
+ }, fetchAndSearchBlocks = async (query, isValidated, licenseKey, email) => {
7138
7145
  try {
7139
- const searchResults = await fetchBlocksFromAPI(isValidated);
7146
+ const searchResults = await fetchBlocksFromAPI(
7147
+ isValidated,
7148
+ licenseKey,
7149
+ email
7150
+ );
7140
7151
  if (searchResults.length === 0)
7141
7152
  return [];
7142
7153
  const fuseBlocksOptions = {
@@ -7161,7 +7172,9 @@ const performLocalSearch = (blocks, query) => {
7161
7172
  isValidated,
7162
7173
  debounceMs = 200,
7163
7174
  minScore = 0.35,
7164
- maxResults = 20
7175
+ maxResults = 20,
7176
+ licenseKey,
7177
+ email
7165
7178
  } = options2, [searchResults, setSearchResults] = useState([]), [isSearching, setIsSearching] = useState(!1), [searchError, setSearchError] = useState(null);
7166
7179
  return useEffect(() => {
7167
7180
  if (!(searchQuery != null && searchQuery.trim())) {
@@ -7173,7 +7186,12 @@ const performLocalSearch = (blocks, query) => {
7173
7186
  try {
7174
7187
  const query = searchQuery.trim().toLowerCase(), localResults = performLocalSearch(localBlocks, query);
7175
7188
  setSearchResults(localResults);
7176
- const apiResults = await fetchAndSearchBlocks(query, isValidated);
7189
+ const apiResults = await fetchAndSearchBlocks(
7190
+ query,
7191
+ isValidated,
7192
+ licenseKey,
7193
+ email
7194
+ );
7177
7195
  if (apiResults.length > 0) {
7178
7196
  const combinedResults = [...apiResults, ...localResults], uniqueResults = removeDuplicateBlocks(combinedResults);
7179
7197
  setSearchResults(uniqueResults);
@@ -7186,7 +7204,16 @@ const performLocalSearch = (blocks, query) => {
7186
7204
  }
7187
7205
  }, debounceMs);
7188
7206
  return () => clearTimeout(searchTimeout);
7189
- }, [searchQuery, localBlocks, isValidated, debounceMs, minScore, maxResults]), {
7207
+ }, [
7208
+ searchQuery,
7209
+ localBlocks,
7210
+ isValidated,
7211
+ debounceMs,
7212
+ minScore,
7213
+ maxResults,
7214
+ licenseKey,
7215
+ email
7216
+ ]), {
7190
7217
  searchResults,
7191
7218
  isSearching,
7192
7219
  searchError
@@ -7227,18 +7254,26 @@ function useLicenseKey() {
7227
7254
  }, [loadLicenseKey]);
7228
7255
  const validateLicenseKey = useCallback(
7229
7256
  async (licensekey, email) => {
7230
- if (!licensekey || typeof licensekey != "string" || !email || typeof email != "string" || !email.includes("@"))
7231
- return !1;
7232
- const trimmedLicenseKey = licensekey.trim(), validateUrl = `https://shadcnstudio.com/api/validate-user?email=${email.trim()}&license_key=${trimmedLicenseKey}`, response = await fetch(validateUrl, {
7257
+ if (!licensekey || typeof licensekey != "string")
7258
+ return { isValid: !1, message: "Invalid license key" };
7259
+ if (!email || typeof email != "string" || !email.includes("@"))
7260
+ return { isValid: !1, message: "Invalid email" };
7261
+ const trimmedLicenseKey = licensekey.trim(), validateUrl = `https://shadcnstudio.com/api/ide-extension/validate-user?email=${email.trim()}&license_key=${trimmedLicenseKey}`, response = await fetch(validateUrl, {
7233
7262
  method: "GET",
7234
7263
  headers: {
7235
7264
  "Content-Type": "application/json"
7236
7265
  }
7237
- });
7238
- return response.ok ? !0 : (console.error(
7266
+ }), data = await response.json();
7267
+ return response.ok ? {
7268
+ isValid: !0,
7269
+ message: data.message || "License key validation successful"
7270
+ } : (console.error(
7239
7271
  "License key validation request failed:",
7240
7272
  response.status
7241
- ), !1);
7273
+ ), {
7274
+ isValid: !1,
7275
+ message: data.message
7276
+ });
7242
7277
  },
7243
7278
  []
7244
7279
  ), saveLicenseKey = useCallback(
@@ -7294,7 +7329,7 @@ function useLicenseKey() {
7294
7329
  }
7295
7330
  }, []), refreshLicenseValidation = useCallback(async () => {
7296
7331
  if (!licenseState.licenseKey)
7297
- return !1;
7332
+ return { isValid: !1, message: "No license key found" };
7298
7333
  try {
7299
7334
  const isValid = await validateLicenseKey(
7300
7335
  licenseState.licenseKey,
@@ -7320,7 +7355,10 @@ function useLicenseKey() {
7320
7355
  removeLicenseKey();
7321
7356
  return isValid;
7322
7357
  } catch (error2) {
7323
- return console.error("Failed to refresh license validation:", error2), !1;
7358
+ return console.error("Failed to refresh license validation:", error2), {
7359
+ isValid: !1,
7360
+ message: "Failed to refresh license validation"
7361
+ };
7324
7362
  }
7325
7363
  }, [licenseState.licenseKey, validateLicenseKey, removeLicenseKey]), needsRevalidation = useCallback(() => licenseState.lastValidated ? (Date.now() - licenseState.lastValidated.getTime()) / (1e3 * 60 * 60) > 24 : !0, [licenseState.lastValidated]);
7326
7364
  return {
@@ -7365,7 +7403,7 @@ const RECENT_BLOCKS_KEY = "shadcnstudio-toolbar-blocks-recent", getRecentBlocks
7365
7403
  onCloseBlocks,
7366
7404
  onReady
7367
7405
  }, ref) => {
7368
- const { isValidated } = useLicenseKey(), [recentBlocks, setRecentBlocks] = useState([]);
7406
+ const { isValidated, licenseKey, email } = useLicenseKey(), [recentBlocks, setRecentBlocks] = useState([]);
7369
7407
  useEffect(() => {
7370
7408
  setRecentBlocks(getRecentBlocks());
7371
7409
  }, []);
@@ -7379,7 +7417,7 @@ const RECENT_BLOCKS_KEY = "shadcnstudio-toolbar-blocks-recent", getRecentBlocks
7379
7417
  }, [recentBlocks]), { searchResults, isSearching, searchError } = useBlockSearch(
7380
7418
  searchQuery || "",
7381
7419
  localBlocks,
7382
- { isValidated, debounceMs: 500 }
7420
+ { isValidated, debounceMs: 500, licenseKey, email }
7383
7421
  ), filteredBlocks = useMemo(() => searchQuery != null && searchQuery.trim() ? searchResults : localBlocks, [searchQuery, searchResults, localBlocks]), [activeIndex, setActiveIndex] = useState(-1), [startIndex, setStartIndex] = useState(0), [isFocused, setIsFocused] = useState(!1), containerRef = useRef(null), visibleBlocks = useMemo(() => filteredBlocks.slice(startIndex, startIndex + 3), [filteredBlocks, startIndex]);
7384
7422
  useEffect(() => {
7385
7423
  activeIndex >= filteredBlocks.length && filteredBlocks.length > 0 ? (setActiveIndex(filteredBlocks.length - 1), setStartIndex(Math.max(0, filteredBlocks.length - 3))) : filteredBlocks.length === 0 && activeIndex !== -1 && (setActiveIndex(-1), setStartIndex(0));
@@ -8013,6 +8051,16 @@ const fetchGenericThemesFromAPI = async () => {
8013
8051
  } catch (error2) {
8014
8052
  return console.warn("Error fetching themes:", error2), [];
8015
8053
  }
8054
+ }, checkPlan = async () => {
8055
+ const { email, licenseKey } = getLicenseDataFromStorage();
8056
+ if (!email || !licenseKey)
8057
+ return "basic";
8058
+ const fetchPlanUrl = `https://shadcnstudio.com/api/ide-extension/plan-variant?email=${email}&license_key=${licenseKey}`;
8059
+ try {
8060
+ return (await (await fetch(fetchPlanUrl, { method: "GET" })).json()).plan_variant;
8061
+ } catch (error2) {
8062
+ console.error("Failed to fetch plan variant:", error2);
8063
+ }
8016
8064
  }, fetchUserThemesFromAPI = async () => {
8017
8065
  const { email, licenseKey } = getLicenseDataFromStorage(), fetchThemesUrl = `https://shadcnstudio.com/api/user-themes?email=${email}&license_key=${licenseKey}&is_extension=true`;
8018
8066
  try {
@@ -8024,8 +8072,11 @@ const fetchGenericThemesFromAPI = async () => {
8024
8072
  return console.warn("Error fetching themes:", error2), [];
8025
8073
  }
8026
8074
  }, fetchThemesFromAPI = async () => {
8027
- const userThemes = await fetchUserThemesFromAPI(), genericThemes = await fetchGenericThemesFromAPI();
8028
- return userThemes.length > 0 ? [...userThemes, ...genericThemes] : genericThemes;
8075
+ const userThemes = await fetchUserThemesFromAPI(), genericThemes = await fetchGenericThemesFromAPI(), userPlan = await checkPlan(), allThemes = userThemes.length > 0 ? [...userThemes, ...genericThemes] : genericThemes;
8076
+ return userPlan === "basic" ? allThemes.filter((theme) => {
8077
+ var _a;
8078
+ return ((_a = theme.meta) == null ? void 0 : _a.isPro) !== !0;
8079
+ }) : allThemes;
8029
8080
  }, fetchAndSearchThemes = async (searchQuery) => {
8030
8081
  try {
8031
8082
  const searchResults = await fetchThemesFromAPI();
@@ -10534,9 +10585,9 @@ function LicenseKeyDialog({
10534
10585
  }
10535
10586
  setIsValidating(!0), setValidationError(null);
10536
10587
  try {
10537
- console.log("In handle Save function Validating license key:", inputKey), console.log("In handle save function With email:", email), await validateLicenseKey(inputKey.trim(), email.trim()) ? (await saveLicenseKey(inputKey.trim(), email.trim()), setInputKey(""), onClose()) : setValidationError(
10538
- "Invalid license key or Email. Please check and try again."
10539
- );
10588
+ console.log("In handle Save function Validating license key:", inputKey), console.log("In handle save function With email:", email);
10589
+ const isValid = await validateLicenseKey(inputKey.trim(), email.trim());
10590
+ console.log("License key validation result:", isValid), isValid.isValid ? (await saveLicenseKey(inputKey.trim(), email.trim()), setInputKey(""), onClose()) : (console.log("License key validation failed:", isValid), setValidationError(isValid.message || "Invalid license key or Email"));
10540
10591
  } catch (error2) {
10541
10592
  setValidationError(
10542
10593
  error2 instanceof Error ? error2.message : "Failed to validate license key"
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "shadcn-studio-extension-cli",
3
3
  "module": "src/index.ts",
4
4
  "type": "module",
5
- "version": "0.1.10",
5
+ "version": "0.1.11",
6
6
  "description": "Shadcn/Studio Extension CLI",
7
7
  "author": "stagewise GmbH",
8
8
  "license": "AGPL-3.0-only",