@trops/dash-core 0.1.217 → 0.1.219

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,30 @@ 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 — strip @ from scope for URL path
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 || "").replace(/^@/, "");
32201
+ const urlName = pkg.name || "";
32202
+ const urlVersion = pkg.version || "1.0.0";
32203
+ if (!urlScope || !urlName) {
32204
+ console.log(
32205
+ `${TAG} [2/5 URL Construction] FAIL — missing scope="${urlScope}" or name="${urlName}"`,
32206
+ );
32207
+ return {
32208
+ success: false,
32209
+ error: `Download failed: package is missing required fields (scope: "${pkg.scope || ""}", name: "${pkg.name || ""}"). The registry entry may be corrupt.`,
32210
+ };
32211
+ }
32212
+ const downloadUrl = `${registryBaseUrl}/api/packages/${encodeURIComponent(urlScope)}/${encodeURIComponent(urlName)}/download?version=${encodeURIComponent(urlVersion)}`;
32162
32213
  console.log(`${TAG} [2/5 URL Construction] url="${downloadUrl}"`);
32163
32214
 
32164
32215
  // Stage 3: Download
@@ -32175,7 +32226,19 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32175
32226
  if (auth?.token) {
32176
32227
  headers["Authorization"] = `Bearer ${auth.token}`;
32177
32228
  }
32178
- const response = await fetch(downloadUrl, { headers });
32229
+
32230
+ let response;
32231
+ try {
32232
+ response = await fetch(downloadUrl, { headers });
32233
+ } catch (fetchErr) {
32234
+ console.log(
32235
+ `${TAG} [3/5 Download] FAIL — network error: ${fetchErr.message}`,
32236
+ );
32237
+ return {
32238
+ success: false,
32239
+ error: `Download failed: could not reach the registry (${fetchErr.message}). Check your internet connection.`,
32240
+ };
32241
+ }
32179
32242
  console.log(
32180
32243
  `${TAG} [3/5 Download] status=${response.status} contentType="${response.headers.get("content-type") || "unknown"}"`,
32181
32244
  );
@@ -32187,19 +32250,59 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32187
32250
  authRequired: true,
32188
32251
  };
32189
32252
  }
32253
+ if (response.status === 404) {
32254
+ return {
32255
+ success: false,
32256
+ error: `Download failed: the registry returned 404 for scope="${urlScope}" name="${urlName}" version="${urlVersion}". The package version may not exist.`,
32257
+ };
32258
+ }
32190
32259
  if (!response.ok) {
32191
32260
  return {
32192
32261
  success: false,
32193
- error: `Failed to download theme: ${response.status} ${response.statusText}`,
32262
+ error: `Download failed: registry returned ${response.status} ${response.statusText}`,
32194
32263
  };
32195
32264
  }
32196
32265
 
32266
+ const contentType = response.headers.get("content-type") || "";
32197
32267
  const arrayBuffer = await response.arrayBuffer();
32198
32268
  const zipBuffer = Buffer.from(arrayBuffer);
32199
32269
  console.log(`${TAG} [3/5 Download] size=${zipBuffer.length} bytes`);
32200
32270
 
32271
+ if (zipBuffer.length === 0) {
32272
+ return {
32273
+ success: false,
32274
+ error: "Download failed: registry returned an empty response.",
32275
+ };
32276
+ }
32277
+
32278
+ // Check if the response is actually a ZIP (not an HTML error page or JSON error)
32279
+ if (
32280
+ contentType.includes("text/html") ||
32281
+ contentType.includes("application/json")
32282
+ ) {
32283
+ const body = zipBuffer.toString("utf-8").slice(0, 200);
32284
+ console.log(
32285
+ `${TAG} [3/5 Download] FAIL — unexpected content type "${contentType}": ${body}`,
32286
+ );
32287
+ return {
32288
+ success: false,
32289
+ error: `Download failed: registry returned ${contentType} instead of a ZIP file. The download URL may be incorrect.`,
32290
+ };
32291
+ }
32292
+
32201
32293
  // Stage 4: ZIP extraction
32202
- const zip = new AdmZip$1(zipBuffer);
32294
+ let zip;
32295
+ try {
32296
+ zip = new AdmZip$1(zipBuffer);
32297
+ } catch (zipErr) {
32298
+ console.log(
32299
+ `${TAG} [4/5 ZIP Extraction] FAIL — invalid ZIP: ${zipErr.message}`,
32300
+ );
32301
+ return {
32302
+ success: false,
32303
+ error: `ZIP extraction failed: the downloaded file is not a valid ZIP archive (${zipErr.message}).`,
32304
+ };
32305
+ }
32203
32306
  const entries = zip.getEntries();
32204
32307
  const entryNames = entries.map((e) => e.entryName);
32205
32308
  const themeEntry = entries.find((entry) =>
@@ -32215,7 +32318,7 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32215
32318
  );
32216
32319
  return {
32217
32320
  success: false,
32218
- error: "ZIP does not contain a .theme.json file",
32321
+ error: `ZIP extraction failed: no .theme.json file found in archive. Files present: [${entryNames.join(", ")}]`,
32219
32322
  };
32220
32323
  }
32221
32324
 
@@ -32224,7 +32327,10 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32224
32327
  themeEntry.entryName.includes("..") ||
32225
32328
  path$2.isAbsolute(themeEntry.entryName)
32226
32329
  ) {
32227
- return { success: false, error: "Invalid file path in ZIP" };
32330
+ return {
32331
+ success: false,
32332
+ error: "ZIP extraction failed: invalid file path detected in archive.",
32333
+ };
32228
32334
  }
32229
32335
 
32230
32336
  // Parse theme data
@@ -32235,7 +32341,7 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32235
32341
  } catch (parseErr) {
32236
32342
  return {
32237
32343
  success: false,
32238
- error: "Invalid JSON in theme file: " + parseErr.message,
32344
+ error: `ZIP extraction failed: ${themeEntry.entryName} contains invalid JSON (${parseErr.message}).`,
32239
32345
  };
32240
32346
  }
32241
32347
 
@@ -32263,7 +32369,7 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32263
32369
  console.log(`${TAG} [5/5 Theme Save] FAIL — ${saveResult.message}`);
32264
32370
  return {
32265
32371
  success: false,
32266
- error: "Failed to save theme: " + saveResult.message,
32372
+ error: `Theme save failed: ${saveResult.message}`,
32267
32373
  };
32268
32374
  }
32269
32375
 
@@ -32276,8 +32382,11 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
32276
32382
  themes: saveResult.themes,
32277
32383
  };
32278
32384
  } catch (err) {
32279
- console.error("[ThemeRegistryController] Error installing theme:", err);
32280
- return { success: false, error: err.message };
32385
+ console.error(`${TAG} Unexpected error:`, err);
32386
+ return {
32387
+ success: false,
32388
+ error: `Unexpected error during theme install: ${err.message}`,
32389
+ };
32281
32390
  }
32282
32391
  }
32283
32392