@trops/dash-core 0.1.218 → 0.1.220

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.
@@ -26864,14 +26864,54 @@ async function searchRegistry$1(query = "", filters = {}) {
26864
26864
  }
26865
26865
 
26866
26866
  /**
26867
- * Get a specific package by name
26867
+ * Get a specific package by name.
26868
26868
  *
26869
- * @param {string} packageName - Name of the package
26869
+ * Handles multiple naming formats:
26870
+ * - bare name: "ocean-depth"
26871
+ * - scoped name: "john/ocean-depth" or "@john/ocean-depth"
26872
+ * - displayName: "Ocean Depth"
26873
+ *
26874
+ * @param {string} packageName - Name of the package (any format)
26870
26875
  * @returns {Promise<Object|null>} Package data or null if not found
26871
26876
  */
26872
26877
  async function getPackage$1(packageName) {
26878
+ if (!packageName) return null;
26879
+
26873
26880
  const index = await fetchRegistryIndex();
26874
- const pkg = (index.packages || []).find((p) => p.name === packageName);
26881
+ const packages = index.packages || [];
26882
+
26883
+ // 1. Exact match on name
26884
+ let pkg = packages.find((p) => p.name === packageName);
26885
+ if (pkg) return pkg;
26886
+
26887
+ // 2. If input contains "/", split into scope + name and match both fields
26888
+ if (packageName.includes("/")) {
26889
+ const parts = packageName.split("/");
26890
+ const inputScope = parts[0].replace(/^@/, "");
26891
+ const inputName = parts.slice(1).join("/");
26892
+ pkg = packages.find(
26893
+ (p) =>
26894
+ p.name === inputName &&
26895
+ (p.scope || "").replace(/^@/, "") === inputScope,
26896
+ );
26897
+ if (pkg) return pkg;
26898
+ }
26899
+
26900
+ // 3. Match by displayName (case-insensitive)
26901
+ const lower = packageName.toLowerCase();
26902
+ pkg = packages.find((p) => (p.displayName || "").toLowerCase() === lower);
26903
+ if (pkg) return pkg;
26904
+
26905
+ // 4. Try bare-name match against scoped registry entries
26906
+ // (registry might store "scope/name" in p.name while caller sends just "name")
26907
+ pkg = packages.find((p) => {
26908
+ if (p.name && p.name.includes("/")) {
26909
+ const bareName = p.name.split("/").pop();
26910
+ return bareName === packageName;
26911
+ }
26912
+ return false;
26913
+ });
26914
+
26875
26915
  return pkg || null;
26876
26916
  }
26877
26917
 
@@ -32137,9 +32177,8 @@ async function prepareThemeForPublish$1(win, appId, themeKey, options = {}) {
32137
32177
  * @returns {Object} Result with success, themeKey, theme
32138
32178
  */
32139
32179
  async function installThemeFromRegistry$1(win, appId, packageName) {
32180
+ const TAG = "[ThemeInstall]";
32140
32181
  try {
32141
- const TAG = "[ThemeInstall]";
32142
-
32143
32182
  // Stage 1: Package lookup
32144
32183
  console.log(`${TAG} [1/5 Package Lookup] input="${packageName}"`);
32145
32184
  const pkg = await registryController$2.getPackage(packageName);
@@ -32147,18 +32186,31 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32147
32186
  console.log(`${TAG} [1/5 Package Lookup] FAIL — package not found`);
32148
32187
  return {
32149
32188
  success: false,
32150
- error: `Theme package "${packageName}" not found in registry`,
32189
+ error: `Package lookup failed: "${packageName}" was not found in the registry index. The package may have been removed or the name may be incorrect.`,
32151
32190
  };
32152
32191
  }
32153
32192
  console.log(
32154
32193
  `${TAG} [1/5 Package Lookup] resolved scope="${pkg.scope}" name="${pkg.name}" version="${pkg.version || "1.0.0"}"`,
32155
32194
  );
32156
32195
 
32157
- // Stage 2: URL construction
32196
+ // Stage 2: URL construction — keep scope as-is (encodeURIComponent handles @)
32158
32197
  const registryBaseUrl =
32159
32198
  process.env.DASH_REGISTRY_API_URL ||
32160
32199
  "https://main.d919rwhuzp7rj.amplifyapp.com";
32161
- const downloadUrl = `${registryBaseUrl}/api/packages/${encodeURIComponent(pkg.scope)}/${encodeURIComponent(pkg.name)}/download?version=${encodeURIComponent(pkg.version || "1.0.0")}`;
32200
+ const urlScope = pkg.scope || "";
32201
+ const urlName = pkg.name || "";
32202
+ const urlVersion = pkg.version || "1.0.0";
32203
+ if (!urlName) {
32204
+ console.log(
32205
+ `${TAG} [2/5 URL Construction] FAIL — missing name="${urlName}"`,
32206
+ );
32207
+ return {
32208
+ success: false,
32209
+ error: `Download failed: package is missing a name field. The registry entry may be corrupt.`,
32210
+ };
32211
+ }
32212
+ const scopePath = urlScope ? `${encodeURIComponent(urlScope)}/` : "";
32213
+ const downloadUrl = `${registryBaseUrl}/api/packages/${scopePath}${encodeURIComponent(urlName)}/download?version=${encodeURIComponent(urlVersion)}`;
32162
32214
  console.log(`${TAG} [2/5 URL Construction] url="${downloadUrl}"`);
32163
32215
 
32164
32216
  // Stage 3: Download
@@ -32175,7 +32227,19 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32175
32227
  if (auth?.token) {
32176
32228
  headers["Authorization"] = `Bearer ${auth.token}`;
32177
32229
  }
32178
- const response = await fetch(downloadUrl, { headers });
32230
+
32231
+ let response;
32232
+ try {
32233
+ response = await fetch(downloadUrl, { headers });
32234
+ } catch (fetchErr) {
32235
+ console.log(
32236
+ `${TAG} [3/5 Download] FAIL — network error: ${fetchErr.message}`,
32237
+ );
32238
+ return {
32239
+ success: false,
32240
+ error: `Download failed: could not reach the registry (${fetchErr.message}). Check your internet connection.`,
32241
+ };
32242
+ }
32179
32243
  console.log(
32180
32244
  `${TAG} [3/5 Download] status=${response.status} contentType="${response.headers.get("content-type") || "unknown"}"`,
32181
32245
  );
@@ -32187,19 +32251,59 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32187
32251
  authRequired: true,
32188
32252
  };
32189
32253
  }
32254
+ if (response.status === 404) {
32255
+ return {
32256
+ success: false,
32257
+ error: `Download failed: the registry returned 404 for scope="${urlScope}" name="${urlName}" version="${urlVersion}". The package version may not exist.`,
32258
+ };
32259
+ }
32190
32260
  if (!response.ok) {
32191
32261
  return {
32192
32262
  success: false,
32193
- error: `Failed to download theme: ${response.status} ${response.statusText}`,
32263
+ error: `Download failed: registry returned ${response.status} ${response.statusText}`,
32194
32264
  };
32195
32265
  }
32196
32266
 
32267
+ const contentType = response.headers.get("content-type") || "";
32197
32268
  const arrayBuffer = await response.arrayBuffer();
32198
32269
  const zipBuffer = Buffer.from(arrayBuffer);
32199
32270
  console.log(`${TAG} [3/5 Download] size=${zipBuffer.length} bytes`);
32200
32271
 
32272
+ if (zipBuffer.length === 0) {
32273
+ return {
32274
+ success: false,
32275
+ error: "Download failed: registry returned an empty response.",
32276
+ };
32277
+ }
32278
+
32279
+ // Check if the response is actually a ZIP (not an HTML error page or JSON error)
32280
+ if (
32281
+ contentType.includes("text/html") ||
32282
+ contentType.includes("application/json")
32283
+ ) {
32284
+ const body = zipBuffer.toString("utf-8").slice(0, 200);
32285
+ console.log(
32286
+ `${TAG} [3/5 Download] FAIL — unexpected content type "${contentType}": ${body}`,
32287
+ );
32288
+ return {
32289
+ success: false,
32290
+ error: `Download failed: registry returned ${contentType} instead of a ZIP file. The download URL may be incorrect.`,
32291
+ };
32292
+ }
32293
+
32201
32294
  // Stage 4: ZIP extraction
32202
- const zip = new AdmZip$1(zipBuffer);
32295
+ let zip;
32296
+ try {
32297
+ zip = new AdmZip$1(zipBuffer);
32298
+ } catch (zipErr) {
32299
+ console.log(
32300
+ `${TAG} [4/5 ZIP Extraction] FAIL — invalid ZIP: ${zipErr.message}`,
32301
+ );
32302
+ return {
32303
+ success: false,
32304
+ error: `ZIP extraction failed: the downloaded file is not a valid ZIP archive (${zipErr.message}).`,
32305
+ };
32306
+ }
32203
32307
  const entries = zip.getEntries();
32204
32308
  const entryNames = entries.map((e) => e.entryName);
32205
32309
  const themeEntry = entries.find((entry) =>
@@ -32215,7 +32319,7 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32215
32319
  );
32216
32320
  return {
32217
32321
  success: false,
32218
- error: "ZIP does not contain a .theme.json file",
32322
+ error: `ZIP extraction failed: no .theme.json file found in archive. Files present: [${entryNames.join(", ")}]`,
32219
32323
  };
32220
32324
  }
32221
32325
 
@@ -32224,7 +32328,10 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32224
32328
  themeEntry.entryName.includes("..") ||
32225
32329
  path$2.isAbsolute(themeEntry.entryName)
32226
32330
  ) {
32227
- return { success: false, error: "Invalid file path in ZIP" };
32331
+ return {
32332
+ success: false,
32333
+ error: "ZIP extraction failed: invalid file path detected in archive.",
32334
+ };
32228
32335
  }
32229
32336
 
32230
32337
  // Parse theme data
@@ -32235,7 +32342,7 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32235
32342
  } catch (parseErr) {
32236
32343
  return {
32237
32344
  success: false,
32238
- error: "Invalid JSON in theme file: " + parseErr.message,
32345
+ error: `ZIP extraction failed: ${themeEntry.entryName} contains invalid JSON (${parseErr.message}).`,
32239
32346
  };
32240
32347
  }
32241
32348
 
@@ -32263,7 +32370,7 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32263
32370
  console.log(`${TAG} [5/5 Theme Save] FAIL — ${saveResult.message}`);
32264
32371
  return {
32265
32372
  success: false,
32266
- error: "Failed to save theme: " + saveResult.message,
32373
+ error: `Theme save failed: ${saveResult.message}`,
32267
32374
  };
32268
32375
  }
32269
32376
 
@@ -32276,8 +32383,11 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32276
32383
  themes: saveResult.themes,
32277
32384
  };
32278
32385
  } catch (err) {
32279
- console.error("[ThemeRegistryController] Error installing theme:", err);
32280
- return { success: false, error: err.message };
32386
+ console.error(`${TAG} Unexpected error:`, err);
32387
+ return {
32388
+ success: false,
32389
+ error: `Unexpected error during theme install: ${err.message}`,
32390
+ };
32281
32391
  }
32282
32392
  }
32283
32393