@open-mercato/cli 0.10.1-develop.7756.1.8f5dec1b96 → 0.10.1-develop.7759.1.416727583e

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.
Files changed (120) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/agentic/guides/module-facts.json +162 -162
  3. package/dist/agentic/guides/module-facts.v2.json +162 -162
  4. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  5. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  6. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  7. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  8. package/dist/agentic/guides/modules/attachments/index.md +1 -1
  9. package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
  10. package/dist/agentic/guides/modules/auth/index.md +1 -1
  11. package/dist/agentic/guides/modules/availability/index.md +1 -1
  12. package/dist/agentic/guides/modules/business_rules/index.md +1 -1
  13. package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
  14. package/dist/agentic/guides/modules/cart/index.md +1 -1
  15. package/dist/agentic/guides/modules/catalog/index.md +1 -1
  16. package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
  17. package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
  18. package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
  19. package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
  20. package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
  21. package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
  22. package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
  23. package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
  24. package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
  25. package/dist/agentic/guides/modules/checkout/index.md +1 -1
  26. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  27. package/dist/agentic/guides/modules/configs/index.md +1 -1
  28. package/dist/agentic/guides/modules/content/index.md +1 -1
  29. package/dist/agentic/guides/modules/currencies/index.md +1 -1
  30. package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
  31. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  32. package/dist/agentic/guides/modules/customers/index.md +1 -1
  33. package/dist/agentic/guides/modules/dashboards/index.md +1 -1
  34. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  35. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  36. package/dist/agentic/guides/modules/devices/index.md +1 -1
  37. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  38. package/dist/agentic/guides/modules/directory/index.md +1 -1
  39. package/dist/agentic/guides/modules/documents/index.md +1 -1
  40. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  41. package/dist/agentic/guides/modules/entities/index.md +1 -1
  42. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  43. package/dist/agentic/guides/modules/events/index.md +1 -1
  44. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  45. package/dist/agentic/guides/modules/forms/index.md +1 -1
  46. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  47. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  48. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  49. package/dist/agentic/guides/modules/generators/index.md +1 -1
  50. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  51. package/dist/agentic/guides/modules/integrations/index.md +1 -1
  52. package/dist/agentic/guides/modules/messages/index.md +1 -1
  53. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  54. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  55. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  56. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  57. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  58. package/dist/agentic/guides/modules/planner/index.md +1 -1
  59. package/dist/agentic/guides/modules/portal/index.md +1 -1
  60. package/dist/agentic/guides/modules/progress/index.md +1 -1
  61. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  62. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  63. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  64. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  65. package/dist/agentic/guides/modules/resources/index.md +1 -1
  66. package/dist/agentic/guides/modules/sales/index.md +1 -1
  67. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  68. package/dist/agentic/guides/modules/search/index.md +1 -1
  69. package/dist/agentic/guides/modules/security/index.md +1 -1
  70. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  71. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  72. package/dist/agentic/guides/modules/sso/index.md +1 -1
  73. package/dist/agentic/guides/modules/staff/index.md +1 -1
  74. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  75. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  76. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  77. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  78. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  79. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  80. package/dist/agentic/guides/modules/translations/index.md +1 -1
  81. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  82. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  83. package/dist/agentic/guides/modules/wms/index.md +1 -1
  84. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  85. package/dist/agentic/guides/reference-module-facts.json +1 -1
  86. package/dist/agentic/guides/upstream/manifest.json +1 -1
  87. package/dist/lib/__integration__/TC-INT-007.spec.js +17 -0
  88. package/dist/lib/__integration__/TC-INT-007.spec.js.map +2 -2
  89. package/dist/lib/module-install.js +46 -8
  90. package/dist/lib/module-install.js.map +2 -2
  91. package/dist/lib/module-search-args.js +97 -0
  92. package/dist/lib/module-search-args.js.map +7 -0
  93. package/dist/lib/module-search-index.js +677 -0
  94. package/dist/lib/module-search-index.js.map +7 -0
  95. package/dist/lib/module-search.js +668 -0
  96. package/dist/lib/module-search.js.map +7 -0
  97. package/dist/lib/modules-config.js +105 -27
  98. package/dist/lib/modules-config.js.map +2 -2
  99. package/dist/lib/resolver.js +21 -1
  100. package/dist/lib/resolver.js.map +2 -2
  101. package/dist/mercato.js +32 -15
  102. package/dist/mercato.js.map +2 -2
  103. package/package.json +8 -7
  104. package/src/__tests__/mercato.test.ts +57 -0
  105. package/src/lib/__fixtures__/module-search/README.md +97 -0
  106. package/src/lib/__fixtures__/module-search/built-in.json +235 -0
  107. package/src/lib/__fixtures__/module-search/catalog-parity.json +4076 -0
  108. package/src/lib/__fixtures__/module-search/modules-index.json +1980 -0
  109. package/src/lib/__integration__/TC-INT-007.spec.ts +22 -0
  110. package/src/lib/__tests__/module-install.test.ts +220 -14
  111. package/src/lib/__tests__/module-search.test.ts +929 -0
  112. package/src/lib/__tests__/modules-config.test.ts +273 -1
  113. package/src/lib/__tests__/resolver.enterprise.test.ts +60 -0
  114. package/src/lib/module-install.ts +54 -10
  115. package/src/lib/module-search-args.ts +116 -0
  116. package/src/lib/module-search-index.ts +1033 -0
  117. package/src/lib/module-search.ts +952 -0
  118. package/src/lib/modules-config.ts +153 -36
  119. package/src/lib/resolver.ts +23 -1
  120. package/src/mercato.ts +36 -11
@@ -0,0 +1,677 @@
1
+ import MiniSearch from "minisearch";
2
+ import { satisfies } from "semver";
3
+ const SEARCH_BOOST = {
4
+ title: 3,
5
+ npm: 3,
6
+ summary: 2,
7
+ whenToUse: 2,
8
+ providers: 2,
9
+ tags: 1.5,
10
+ aliases: 1.5,
11
+ renamedFrom: 1,
12
+ category: 1,
13
+ anatomy: 1
14
+ };
15
+ const SEARCH_FIELDS = Object.keys(SEARCH_BOOST);
16
+ const ALIASES_META_KEY = "com.openmercato.modules/aliases";
17
+ const INSTALLABLE_META_KEY = "com.openmercato.modules/installable";
18
+ const BUILTIN_MAX = 5;
19
+ const BUILTIN_RATIO = 0.5;
20
+ const BOOST_VERIFIED = 0.15;
21
+ const BOOST_OFFICIAL = 0.1;
22
+ const MIN_AND_RESULTS = 3;
23
+ const WEAK_HIT_RATIO = 0.2;
24
+ const SEARCH_MAX_LIMIT = 20;
25
+ const SEARCH_DEFAULTS = { verifiedOnly: false, includeBuiltIn: true, includeExamples: false, limit: 10 };
26
+ const CORE_PACKAGE = "@open-mercato/core";
27
+ const ENTERPRISE_PACKAGE = "@open-mercato/enterprise";
28
+ const ENTERPRISE_ENABLE_STEP = "echo OM_ENABLE_ENTERPRISE_MODULES=true >> .env";
29
+ const PREVIEW_LINE = "Receipts: Preview run in Docker on the maintainer's machine, not CI. The first nightly CI run replaces it.";
30
+ const VERDICT_STATES = /* @__PURE__ */ new Set(["verified", "broken", "harness-red", "infra-error"]);
31
+ const STOPWORDS = /* @__PURE__ */ new Set([
32
+ "a",
33
+ "an",
34
+ "and",
35
+ "are",
36
+ "as",
37
+ "at",
38
+ "be",
39
+ "by",
40
+ "for",
41
+ "from",
42
+ "i",
43
+ "in",
44
+ "into",
45
+ "is",
46
+ "it",
47
+ "its",
48
+ "me",
49
+ "module",
50
+ "modules",
51
+ "my",
52
+ "of",
53
+ "on",
54
+ "or",
55
+ "our",
56
+ "that",
57
+ "the",
58
+ "this",
59
+ "to",
60
+ "via",
61
+ "we",
62
+ "with",
63
+ "you",
64
+ "your",
65
+ "can",
66
+ "do",
67
+ "does",
68
+ "how",
69
+ "need",
70
+ "needs",
71
+ "use",
72
+ "used",
73
+ "uses",
74
+ "want",
75
+ "wants",
76
+ "what",
77
+ "when",
78
+ "which"
79
+ ]);
80
+ function tokenize(text) {
81
+ const lower = text.toLowerCase();
82
+ const tokens = lower.split(/[^a-z0-9*]+/).filter((token) => token !== "");
83
+ for (const match of lower.matchAll(/[a-z0-9]+(?:[._-][a-z0-9*]+)+/g)) tokens.push(match[0]);
84
+ return tokens;
85
+ }
86
+ function processTerm(term) {
87
+ return term.length < 2 || STOPWORDS.has(term) ? null : term;
88
+ }
89
+ const SEARCH_OPTIONS = {
90
+ idField: "id",
91
+ fields: SEARCH_FIELDS,
92
+ storeFields: ["group"],
93
+ tokenize,
94
+ processTerm,
95
+ searchOptions: { prefix: true, fuzzy: 0.2, boost: { ...SEARCH_BOOST } }
96
+ };
97
+ function anatomyIds(anatomy, moduleIds) {
98
+ const lists = anatomy?.lists;
99
+ return {
100
+ event: [.../* @__PURE__ */ new Set([...lists?.eventsEmitted ?? [], ...lists?.eventsConsumed ?? []])],
101
+ emits: [...lists?.eventsEmitted ?? []],
102
+ consumes: [...lists?.eventsConsumed ?? []],
103
+ entity: lists?.tables ?? [],
104
+ permission: lists?.aclFeatures ?? [],
105
+ env: lists?.env ?? [],
106
+ host: lists?.hosts ?? [],
107
+ setting: (lists?.credentials ?? []).map((credential) => credential.key),
108
+ module: [...moduleIds]
109
+ };
110
+ }
111
+ const anatomyText = (ids) => [...ids.module, ...ids.entity, ...ids.event, ...ids.permission, ...ids.setting, ...ids.env, ...ids.host].join(" ");
112
+ function aliasesOf(entry) {
113
+ const value = entry._meta?.[ALIASES_META_KEY];
114
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
115
+ }
116
+ function moduleDoc(entry, ids) {
117
+ return {
118
+ id: entry.locator,
119
+ group: "module",
120
+ title: entry.title,
121
+ npm: [entry.npm ?? entry.locator.replace(/^github:/, ""), entry.path].join(" "),
122
+ summary: entry.summary,
123
+ whenToUse: entry.whenToUse,
124
+ providers: entry.providers.map((provider) => `${provider.name} ${provider.label}`).join(" "),
125
+ tags: entry.tags.join(" "),
126
+ aliases: aliasesOf(entry).join(" "),
127
+ renamedFrom: entry.renamedFrom.map((locator) => locator.replace(/^(npm|github):/, "")).join(" "),
128
+ category: entry.category,
129
+ anatomy: anatomyText(ids)
130
+ };
131
+ }
132
+ function builtInDoc(coreModule, ids) {
133
+ return {
134
+ id: `core:${coreModule.id}`,
135
+ group: "builtin",
136
+ title: coreModule.title,
137
+ npm: coreModule.id,
138
+ summary: coreModule.description,
139
+ whenToUse: "",
140
+ providers: "",
141
+ tags: "",
142
+ aliases: "",
143
+ renamedFrom: "",
144
+ category: coreModule.category,
145
+ anatomy: anatomyText(ids)
146
+ };
147
+ }
148
+ function createCatalogSearcher(index, builtIn) {
149
+ const miniSearch = new MiniSearch(SEARCH_OPTIONS);
150
+ const modules = /* @__PURE__ */ new Map();
151
+ const builtInModules = /* @__PURE__ */ new Map();
152
+ const docs = [];
153
+ for (const entry of index.entries.filter((candidate) => candidate.listed)) {
154
+ const ids = anatomyIds(entry.anatomy, entry.moduleIds);
155
+ modules.set(entry.locator, {
156
+ entry,
157
+ ids,
158
+ example: entry.tags.includes("example"),
159
+ omQuality: entry.quality !== null && entry.quality !== void 0
160
+ });
161
+ docs.push(moduleDoc(entry, ids));
162
+ }
163
+ for (const coreModule of builtIn?.modules ?? []) {
164
+ const ids = anatomyIds(coreModule.anatomy, [coreModule.id]);
165
+ builtInModules.set(coreModule.id, { module: coreModule, ids });
166
+ docs.push(builtInDoc(coreModule, ids));
167
+ }
168
+ miniSearch.addAll(docs);
169
+ const loaded = MiniSearch.loadJS(miniSearch.toJSON(), SEARCH_OPTIONS);
170
+ return { miniSearch: loaded, index, builtIn, site: index.site.replace(/\/+$/, ""), modules, builtInModules };
171
+ }
172
+ const absolute = (site, page) => /^https?:\/\//.test(page) ? page : `${site}${page}`;
173
+ function latestLine(lines) {
174
+ return lines.find((line) => line.source === "latest") ?? null;
175
+ }
176
+ const SEMVER = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
177
+ function resolveLine(omVersion, lines) {
178
+ const found = (line2) => line2 ? { line: line2.key, version: line2.version, note: null } : { line: null, version: null, note: null };
179
+ const raw = (omVersion ?? "").trim();
180
+ if (raw === "") return found(latestLine(lines));
181
+ const byKey = lines.find((line2) => line2.key === raw);
182
+ if (byKey) return found(byKey);
183
+ const version = raw.replace(/^(?:v|=|\^|~|>=)\s*/, "");
184
+ const exact = lines.find((line2) => line2.version === version);
185
+ if (exact) return found(exact);
186
+ const semver = SEMVER.exec(version);
187
+ if (semver && semver[4] && /(^|[.-])develop([.-]|$)/.test(semver[4])) {
188
+ const next = lines.find((line2) => line2.source === "develop");
189
+ if (next) return found(next);
190
+ }
191
+ const majorMinor = /^(\d+)\.(\d+)(?:\.\d+)?(?:-[0-9A-Za-z.-]+)?$/.exec(version);
192
+ if (!majorMinor) return { line: null, version: null, note: "Unknown Open Mercato version." };
193
+ const key = `${Number(majorMinor[1])}.${Number(majorMinor[2])}`;
194
+ const line = lines.find((candidate) => candidate.key === key);
195
+ if (line) return found(line);
196
+ return { line: null, version: null, note: `Line ${key} is not tested by the catalog.` };
197
+ }
198
+ function matchedOn(match, meta, queryTerms = []) {
199
+ const chips = [];
200
+ const add = (chip) => {
201
+ if (!chips.includes(chip)) chips.push(chip);
202
+ };
203
+ const has = (id, term) => tokenize(id).includes(term);
204
+ const order = ["title", "npm", "aliases", "renamedFrom", "providers", "anatomy", "summary", "whenToUse", "tags", "category"];
205
+ const typed = new Set(queryTerms);
206
+ const fieldsByTerm = Object.entries(match).sort(
207
+ (left, right) => Number(typed.has(right[0])) - Number(typed.has(left[0])) || right[0].length - left[0].length
208
+ );
209
+ for (const field of order) {
210
+ for (const [term, fields] of fieldsByTerm) {
211
+ if (!fields.includes(field)) continue;
212
+ if (field === "title" || field === "npm" || field === "aliases" || field === "renamedFrom") add("name");
213
+ else if (field === "summary" || field === "whenToUse") add("summary");
214
+ else if (field === "tags") {
215
+ const tag = meta.tags?.find((candidate) => has(candidate, term));
216
+ add(tag ? `tag ${tag}` : "summary");
217
+ } else if (field === "category" && meta.category) add(`category ${meta.category}`);
218
+ else if (field === "providers") {
219
+ const provider = meta.providers?.find((candidate) => has(candidate.name, term) || has(candidate.label, term));
220
+ add(provider ? `provider ${provider.label}` : "provider");
221
+ } else if (field === "anatomy") anatomyChips(meta.ids, fieldsByTerm, has).forEach(add);
222
+ }
223
+ }
224
+ return chips.slice(0, 5);
225
+ }
226
+ function anatomyChips(ids, fieldsByTerm, has) {
227
+ const kinds = ["event", "entity", "permission", "env", "setting", "host", "module"];
228
+ const terms = fieldsByTerm.filter(([, fields]) => fields.includes("anatomy")).map(([term]) => term);
229
+ const left = new Set(terms);
230
+ const chips = [];
231
+ while (left.size > 0) {
232
+ let best = null;
233
+ for (const kind of kinds)
234
+ for (const id of ids[kind]) {
235
+ const covers = terms.filter((term) => left.has(term) && (id === term || has(id, term)));
236
+ if (covers.length === 0) continue;
237
+ const exact = covers.includes(id);
238
+ const first = terms.indexOf(covers[0]);
239
+ const better = !best || covers.length > best.covers.length || covers.length === best.covers.length && (exact && !best.exact ? true : exact === best.exact && first < best.first);
240
+ if (better) best = { chip: `${kind} ${id}`, covers, exact, first };
241
+ }
242
+ if (!best) break;
243
+ chips.push(best.chip);
244
+ for (const term of best.covers) left.delete(term);
245
+ }
246
+ return chips;
247
+ }
248
+ const STABLE_VERSION = /^\d+\.\d+\.\d+$/;
249
+ function satisfiesRange(version, range) {
250
+ try {
251
+ return satisfies(version, range, { includePrerelease: true });
252
+ } catch {
253
+ return false;
254
+ }
255
+ }
256
+ function lineVersion(entry, line) {
257
+ return (line !== null ? entry.compat.ships?.[line] : void 0) ?? installVersion(entry, line);
258
+ }
259
+ function judgedCell(entry, line) {
260
+ const cell = entry.compat.lines[line] ?? null;
261
+ if (!cell || cell.moduleVersion === null || cell.moduleVersion === void 0 || !VERDICT_STATES.has(cell.status)) return cell;
262
+ const installs = lineVersion(entry, line);
263
+ return installs === null || cell.moduleVersion === installs ? cell : null;
264
+ }
265
+ function statusOn(entry, line) {
266
+ if (entry.version.recommended[line]) return "verified";
267
+ return judgedCell(entry, line)?.status ?? "untested";
268
+ }
269
+ function installableOn(entry, line) {
270
+ if (line === null) return void 0;
271
+ const map = entry._meta?.[INSTALLABLE_META_KEY];
272
+ if (!map || typeof map !== "object") return void 0;
273
+ const value = map[line];
274
+ return typeof value === "string" ? value : value === null ? null : void 0;
275
+ }
276
+ function installVersion(entry, line) {
277
+ return (line !== null ? entry.version.recommended[line] : null) ?? installableOn(entry, line) ?? entry.version.latest ?? entry.version.preview ?? null;
278
+ }
279
+ function declaredRangeOf(entry, version) {
280
+ const builtFor = entry.compat.builtFor;
281
+ if (!builtFor || builtFor.kind === "missing" || builtFor.kind === "star") return null;
282
+ if (builtFor.ranges) {
283
+ for (const [line, range] of Object.entries(builtFor.ranges)) if (lineVersion(entry, line) === version) return range;
284
+ return null;
285
+ }
286
+ const lines = /* @__PURE__ */ new Set([...Object.keys(entry.compat.lines), ...Object.keys(entry.compat.ships ?? {})]);
287
+ return [...lines].some((line) => lineVersion(entry, line) === version) ? builtFor.range : null;
288
+ }
289
+ function emptyPresetVersion(entry, line) {
290
+ const version = installVersion(entry, line);
291
+ if (line === null || !version) return version;
292
+ const ships = entry.compat.ships?.[line];
293
+ if (!ships || ships === version) return version;
294
+ const isolation = entry.compat.isolation?.[line];
295
+ if (isolation?.moduleVersion === version) return isolation.status === "broken" ? ships : version;
296
+ const range = declaredRangeOf(entry, version);
297
+ return STABLE_VERSION.test(ships) && range !== null && !satisfiesRange(ships, range) ? ships : version;
298
+ }
299
+ function builtInEnableCommand(id) {
300
+ return `yarn mercato module enable ${CORE_PACKAGE} --module ${id}`;
301
+ }
302
+ const isAdapter = (entry) => entry.kind === "provider" && entry.moduleIds.length === 0;
303
+ function peerLibrarySpecs(entry, version, line, find) {
304
+ if (!find || !entry.npm || !isAdapter(entry)) return [];
305
+ const specs = [];
306
+ for (const requirement of entry.requires ?? []) {
307
+ const peer = requirement.resolvesTo?.startsWith("npm:") ? find(requirement.resolvesTo) : null;
308
+ if (!peer?.npm || peer.kind !== "library" || peer.npm === entry.npm) continue;
309
+ const sameRelease = Boolean(version) && peer.npm.startsWith("@open-mercato/") && entry.npm.startsWith("@open-mercato/");
310
+ const peerVersion = sameRelease ? version : installVersion(peer, line);
311
+ const spec = peerVersion ? `${peer.npm}@${peerVersion}` : peer.npm;
312
+ if (!specs.includes(spec)) specs.push(spec);
313
+ }
314
+ return specs;
315
+ }
316
+ function packageCommand(entry, spec, peers = []) {
317
+ if (entry.kind === "tool") return entry.tags.includes("cli") ? `npx ${spec}` : `yarn add ${spec}`;
318
+ if (isAdapter(entry)) return `yarn add ${[...peers, spec].join(" ")}`;
319
+ return entry.kind === "library" ? `yarn add ${spec}` : null;
320
+ }
321
+ function inPreset(entry, enabled) {
322
+ if (!enabled || !entry.npm || entry.moduleIds.length === 0) return false;
323
+ return entry.moduleIds.every((id) => enabled.some((item) => item.id === id && item.from === entry.npm));
324
+ }
325
+ function installCli(entry, line, preset, version = installVersion(entry, line), find) {
326
+ if (entry.npm === null) {
327
+ const repo = entry.locator.replace(/^github:/, "");
328
+ const ref = entry.version.gitRef ? ` --ref ${entry.version.gitRef}` : "";
329
+ return `npx create-mercato-module install ${repo}${ref}`;
330
+ }
331
+ const spec = version ? `${entry.npm}@${version}` : entry.npm;
332
+ const own = packageCommand(entry, spec, peerLibrarySpecs(entry, version, line, find));
333
+ if (own) return own;
334
+ if (inPreset(entry, preset)) return `yarn add ${spec}`;
335
+ const moduleFlag = entry.install.moduleFlag ?? null;
336
+ if (entry.npm === ENTERPRISE_PACKAGE && !moduleFlag) return `${ENTERPRISE_ENABLE_STEP} && yarn generate`;
337
+ const thirdParty = entry.npm.startsWith("@open-mercato/") ? "" : " --allow-third-party";
338
+ if (!moduleFlag && entry.moduleIds.length > 1) {
339
+ return entry.moduleIds.map((id) => `yarn mercato module add ${spec}${thirdParty} --module ${id}`).join(" && ");
340
+ }
341
+ return `yarn mercato module add ${spec}${thirdParty}${moduleFlag ? ` --module ${moduleFlag}` : ""}`;
342
+ }
343
+ function installCommand(entry, line, latest, find) {
344
+ if (line === null || line === latest) return entry.install.cli;
345
+ const both = entry.npm !== null && (entry.compat.inEmptyPreset ?? []).includes(line);
346
+ const version = (entry.compat.inPresets ?? []).includes(line) ? emptyPresetVersion(entry, line) : installVersion(entry, line);
347
+ const npm = entry.npm;
348
+ return installCli(entry, line, both && npm ? entry.moduleIds.map((id) => ({ id, from: npm })) : null, version, find);
349
+ }
350
+ function listAnd(items) {
351
+ return items.length <= 1 ? items[0] ?? "" : `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
352
+ }
353
+ const EMPTY_PRESET_LEAD = "In an app from the empty preset:";
354
+ function presetInstallText(moduleIds) {
355
+ return `Nothing to install: a new app already registers ${moduleIds.length ? listAnd(moduleIds) : "it"} in src/modules.ts.`;
356
+ }
357
+ function newAppInstallText(moduleIds, emptyCommand) {
358
+ return emptyCommand ? `${presetInstallText(moduleIds)} ${EMPTY_PRESET_LEAD} ${emptyCommand}` : presetInstallText(moduleIds);
359
+ }
360
+ function installFields(entry, line, latest, find) {
361
+ const command = installCommand(entry, line, latest, find);
362
+ if (line === null || !(entry.compat.inPresets ?? []).includes(line)) return { install: command };
363
+ const empty = (entry.compat.inEmptyPreset ?? []).includes(line) ? null : command;
364
+ return {
365
+ install: presetInstallText(entry.moduleIds),
366
+ presetNote: newAppInstallText(entry.moduleIds, empty),
367
+ installEmptyPreset: empty
368
+ };
369
+ }
370
+ function builtInPresetText(coreModule, line) {
371
+ if (!line || !coreModule.inPresets?.includes(line)) return null;
372
+ const on = `On in a new app on ${line}: nothing to enable.`;
373
+ if (coreModule.inEmptyPreset?.includes(line)) return on;
374
+ return `${on} ${EMPTY_PRESET_LEAD} ${coreModule.install || builtInEnableCommand(coreModule.id)}`;
375
+ }
376
+ function builtInNotes(coreModule, line) {
377
+ const text = builtInPresetText(coreModule, line);
378
+ if (text) return [`Built into Open Mercato core as ${coreModule.id}.`, text];
379
+ return [`Built into Open Mercato core as ${coreModule.id}. Enable it: ${builtInEnableCommand(coreModule.id)}`];
380
+ }
381
+ function relevanceCompare(line) {
382
+ const level = (meta) => meta.omQuality ? 0 : meta.entry.tier === "verified" ? 1 : meta.entry.tier === "listed" ? 2 : 3;
383
+ const fresh = (meta) => {
384
+ const at = line ? judgedCell(meta.entry, line)?.at : null;
385
+ return at ? Date.parse(at) : 0;
386
+ };
387
+ return (left, right) => level(left) - level(right) || Number(right.entry.featured) - Number(left.entry.featured) || fresh(right) - fresh(left) || left.entry.title.localeCompare(right.entry.title);
388
+ }
389
+ function swapVariants(query) {
390
+ const words = query.trim().toLowerCase().split(/\s+/).filter(Boolean);
391
+ if (words.length > 6) return [];
392
+ const variants = [];
393
+ words.forEach((word, wordIndex) => {
394
+ if (word.length < 3 || word.length > 24 || !/^[a-z0-9]+$/.test(word) || processTerm(word) === null) return;
395
+ for (let index = 0; index < word.length - 1; index++) {
396
+ if (word[index] === word[index + 1]) continue;
397
+ const swapped = `${word.slice(0, index)}${word[index + 1]}${word[index]}${word.slice(index + 2)}`;
398
+ variants.push([...words.slice(0, wordIndex), swapped, ...words.slice(wordIndex + 1)].join(" "));
399
+ }
400
+ });
401
+ return [...new Set(variants)].slice(0, 60);
402
+ }
403
+ function rankModules(searcher, rawInput) {
404
+ const input = {
405
+ ...rawInput,
406
+ query: rawInput.query ?? "",
407
+ verifiedOnly: rawInput.verifiedOnly ?? SEARCH_DEFAULTS.verifiedOnly,
408
+ includeBuiltIn: rawInput.includeBuiltIn ?? SEARCH_DEFAULTS.includeBuiltIn,
409
+ includeExamples: rawInput.includeExamples ?? SEARCH_DEFAULTS.includeExamples
410
+ };
411
+ const lines = searcher.index.lines;
412
+ const latest = latestLine(lines)?.key ?? null;
413
+ const line = input.omVersion ? resolveLine(input.omVersion, lines).line : latest;
414
+ const boostDocument = (id) => {
415
+ const meta = searcher.modules.get(String(id));
416
+ if (!meta) return 1;
417
+ const verified = line !== null && statusOn(meta.entry, line) === "verified" ? 1 : 0;
418
+ return 1 + BOOST_VERIFIED * verified + BOOST_OFFICIAL * (meta.entry.type === "official" ? 1 : 0);
419
+ };
420
+ const wantKinds = input.kind;
421
+ const provider = input.provider?.toLowerCase();
422
+ const providerMatches = (item) => item.name === provider || item.label.toLowerCase() === provider;
423
+ const moduleOk = (meta) => {
424
+ const entry = meta.entry;
425
+ return entry.listed && (input.includeExamples || !meta.example) && (!input.category || entry.category === input.category) && (!input.type || input.type.includes(entry.type)) && (!wantKinds || wantKinds.includes(entry.kind)) && (!input.verifiedOnly || line !== null && statusOn(entry, line) === "verified") && (!input.verifiedModulesOnly || entry.kind !== "module" || line !== null && Boolean(entry.version.recommended[line])) && (!input.emits || meta.ids.emits.includes(input.emits)) && (!input.consumes || meta.ids.consumes.includes(input.consumes)) && (!provider || entry.providers.some(providerMatches));
426
+ };
427
+ const builtInOk = (meta) => input.includeBuiltIn && (!wantKinds || wantKinds.includes("built-in")) && (!input.type || input.type.includes("official")) && (!input.category || meta.module.category === input.category) && !input.provider && !input.verifiedOnly && (!input.emits || meta.ids.emits.includes(input.emits)) && (!input.consumes || meta.ids.consumes.includes(input.consumes));
428
+ const builtInCard = (meta, chips) => ({
429
+ id: meta.module.id,
430
+ title: meta.module.title,
431
+ description: meta.module.description,
432
+ category: meta.module.category,
433
+ enabled: null,
434
+ install: meta.module.install || builtInEnableCommand(meta.module.id),
435
+ page: absolute(searcher.site, meta.module.page),
436
+ matchedOn: chips,
437
+ presetNote: builtInPresetText(meta.module, line)
438
+ });
439
+ const filtered = Boolean(
440
+ input.category || input.emits || input.consumes || input.provider || input.type || wantKinds || input.verifiedOnly
441
+ );
442
+ const words = tokenize(input.query).some((term) => processTerm(term) !== null);
443
+ if (input.query.trim() === "" || filtered && !words) {
444
+ const filterChips = (category, providers) => [
445
+ ...input.emits ? [`event ${input.emits}`] : [],
446
+ ...input.consumes && input.consumes !== input.emits ? [`event ${input.consumes}`] : [],
447
+ ...provider ? providers.filter(providerMatches).slice(0, 1).map((item) => `provider ${item.label}`) : [],
448
+ ...input.category ? [`category ${category}`] : []
449
+ ];
450
+ const modules2 = [...searcher.modules.values()].filter(moduleOk).sort(relevanceCompare(line));
451
+ const narrowed = Boolean(input.category || input.emits || input.consumes || wantKinds);
452
+ const builtIns = narrowed ? [...searcher.builtInModules.values()].filter(builtInOk).sort((left, right) => left.module.title.localeCompare(right.module.title)) : [];
453
+ return {
454
+ line,
455
+ latest,
456
+ modules: modules2.map((meta) => ({ meta, matchedOn: filterChips(meta.entry.category, meta.entry.providers) })),
457
+ builtIn: builtIns.slice(0, BUILTIN_MAX).map((meta) => builtInCard(meta, filterChips(meta.module.category, []))),
458
+ didYouMean: null
459
+ };
460
+ }
461
+ const run = (combineWith, query2 = input.query) => {
462
+ const hits = searcher.miniSearch.search(query2, {
463
+ combineWith,
464
+ prefix: true,
465
+ fuzzy: 0.2,
466
+ boost: { ...SEARCH_BOOST },
467
+ boostDocument
468
+ });
469
+ const modules2 = [];
470
+ const builtIns = [];
471
+ for (const result of hits) {
472
+ const id = String(result.id);
473
+ if (result["group"] === "builtin") {
474
+ const meta = searcher.builtInModules.get(id.replace(/^core:/, ""));
475
+ if (meta && builtInOk(meta)) builtIns.push({ meta, result });
476
+ } else {
477
+ const meta = searcher.modules.get(id);
478
+ if (meta && moduleOk(meta)) modules2.push({ meta, result });
479
+ }
480
+ }
481
+ return { modules: modules2, builtIns };
482
+ };
483
+ const none = (hits) => hits.modules.length === 0 && hits.builtIns.length === 0;
484
+ const topOf = (hits) => Math.max(hits.modules[0]?.result.score ?? 0, hits.builtIns[0]?.result.score ?? 0);
485
+ const typed = new Set(tokenize(input.query).filter((term) => processTerm(term) !== null));
486
+ const strong = (hits, top) => hits.filter((hit) => hit.result.score >= WEAK_HIT_RATIO * top || Object.keys(hit.result.match).some((term) => typed.has(term)));
487
+ let found = run("AND");
488
+ let didYouMean = null;
489
+ if (none(found)) {
490
+ const orHits = run("OR");
491
+ const top = topOf(orHits);
492
+ found = { modules: strong(orHits.modules, top), builtIns: strong(orHits.builtIns, top) };
493
+ if (none(found)) {
494
+ let best2 = null;
495
+ for (const variant of swapVariants(input.query)) {
496
+ const hits = run("AND", variant);
497
+ const top2 = topOf(hits);
498
+ if (!none(hits) && (!best2 || top2 > best2.top)) best2 = { variant, hits, top: top2 };
499
+ }
500
+ if (best2) {
501
+ found = best2.hits;
502
+ didYouMean = best2.variant;
503
+ }
504
+ }
505
+ } else if (found.modules.length < MIN_AND_RESULTS && tokenize(input.query).filter((term) => processTerm(term)).length > 1) {
506
+ const orHits = run("OR");
507
+ const top = Math.max(topOf(found), topOf(orHits));
508
+ const seen = new Set(found.modules.map((hit) => hit.meta.entry.locator));
509
+ found = {
510
+ modules: [...found.modules, ...strong(orHits.modules, top).filter((hit) => !seen.has(hit.meta.entry.locator))],
511
+ builtIns: found.builtIns
512
+ };
513
+ }
514
+ const best = found.modules[0]?.result.score ?? 0;
515
+ const query = (didYouMean ?? input.query).trim().toLowerCase();
516
+ const builtIn = found.builtIns.filter(
517
+ ({ meta, result }) => result.score >= BUILTIN_RATIO * best || meta.module.title.toLowerCase() === query || meta.module.id === query.replace(/[\s-]+/g, "_")
518
+ ).slice(0, BUILTIN_MAX).map(({ meta, result }) => builtInCard(meta, matchedOn(result.match, { ids: meta.ids }, result.queryTerms)));
519
+ const modules = found.modules.map(({ meta, result }) => ({
520
+ meta,
521
+ matchedOn: matchedOn(
522
+ result.match,
523
+ { providers: meta.entry.providers, tags: meta.entry.tags, ids: meta.ids, category: meta.entry.category },
524
+ result.queryTerms
525
+ )
526
+ }));
527
+ return { line, latest, modules, builtIn, didYouMean };
528
+ }
529
+ function toModuleCard(searcher, hit, line, latest) {
530
+ const entry = hit.meta.entry;
531
+ return {
532
+ locator: entry.locator,
533
+ path: entry.path,
534
+ title: entry.title,
535
+ summary: entry.summary,
536
+ whenToUse: entry.whenToUse,
537
+ type: entry.type,
538
+ kind: entry.kind,
539
+ category: entry.category,
540
+ license: { spdx: entry.license.spdx, kind: entry.license.kind },
541
+ tier: entry.tier,
542
+ omQuality: hit.meta.omQuality,
543
+ verifiedOn: entry.compat.verifiedOn,
544
+ line,
545
+ status: line ? statusOn(entry, line) : null,
546
+ agentPolicy: line ? entry.agentPolicy[line] ?? null : null,
547
+ installableFrom: entry.version.installableFrom,
548
+ ...installFields(entry, line, latest, peerLookup(searcher)),
549
+ matchedOn: hit.matchedOn,
550
+ card: absolute(searcher.site, entry.links.page)
551
+ };
552
+ }
553
+ function peerLookup(searcher) {
554
+ return (locator) => searcher.modules.get(locator)?.entry;
555
+ }
556
+ function receiptSourceOf(searcher) {
557
+ const source = searcher.index.dataAsOf?.source;
558
+ return source === "ci" || source === "preview" ? source : null;
559
+ }
560
+ function searchModules(searcher, input) {
561
+ const limit = Math.min(SEARCH_MAX_LIMIT, Math.max(1, Math.floor(input.limit ?? SEARCH_DEFAULTS.limit)));
562
+ const ranked = rankModules(searcher, input);
563
+ return {
564
+ results: ranked.modules.slice(0, limit).map((hit) => toModuleCard(searcher, hit, ranked.line, ranked.latest)),
565
+ builtIn: ranked.builtIn,
566
+ total: ranked.modules.length,
567
+ line: ranked.line,
568
+ dataVersion: searcher.index.dataVersion,
569
+ generatedAt: searcher.index.generatedAt,
570
+ receiptSource: receiptSourceOf(searcher),
571
+ ...ranked.didYouMean ? { didYouMean: ranked.didYouMean } : {}
572
+ };
573
+ }
574
+ function stripVersion(ref) {
575
+ const match = /^(.+?)@(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(ref.trim());
576
+ return match ? { name: match[1], version: match[2] } : { name: ref.trim(), version: null };
577
+ }
578
+ const normalizeRef = (value) => value.trim().toLowerCase();
579
+ const rankEntry = (entry) => (entry.type === "official" ? 0 : 2) + (entry.tier === "verified" ? 0 : 1);
580
+ function resolveRef(ref, entries, builtIn) {
581
+ const wanted = normalizeRef(stripVersion(ref).name);
582
+ const direct = entries.find(
583
+ (entry) => normalizeRef(entry.locator) === wanted || entry.npm !== null && normalizeRef(entry.npm) === wanted || normalizeRef(entry.path) === wanted || normalizeRef(`/m/${entry.path}`) === wanted || entry.renamedFrom.some((previous) => normalizeRef(previous) === wanted || normalizeRef(previous) === `npm:${wanted}`)
584
+ );
585
+ if (direct) return { kind: "entry", entry: direct, candidates: [] };
586
+ const githubPath = wanted.startsWith("github:") ? `github/${wanted.slice(7)}` : wanted.replace(/^https:\/\/github\.com\//, "github/");
587
+ const github = entries.find((entry) => normalizeRef(entry.path) === githubPath);
588
+ if (github) return { kind: "entry", entry: github, candidates: [] };
589
+ const id = wanted.replace(/^core:/, "");
590
+ const byId = entries.filter((entry) => entry.moduleIds.includes(id)).sort((left, right) => rankEntry(left) - rankEntry(right));
591
+ const core = builtIn.find((coreModule) => coreModule.id === id);
592
+ if (core) return { kind: "builtin", builtIn: core, candidates: byId.map((entry) => entry.locator).slice(0, 10) };
593
+ if (byId.length === 1) return { kind: "entry", entry: byId[0], candidates: [] };
594
+ if (byId.length > 1) return { kind: "none", candidates: byId.map((entry) => entry.locator).slice(0, 10) };
595
+ const loose = entries.filter(
596
+ (entry) => wanted.length >= 3 && (normalizeRef(entry.locator).includes(wanted) || entry.moduleIds.some((moduleId) => moduleId.includes(wanted.replace(/-/g, "_"))))
597
+ ).sort((left, right) => rankEntry(left) - rankEntry(right));
598
+ return { kind: "none", candidates: loose.map((entry) => entry.locator).slice(0, 10) };
599
+ }
600
+ const clip = (text, max = 200) => text.length > max ? `${text.slice(0, max - 3)}...` : text;
601
+ function entryWarnings(entry, today, line, receiptSource = null) {
602
+ const warnings = [];
603
+ if (!entry.listed) warnings.push(`Not listed: ${(line ? entry.agentPolicy[line] : null)?.reasons[0]?.text ?? "see the card."}`);
604
+ if (entry.status !== "active") warnings.push(`Status: ${entry.status}.`);
605
+ if (entry.version.installableFrom && entry.version.installableFrom > today)
606
+ warnings.push(
607
+ `${entry.version.latest ?? "The newest release"} is installable from ${entry.version.installableFrom} (Yarn age gate).`
608
+ );
609
+ if (entry.license.mismatch) warnings.push("License sources disagree. See the card.");
610
+ const supplyChain = entry.signals?.supplyChain;
611
+ if (supplyChain && supplyChain.status !== "ok")
612
+ warnings.push(`Supply chain ${supplyChain.status}: ${supplyChain.reasons.join("; ") || "see the card"}.`);
613
+ const hygiene = entry.signals?.hygiene;
614
+ if (hygiene && hygiene.status !== "ok") warnings.push(`Hygiene ${hygiene.status}: ${hygiene.failing.join(", ") || "see the card"}.`);
615
+ if (entry.signals?.anatomy === "hidden") warnings.push("Anatomy is not published for this entry.");
616
+ return [...receiptSource === "preview" ? [PREVIEW_LINE] : [], ...warnings.map((warning) => clip(warning))].slice(0, 10);
617
+ }
618
+ function unknownModuleMessage(ref, candidates) {
619
+ return candidates.length > 0 ? `Unknown module "${ref.slice(0, 80)}". Did you mean: ${candidates.join(", ")}?` : `Unknown module "${ref.slice(0, 80)}".`;
620
+ }
621
+ function builtInWarnings(coreModule, line) {
622
+ return builtInNotes(coreModule, line).map((note) => clip(note));
623
+ }
624
+ function sharedModuleIdWarning(id, count) {
625
+ return clip(`Module ID ${id} is provided by ${count} entries. Pick one of the candidates.`);
626
+ }
627
+ function cardUrl(searcher, page) {
628
+ return absolute(searcher.site, page);
629
+ }
630
+ export {
631
+ ALIASES_META_KEY,
632
+ BOOST_OFFICIAL,
633
+ BOOST_VERIFIED,
634
+ BUILTIN_MAX,
635
+ BUILTIN_RATIO,
636
+ CORE_PACKAGE,
637
+ ENTERPRISE_ENABLE_STEP,
638
+ ENTERPRISE_PACKAGE,
639
+ INSTALLABLE_META_KEY,
640
+ MIN_AND_RESULTS,
641
+ PREVIEW_LINE,
642
+ SEARCH_BOOST,
643
+ SEARCH_DEFAULTS,
644
+ SEARCH_MAX_LIMIT,
645
+ WEAK_HIT_RATIO,
646
+ builtInEnableCommand,
647
+ builtInNotes,
648
+ builtInPresetText,
649
+ builtInWarnings,
650
+ cardUrl,
651
+ createCatalogSearcher,
652
+ emptyPresetVersion,
653
+ entryWarnings,
654
+ installCommand,
655
+ installFields,
656
+ installVersion,
657
+ isAdapter,
658
+ latestLine,
659
+ lineVersion,
660
+ newAppInstallText,
661
+ peerLibrarySpecs,
662
+ peerLookup,
663
+ processTerm,
664
+ rankModules,
665
+ receiptSourceOf,
666
+ resolveLine,
667
+ resolveRef,
668
+ searchModules,
669
+ sharedModuleIdWarning,
670
+ statusOn,
671
+ stripVersion,
672
+ swapVariants,
673
+ toModuleCard,
674
+ tokenize,
675
+ unknownModuleMessage
676
+ };
677
+ //# sourceMappingURL=module-search-index.js.map