@garagem-ai/site-sdk 0.4.1 → 0.4.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/dist/index.mjs CHANGED
@@ -1199,6 +1199,116 @@ async function resolvePublicSiteId(options) {
1199
1199
  );
1200
1200
  }
1201
1201
 
1202
+ // src/studio-contract.ts
1203
+ var STUDIO_SDK_PACKAGE = "@garagem-ai/site-sdk";
1204
+ var STUDIO_SDK_CONTRACT = {
1205
+ package: STUDIO_SDK_PACKAGE,
1206
+ /**
1207
+ * Exact pin for generated Studio sites. Must be ≥ `selfInjectSince` so
1208
+ * prompts that skip the layout chrome tag match the tarball v0 installs.
1209
+ * This PR’s changeset publishes that tarball as 0.4.2 — do not generate
1210
+ * against this floor until Version Packages is on npm.
1211
+ */
1212
+ minNpmVersion: "0.4.2",
1213
+ /** First release where ListingCard and ResultsSkeleton inject the sheet. */
1214
+ selfInjectSince: "0.4.2",
1215
+ chromeStrategy: "self-inject",
1216
+ reactExports: [
1217
+ "SearchPage",
1218
+ "ListingCard",
1219
+ "usePublicSearch",
1220
+ "ResultsSkeleton"
1221
+ ],
1222
+ /**
1223
+ * Names that exist in git / the unpublished patch. Completeness treats an
1224
+ * import as `sdk-export-mismatch` when the generated pin is older than
1225
+ * `since`. Studio prompts must not mention these names at all (even as
1226
+ * “never import”) — v0 copies the identifier and the preview ESM loader
1227
+ * throws FatalRendererError.
1228
+ */
1229
+ optionalReactExports: {
1230
+ SearchPageFallback: "0.4.1",
1231
+ SearchChromeStyles: "0.4.1"
1232
+ },
1233
+ forbiddenImports: ["@garagem-ai/site-sdk/react/search.css"]
1234
+ };
1235
+ var REACT_SDK_NAMED_IMPORT_RE = /(?:^|[\n;])\s*import\s+(?!type\b)(?:type\s+)?\{([^}]+)\}\s+from\s+['"]@garagem-ai\/site-sdk\/react['"]/g;
1236
+ function coerceNpmVersion(raw) {
1237
+ if (typeof raw !== "string") return null;
1238
+ const match = raw.trim().match(/(\d+)\.(\d+)\.(\d+)/);
1239
+ return match ? `${match[1]}.${match[2]}.${match[3]}` : null;
1240
+ }
1241
+ function compareSemver(a, b) {
1242
+ const left = a.split(".").map((part) => Number(part));
1243
+ const right = b.split(".").map((part) => Number(part));
1244
+ for (let i = 0; i < 3; i += 1) {
1245
+ const delta = (left[i] ?? 0) - (right[i] ?? 0);
1246
+ if (delta !== 0) return delta;
1247
+ }
1248
+ return 0;
1249
+ }
1250
+ function parseReactSdkNamedImports(source) {
1251
+ const names = [];
1252
+ REACT_SDK_NAMED_IMPORT_RE.lastIndex = 0;
1253
+ let match;
1254
+ while ((match = REACT_SDK_NAMED_IMPORT_RE.exec(source)) !== null) {
1255
+ const body = match[1];
1256
+ if (!body) continue;
1257
+ for (const raw of body.split(",")) {
1258
+ const token = raw.trim();
1259
+ if (!token || token.startsWith("type ")) continue;
1260
+ const name = token.split(/\s+as\s+/)[0]?.trim();
1261
+ if (name) names.push(name);
1262
+ }
1263
+ }
1264
+ return names;
1265
+ }
1266
+ function reactExportsAvailableAt(pin) {
1267
+ const available = new Set(STUDIO_SDK_CONTRACT.reactExports);
1268
+ for (const [name, since] of Object.entries(
1269
+ STUDIO_SDK_CONTRACT.optionalReactExports
1270
+ )) {
1271
+ if (compareSemver(pin, since) >= 0) available.add(name);
1272
+ }
1273
+ return available;
1274
+ }
1275
+ function unavailableReactImports(source, pin) {
1276
+ const available = reactExportsAvailableAt(pin);
1277
+ const missing = [];
1278
+ for (const name of parseReactSdkNamedImports(source)) {
1279
+ if (!available.has(name) && !missing.includes(name)) {
1280
+ missing.push(name);
1281
+ }
1282
+ }
1283
+ return missing;
1284
+ }
1285
+ function studioSdkPinInstruction() {
1286
+ const version = STUDIO_SDK_CONTRACT.minNpmVersion;
1287
+ const names = STUDIO_SDK_CONTRACT.reactExports.join(", ");
1288
+ return `In \`package.json\` set \`"@garagem-ai/site-sdk": "${version}"\` (exact). Import only these \`${STUDIO_SDK_PACKAGE}/react\` names: ${names}.`;
1289
+ }
1290
+ function studioChromeInstruction() {
1291
+ const injectors = compareSemver(
1292
+ STUDIO_SDK_CONTRACT.minNpmVersion,
1293
+ STUDIO_SDK_CONTRACT.selfInjectSince
1294
+ ) >= 0 ? "`SearchPage`, `ListingCard`, and `ResultsSkeleton`" : "`SearchPage`";
1295
+ return `Search chrome CSS is injected by ${injectors} (JS \`<style>\` tag). Never \`import "@garagem-ai/site-sdk/react/search.css"\` \u2014 v0 preview cannot load npm CSS. Do not copy SDK layout into the app. Theme via CSS variables in \`app/globals.css\` (\`SEARCH_CSS_RECIPE\` / \`--garagem-*\`), \`classNames\`, and \`data-slot\`.`;
1296
+ }
1297
+ function studioCodegenContractViolations(text) {
1298
+ const violations = [];
1299
+ for (const name of Object.keys(STUDIO_SDK_CONTRACT.optionalReactExports)) {
1300
+ if (text.includes(name)) violations.push(name);
1301
+ }
1302
+ const pin = STUDIO_SDK_CONTRACT.minNpmVersion;
1303
+ const available = reactExportsAvailableAt(pin);
1304
+ for (const name of parseReactSdkNamedImports(text)) {
1305
+ if (!available.has(name) && !violations.includes(name)) {
1306
+ violations.push(name);
1307
+ }
1308
+ }
1309
+ return violations;
1310
+ }
1311
+
1202
1312
  // src/client.ts
1203
1313
  function createGaragemClient(options = {}) {
1204
1314
  const resolveSiteId = (override) => {
@@ -1336,11 +1446,15 @@ export {
1336
1446
  SEARCH_CSS_RECIPE,
1337
1447
  SEARCH_CSS_VARS,
1338
1448
  SEARCH_SORT_RELEVANCE,
1449
+ STUDIO_SDK_CONTRACT,
1450
+ STUDIO_SDK_PACKAGE,
1339
1451
  TOOLBAR_PRIMARY_FILTER_IDS,
1340
1452
  applyPathFilter,
1341
1453
  buildQueryListingsParams,
1342
1454
  canonicalizeSearchHref,
1343
1455
  clearStagedPathFilters,
1456
+ coerceNpmVersion,
1457
+ compareSemver,
1344
1458
  composeSearchPublicHref2 as composeSearchPublicHref,
1345
1459
  composeSearchPublicPath2 as composeSearchPublicPath,
1346
1460
  countFacetChoices,
@@ -1372,6 +1486,7 @@ export {
1372
1486
  paginationPages,
1373
1487
  parseAppliedSearchQuery2 as parseAppliedSearchQuery,
1374
1488
  parseGroupedInteger,
1489
+ parseReactSdkNamedImports,
1375
1490
  parseSearchPublicPath2 as parseSearchPublicPath,
1376
1491
  pathFilterHasOption,
1377
1492
  pathFilterValue,
@@ -1387,8 +1502,12 @@ export {
1387
1502
  searchResultsHeading,
1388
1503
  searchSortOptions,
1389
1504
  serializeAppliedSearchQuery2 as serializeAppliedSearchQuery,
1505
+ studioChromeInstruction,
1506
+ studioCodegenContractViolations,
1507
+ studioSdkPinInstruction,
1390
1508
  toListingCardModel,
1391
1509
  toolbarFilterIds,
1510
+ unavailableReactImports,
1392
1511
  visibleSearchFilters
1393
1512
  };
1394
1513
  //# sourceMappingURL=index.mjs.map