@picked/vite-plugin-picked 0.0.78-next.1 → 0.0.78-next.3

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/esm/index.js CHANGED
@@ -2,36 +2,37 @@ import { existsSync as e } from "node:fs";
2
2
  import { join as t, resolve as n } from "node:path";
3
3
  import { createClientHeaders as r, fetchExperienceContent as i, fetchProject as a } from "@picked/delivery-api-client";
4
4
  import { generate as o } from "@picked/typegen";
5
- import { loadPickedConfig as s, loadResolvedPickedConfig as c } from "@picked/config";
6
- import { appendFile as l, mkdir as u, readFile as d, writeFile as f } from "node:fs/promises";
5
+ import { detectHostEnvironment as s, isTelemetryEnabled as c, isTelemetryForcedOffByEnvironment as l, loadPickedConfig as u, loadResolvedPickedConfig as d } from "@picked/config";
6
+ import { appendFile as f, mkdir as p, readFile as m, writeFile as h } from "node:fs/promises";
7
+ import { createSpanId as g, createTelemetryEmitter as _, createTraceId as v, toUnixNano as y } from "@picked/telemetry";
7
8
  //#region \0@oxc-project+runtime@0.142.0/helpers/esm/taggedTemplateLiteral.js
8
- function p(e, t) {
9
+ function b(e, t) {
9
10
  return t ||= e.slice(0), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } }));
10
11
  }
11
12
  //#endregion
12
13
  //#region src/launcher.ts
13
- var m, h = ["true", "false"], g = "false";
14
- function _(e) {
14
+ var x, S = ["true", "false"], C = "false";
15
+ function w(e) {
15
16
  let t = e.variants;
16
- return !t || t.length === 0 ? h : t.map((e) => String(e.value));
17
+ return !t || t.length === 0 ? S : t.map((e) => String(e.value));
17
18
  }
18
- function v(e) {
19
- let t = _(e), n = Math.max(0, t.findIndex((e) => e !== g));
20
- return t.map((e, t) => `<option value="${x(e)}"${t === n ? " selected" : ""}>${b(e)}</option>`).join("");
19
+ function T(e) {
20
+ let t = w(e), n = Math.max(0, t.findIndex((e) => e !== C));
21
+ return t.map((e, t) => `<option value="${O(e)}"${t === n ? " selected" : ""}>${D(e)}</option>`).join("");
21
22
  }
22
- function y(e) {
23
+ function E(e) {
23
24
  let t = JSON.stringify(e).replaceAll("<", String.raw`\u003c`), n = e.length > 0 ? e.map((e) => `
24
25
  <div class="feature-row">
25
26
  <label>
26
- <input type="checkbox" data-feature-id="${x(e.id)}" checked>
27
- <span class="feature-name">${b(e.name)}</span>
28
- <span class="feature-id">${b(e.id)}</span>
27
+ <input type="checkbox" data-feature-id="${O(e.id)}" checked>
28
+ <span class="feature-name">${D(e.name)}</span>
29
+ <span class="feature-id">${D(e.id)}</span>
29
30
  </label>
30
- <select data-value-for="${x(e.id)}">
31
- ${v(e)}
31
+ <select data-value-for="${O(e.id)}">
32
+ ${T(e)}
32
33
  </select>
33
34
  </div>`).join("") : "<p class=\"text no-features\">No features configured for this project.</p>";
34
- return String.raw(m ||= p([
35
+ return String.raw(x ||= b([
35
36
  "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta name=\"robots\" content=\"noindex, nofollow\">\n <title>Picked</title>\n <style>\n main {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n display: grid;\n align-items: center;\n justify-content: center;\n font-family: monospace;\n color: #4A4A4A\n }\n\n .wrap {\n padding-left: 1.5rem;\n padding-right: 1.5rem;\n max-width: 480px;\n width: 100%;\n }\n\n .title {\n font-size: 1.125rem;\n font-weight: 700;\n margin-bottom: 0;\n }\n\n .text {\n margin-top: .5rem;\n font-size: .875rem\n }\n\n .text a {\n color: #4A4A4A;\n text-decoration: none;\n }\n\n .text a:hover {\n cursor: pointer;\n text-decoration: underline\n }\n\n .preview-form {\n margin-top: 2rem;\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n }\n\n .preview-input {\n padding: 0.5rem;\n border: 1px solid #4A4A4A;\n border-radius: 0;\n font-family: monospace;\n }\n\n .preview-button {\n padding: 0.5rem;\n background: #4A4A4A;\n color: white;\n border: none;\n border-radius: 0;\n cursor: pointer;\n font-family: monospace;\n }\n\n .preview-button:hover {\n opacity: 0.9;\n }\n\n .buttons {\n display: grid;\n gap: 0.5em;\n grid-template-columns: 1fr 1fr;\n }\n\n #copy-status {\n font-size: 1em;\n text-align: right;\n margin-top: 0.5em;\n }\n\n .features-section {\n margin-top: 1.5rem;\n }\n\n .features-label {\n font-weight: 700;\n font-size: .875rem;\n margin-bottom: 0.5rem;\n }\n\n .feature-row {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 0.5rem;\n padding: 0.25rem 0;\n }\n\n .feature-row label {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n cursor: pointer;\n min-width: 0;\n flex: 1;\n }\n\n .feature-name {\n font-size: .875rem;\n }\n\n .feature-id {\n font-size: .75rem;\n color: #888;\n }\n\n .feature-row select {\n font-family: monospace;\n font-size: .75rem;\n padding: 0.125rem 0.25rem;\n border: 1px solid #4A4A4A;\n border-radius: 0;\n background: white;\n flex-shrink: 0;\n }\n\n .no-features {\n color: #888;\n font-style: italic;\n }\n\n .url-history {\n margin-top: 0.5rem;\n font-size: .75rem;\n }\n\n .url-history-item {\n display: flex;\n align-items: center;\n gap: 0.25rem;\n padding: 0.125rem 0;\n }\n\n .url-history-item button {\n background: none;\n border: none;\n cursor: pointer;\n font-family: monospace;\n font-size: .75rem;\n color: #888;\n padding: 0;\n }\n\n .url-history-item button.url-link {\n color: #4A4A4A;\n text-decoration: none;\n text-align: left;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n flex: 1;\n min-width: 0;\n }\n\n .url-history-item button.url-link:hover {\n text-decoration: underline;\n }\n\n .url-history-item button.url-delete:hover {\n color: #b71c1c;\n }\n\n @media (min-width: 640px) {\n .title {\n font-size: 1.25rem\n }\n\n .text {\n font-size: 1rem\n }\n }\n </style>\n</head>\n<body>\n\n<main>\n <div class=\"wrap\">\n <p class=\"title\">Picked</p>\n <p class=\"text\">\n Learn more at\n <a href=\"https://picked.app\">\n https://picked.app\n </a>\n </p>\n <div class=\"preview-form\">\n <input type=\"text\" id=\"url-input\" pattern=\"^(https?://)?.+\" placeholder=\"Enter preview URL\" required\n class=\"preview-input\">\n <div id=\"url-history\" class=\"url-history\"></div>\n <div class=\"features-section\">\n <p class=\"features-label\">Features</p>\n ",
36
37
  "\n </div>\n <div class=\"buttons\">\n <button type=\"button\" class=\"preview-button\" id=\"copy-btn\">Copy</button>\n <button type=\"button\" class=\"preview-button\" id=\"preview-btn\">Preview</button>\n </div>\n <p class=\"text\" id=\"copy-status\" aria-live=\"polite\" style=\"visibility:hidden;\">\n &nbsp;\n </p>\n </div>\n </div>\n\n <script>\n var FEATURES = ",
37
38
  ";\n var STORAGE_KEY_URL = 'picked-launcher-url';\n var STORAGE_KEY_HISTORY = 'picked-launcher-history';\n var STORAGE_KEY_SELECTIONS = 'picked-launcher-selections';\n\n function getUrlInput() {\n return document.getElementById('url-input');\n }\n\n // URL history\n function getHistory() {\n try {\n var raw = localStorage.getItem(STORAGE_KEY_HISTORY);\n if (!raw) return [];\n var parsed = JSON.parse(raw);\n return Array.isArray(parsed) ? parsed : [];\n } catch (e) {\n return [];\n }\n }\n\n function saveHistory(history) {\n localStorage.setItem(STORAGE_KEY_HISTORY, JSON.stringify(history));\n }\n\n function addToHistory(url) {\n var history = getHistory().filter(function(h) { return h !== url; });\n history.unshift(url);\n if (history.length > 10) history = history.slice(0, 10);\n saveHistory(history);\n renderHistory();\n }\n\n function removeFromHistory(url) {\n var history = getHistory().filter(function(h) { return h !== url; });\n saveHistory(history);\n renderHistory();\n }\n\n function renderHistory() {\n var container = document.getElementById('url-history');\n if (!container) return;\n var history = getHistory();\n if (history.length === 0) {\n container.innerHTML = '';\n return;\n }\n container.innerHTML = history.map(function(url) {\n return '<div class=\"url-history-item\">' +\n '<button type=\"button\" class=\"url-link\" data-history-url=\"' + escapeAttr(url) + '\">' + escapeHtml(url) + '</button>' +\n '<button type=\"button\" class=\"url-delete\" data-history-delete=\"' + escapeAttr(url) + '\">x</button>' +\n '</div>';\n }).join('');\n }\n\n // Feature selection persistence\n function getSelections() {\n try {\n var raw = localStorage.getItem(STORAGE_KEY_SELECTIONS);\n if (!raw) return {};\n var parsed = JSON.parse(raw);\n return typeof parsed === 'object' && parsed !== null ? parsed : {};\n } catch (e) {\n return {};\n }\n }\n\n function saveSelections() {\n var selections = {};\n FEATURES.forEach(function(f) {\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox && select) {\n selections[f.id] = { checked: checkbox.checked, value: select.value };\n }\n });\n localStorage.setItem(STORAGE_KEY_SELECTIONS, JSON.stringify(selections));\n }\n\n function restoreSelections() {\n var selections = getSelections();\n FEATURES.forEach(function(f) {\n var saved = selections[f.id];\n if (!saved) return;\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox) checkbox.checked = saved.checked;\n if (select) select.value = saved.value;\n });\n }\n\n function escapeHtml(str) {\n var div = document.createElement('div');\n div.textContent = str;\n return div.innerHTML;\n }\n\n function escapeAttr(str) {\n return str.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n }\n\n function buildTargetUrl(inputValue) {\n var value = inputValue;\n if (!value.startsWith('http://') && !value.startsWith('https://')) {\n value = 'https://' + value;\n }\n var hostname = window.location.hostname;\n var subdomain = hostname.split('.').length > 2 ? hostname.split('.')[0] : '';\n var target = value;\n var sep = target.includes('?') ? '&' : '?';\n if (subdomain) {\n target = target + sep + 'cvly_env=' + encodeURIComponent(subdomain);\n sep = '&';\n }\n FEATURES.forEach(function(f) {\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox && checkbox.checked && select) {\n target = target + sep + 'picked-feature=' + encodeURIComponent(f.id + ':' + select.value);\n sep = '&';\n }\n });\n return target;\n }\n\n function showCopyStatus(message, success) {\n var el = document.getElementById('copy-status');\n if (!el) return;\n el.textContent = message;\n el.style.visibility = 'visible';\n el.style.color = success ? '#2e7d32' : '#b71c1c';\n setTimeout(function() {\n el.style.visibility = 'hidden';\n }, 2000);\n }\n\n // Init\n window.addEventListener('load', function() {\n var input = getUrlInput();\n var savedUrl = localStorage.getItem(STORAGE_KEY_URL);\n if (savedUrl && input) {\n input.value = savedUrl;\n }\n renderHistory();\n restoreSelections();\n });\n\n // Delegate click events\n document.addEventListener('click', function(e) {\n var target = e.target;\n\n // History URL click\n var historyUrl = target.getAttribute('data-history-url');\n if (historyUrl) {\n var input = getUrlInput();\n if (input) input.value = historyUrl;\n return;\n }\n\n // History delete click\n var deleteUrl = target.getAttribute('data-history-delete');\n if (deleteUrl) {\n removeFromHistory(deleteUrl);\n return;\n }\n });\n\n // Feature change persistence\n document.addEventListener('change', function(e) {\n var target = e.target;\n if (target.getAttribute('data-feature-id') || target.getAttribute('data-value-for')) {\n saveSelections();\n }\n });\n\n // Copy button\n document.getElementById('copy-btn').addEventListener('click', function() {\n var input = getUrlInput();\n if (!input || !input.value) return;\n localStorage.setItem(STORAGE_KEY_URL, input.value);\n addToHistory(input.value);\n saveSelections();\n var target = buildTargetUrl(input.value);\n navigator.clipboard.writeText(target).then(function() {\n showCopyStatus('Preview URL copied to clipboard', true);\n });\n });\n\n // Preview button\n document.getElementById('preview-btn').addEventListener('click', function() {\n var input = getUrlInput();\n if (!input || !input.value) return;\n localStorage.setItem(STORAGE_KEY_URL, input.value);\n addToHistory(input.value);\n saveSelections();\n var target = buildTargetUrl(input.value);\n window.location.href = target;\n });\n <\/script>\n</main>\n</body>\n</html>"
@@ -41,46 +42,46 @@ function y(e) {
41
42
  ";\n var STORAGE_KEY_URL = 'picked-launcher-url';\n var STORAGE_KEY_HISTORY = 'picked-launcher-history';\n var STORAGE_KEY_SELECTIONS = 'picked-launcher-selections';\n\n function getUrlInput() {\n return document.getElementById('url-input');\n }\n\n // URL history\n function getHistory() {\n try {\n var raw = localStorage.getItem(STORAGE_KEY_HISTORY);\n if (!raw) return [];\n var parsed = JSON.parse(raw);\n return Array.isArray(parsed) ? parsed : [];\n } catch (e) {\n return [];\n }\n }\n\n function saveHistory(history) {\n localStorage.setItem(STORAGE_KEY_HISTORY, JSON.stringify(history));\n }\n\n function addToHistory(url) {\n var history = getHistory().filter(function(h) { return h !== url; });\n history.unshift(url);\n if (history.length > 10) history = history.slice(0, 10);\n saveHistory(history);\n renderHistory();\n }\n\n function removeFromHistory(url) {\n var history = getHistory().filter(function(h) { return h !== url; });\n saveHistory(history);\n renderHistory();\n }\n\n function renderHistory() {\n var container = document.getElementById('url-history');\n if (!container) return;\n var history = getHistory();\n if (history.length === 0) {\n container.innerHTML = '';\n return;\n }\n container.innerHTML = history.map(function(url) {\n return '<div class=\"url-history-item\">' +\n '<button type=\"button\" class=\"url-link\" data-history-url=\"' + escapeAttr(url) + '\">' + escapeHtml(url) + '</button>' +\n '<button type=\"button\" class=\"url-delete\" data-history-delete=\"' + escapeAttr(url) + '\">x</button>' +\n '</div>';\n }).join('');\n }\n\n // Feature selection persistence\n function getSelections() {\n try {\n var raw = localStorage.getItem(STORAGE_KEY_SELECTIONS);\n if (!raw) return {};\n var parsed = JSON.parse(raw);\n return typeof parsed === 'object' && parsed !== null ? parsed : {};\n } catch (e) {\n return {};\n }\n }\n\n function saveSelections() {\n var selections = {};\n FEATURES.forEach(function(f) {\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox && select) {\n selections[f.id] = { checked: checkbox.checked, value: select.value };\n }\n });\n localStorage.setItem(STORAGE_KEY_SELECTIONS, JSON.stringify(selections));\n }\n\n function restoreSelections() {\n var selections = getSelections();\n FEATURES.forEach(function(f) {\n var saved = selections[f.id];\n if (!saved) return;\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox) checkbox.checked = saved.checked;\n if (select) select.value = saved.value;\n });\n }\n\n function escapeHtml(str) {\n var div = document.createElement('div');\n div.textContent = str;\n return div.innerHTML;\n }\n\n function escapeAttr(str) {\n return str.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n }\n\n function buildTargetUrl(inputValue) {\n var value = inputValue;\n if (!value.startsWith('http://') && !value.startsWith('https://')) {\n value = 'https://' + value;\n }\n var hostname = window.location.hostname;\n var subdomain = hostname.split('.').length > 2 ? hostname.split('.')[0] : '';\n var target = value;\n var sep = target.includes('?') ? '&' : '?';\n if (subdomain) {\n target = target + sep + 'cvly_env=' + encodeURIComponent(subdomain);\n sep = '&';\n }\n FEATURES.forEach(function(f) {\n var checkbox = document.querySelector('input[data-feature-id=\"' + f.id + '\"]');\n var select = document.querySelector('select[data-value-for=\"' + f.id + '\"]');\n if (checkbox && checkbox.checked && select) {\n target = target + sep + 'picked-feature=' + encodeURIComponent(f.id + ':' + select.value);\n sep = '&';\n }\n });\n return target;\n }\n\n function showCopyStatus(message, success) {\n var el = document.getElementById('copy-status');\n if (!el) return;\n el.textContent = message;\n el.style.visibility = 'visible';\n el.style.color = success ? '#2e7d32' : '#b71c1c';\n setTimeout(function() {\n el.style.visibility = 'hidden';\n }, 2000);\n }\n\n // Init\n window.addEventListener('load', function() {\n var input = getUrlInput();\n var savedUrl = localStorage.getItem(STORAGE_KEY_URL);\n if (savedUrl && input) {\n input.value = savedUrl;\n }\n renderHistory();\n restoreSelections();\n });\n\n // Delegate click events\n document.addEventListener('click', function(e) {\n var target = e.target;\n\n // History URL click\n var historyUrl = target.getAttribute('data-history-url');\n if (historyUrl) {\n var input = getUrlInput();\n if (input) input.value = historyUrl;\n return;\n }\n\n // History delete click\n var deleteUrl = target.getAttribute('data-history-delete');\n if (deleteUrl) {\n removeFromHistory(deleteUrl);\n return;\n }\n });\n\n // Feature change persistence\n document.addEventListener('change', function(e) {\n var target = e.target;\n if (target.getAttribute('data-feature-id') || target.getAttribute('data-value-for')) {\n saveSelections();\n }\n });\n\n // Copy button\n document.getElementById('copy-btn').addEventListener('click', function() {\n var input = getUrlInput();\n if (!input || !input.value) return;\n localStorage.setItem(STORAGE_KEY_URL, input.value);\n addToHistory(input.value);\n saveSelections();\n var target = buildTargetUrl(input.value);\n navigator.clipboard.writeText(target).then(function() {\n showCopyStatus('Preview URL copied to clipboard', true);\n });\n });\n\n // Preview button\n document.getElementById('preview-btn').addEventListener('click', function() {\n var input = getUrlInput();\n if (!input || !input.value) return;\n localStorage.setItem(STORAGE_KEY_URL, input.value);\n addToHistory(input.value);\n saveSelections();\n var target = buildTargetUrl(input.value);\n window.location.href = target;\n });\n <\/script>\n</main>\n</body>\n</html>"
42
43
  ]), n, t);
43
44
  }
44
- function b(e) {
45
+ function D(e) {
45
46
  return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;");
46
47
  }
47
- function x(e) {
48
+ function O(e) {
48
49
  return e.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
49
50
  }
50
51
  //#endregion
51
52
  //#region src/log.ts
52
- var S = "picked", C = "\x1B[0m";
53
- function w() {
53
+ var k = "picked", ee = "\x1B[0m";
54
+ function te() {
54
55
  let e = process.env.NO_COLOR;
55
56
  return e === "1" || e === "true";
56
57
  }
57
- function T(e) {
58
- return (t) => w() ? t : `${e}${t}${C}`;
58
+ function A(e) {
59
+ return (t) => te() ? t : `${e}${t}${ee}`;
59
60
  }
60
- var E = [
61
+ var j = [
61
62
  "debug",
62
63
  "info",
63
64
  "warn",
64
65
  "error",
65
66
  "silent"
66
- ], D = {
67
+ ], M = {
67
68
  debug: {
68
- color: T("\x1B[2m"),
69
+ color: A("\x1B[2m"),
69
70
  log: console.debug,
70
71
  enabled: !1
71
72
  },
72
73
  info: {
73
- color: T("\x1B[36m"),
74
+ color: A("\x1B[36m"),
74
75
  log: console.log,
75
76
  enabled: !0
76
77
  },
77
78
  warn: {
78
- color: T("\x1B[33m"),
79
+ color: A("\x1B[33m"),
79
80
  log: console.warn,
80
81
  enabled: !0
81
82
  },
82
83
  error: {
83
- color: T("\x1B[31m"),
84
+ color: A("\x1B[31m"),
84
85
  log: console.error,
85
86
  enabled: !0
86
87
  },
@@ -89,52 +90,52 @@ var E = [
89
90
  enabled: !1
90
91
  }
91
92
  };
92
- function ee(e, t) {
93
- return `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${t ? `${S}:${t}` : S}] ${e}`;
93
+ function ne(e, t) {
94
+ return `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${t ? `${k}:${t}` : k}] ${e}`;
94
95
  }
95
- function O(e, t, n, r) {
96
+ function N(e, t, n, r) {
96
97
  if (!e.enabled) return;
97
- let i = ee(t, r);
98
+ let i = ne(t, r);
98
99
  e.log(e.color ? e.color(i) : i), n !== void 0 && e.log(n);
99
100
  }
100
- function k(e) {
101
- let t = D[e], n = /* @__PURE__ */ new Set();
101
+ function P(e) {
102
+ let t = M[e], n = /* @__PURE__ */ new Set();
102
103
  return Object.assign((e, n, r) => {
103
- O(t, e, n, r);
104
+ N(t, e, n, r);
104
105
  }, { once(e, r, i) {
105
- !t.enabled || n.has(e) || (n.add(e), O(t, e, r, i));
106
+ !t.enabled || n.has(e) || (n.add(e), N(t, e, r, i));
106
107
  } });
107
108
  }
108
- function te(e) {
109
- let t = E.indexOf(e);
109
+ function re(e) {
110
+ let t = j.indexOf(e);
110
111
  if (t === -1) {
111
- O(D.error, `invalid log level: ${e}`);
112
+ N(M.error, `invalid log level: ${e}`);
112
113
  return;
113
114
  }
114
- for (let [e, n] of E.entries()) D[n].enabled = e >= t;
115
+ for (let [e, n] of j.entries()) M[n].enabled = e >= t;
115
116
  }
116
- var A = T("\x1B[34m"), j = T("\x1B[36m");
117
- function ne() {
117
+ var F = A("\x1B[34m"), ie = A("\x1B[36m");
118
+ function ae() {
118
119
  let e = [
119
- ` ${A("_")} ${j("_")} _ _ _`,
120
- `${A("(_)")} ${j("(_)")} _ __(_)__| |_____ __| |`,
121
- ` ${A("_")} ${A("_")} | '_ \\ / _| / / -_) _\` |`,
122
- `${A("(_)")} ${A("(_)")} | .__/_\\__|_\\_\\___\\__,_|`,
120
+ ` ${F("_")} ${ie("_")} _ _ _`,
121
+ `${F("(_)")} ${ie("(_)")} _ __(_)__| |_____ __| |`,
122
+ ` ${F("_")} ${F("_")} | '_ \\ / _| / / -_) _\` |`,
123
+ `${F("(_)")} ${F("(_)")} | .__/_\\__|_\\_\\___\\__,_|`,
123
124
  " |_|\n "
124
125
  ];
125
126
  console.log(e.join("\n"));
126
127
  }
127
- var M = {
128
- banner: ne,
129
- debug: k("debug"),
130
- info: k("info"),
131
- warn: k("warn"),
132
- error: k("error"),
133
- setLevel: te
128
+ var I = {
129
+ banner: ae,
130
+ debug: P("debug"),
131
+ info: P("info"),
132
+ warn: P("warn"),
133
+ error: P("error"),
134
+ setLevel: re
134
135
  };
135
136
  //#endregion
136
137
  //#region src/middleware.ts
137
- function re(e) {
138
+ function oe(e) {
138
139
  return (t, n, r) => {
139
140
  if (t.method !== "GET") {
140
141
  r();
@@ -151,28 +152,28 @@ function re(e) {
151
152
  }
152
153
  //#endregion
153
154
  //#region src/gitignore.ts
154
- var N = ".picked/";
155
- async function ie(n, r) {
155
+ var L = ".picked/";
156
+ async function se(n, r) {
156
157
  if (r) return;
157
158
  let i = t(n, ".gitignore");
158
159
  if (!e(i)) {
159
- await f(i, `${N}
160
+ await h(i, `${L}
160
161
  `);
161
162
  return;
162
163
  }
163
- let a = await d(i, "utf8");
164
- if (P(a)) return;
165
- let o = `${a.length > 0 && !a.endsWith("\n") ? "\n" : ""}${N}
164
+ let a = await m(i, "utf8");
165
+ if (ce(a)) return;
166
+ let o = `${a.length > 0 && !a.endsWith("\n") ? "\n" : ""}${L}
166
167
  `;
167
- await l(i, o);
168
+ await f(i, o);
168
169
  }
169
- function P(e) {
170
- return e.split(/\r?\n/).map((e) => e.trim()).some((e) => e === N || e === ".picked");
170
+ function ce(e) {
171
+ return e.split(/\r?\n/).map((e) => e.trim()).some((e) => e === L || e === ".picked");
171
172
  }
172
173
  //#endregion
173
174
  //#region src/retry.ts
174
- var F = 6, ae = 5e3;
175
- function I(e) {
175
+ var R = 6, le = 5e3;
176
+ function z(e) {
176
177
  let t;
177
178
  try {
178
179
  t = new URL(e).hostname;
@@ -181,12 +182,12 @@ function I(e) {
181
182
  }
182
183
  return t === "localhost" || t === "127.0.0.1" || t === "::1" || t === "[::1]" || t !== "api.picked.app" && t.endsWith(".picked.app");
183
184
  }
184
- function oe(e) {
185
+ function ue(e) {
185
186
  return new Promise((t) => {
186
187
  setTimeout(t, e);
187
188
  });
188
189
  }
189
- async function L(e, t) {
190
+ async function B(e, t) {
190
191
  let n = null, r = null;
191
192
  try {
192
193
  n = await e();
@@ -194,9 +195,9 @@ async function L(e, t) {
194
195
  r = e;
195
196
  }
196
197
  if (n !== null) return n;
197
- for (let i = 1; i <= F; i++) {
198
- let a = ae * 2 ** (i - 1);
199
- t(i, F, a), await oe(a), r = null;
198
+ for (let i = 1; i <= R; i++) {
199
+ let a = le * 2 ** (i - 1);
200
+ t(i, R, a), await ue(a), r = null;
200
201
  try {
201
202
  n = await e();
202
203
  } catch (e) {
@@ -209,10 +210,10 @@ async function L(e, t) {
209
210
  }
210
211
  //#endregion
211
212
  //#region src/util.ts
212
- function R(e) {
213
+ function V(e) {
213
214
  return Array.isArray(e) ? e : [];
214
215
  }
215
- function se(e) {
216
+ function de(e) {
216
217
  let t = e.variants, n = (t ?? []).reduce((e, t) => e + t.weight, 0);
217
218
  return !t || t.length === 0 || n === 0 ? `${e.weight.toString()}%` : t.map((e) => {
218
219
  let t = Math.round(100 * e.weight / n);
@@ -221,8 +222,8 @@ function se(e) {
221
222
  }
222
223
  //#endregion
223
224
  //#region src/prefetch.ts
224
- var z = 2;
225
- function B(e) {
225
+ var H = 2;
226
+ function U(e) {
226
227
  let n = t(e, ".picked");
227
228
  return {
228
229
  pickedDir: n,
@@ -231,60 +232,60 @@ function B(e) {
231
232
  experiencesDir: t(n, "experiences")
232
233
  };
233
234
  }
234
- async function ce(t) {
235
+ async function fe(t) {
235
236
  if (!e(t)) return null;
236
237
  try {
237
- let e = await d(t, "utf8"), n = JSON.parse(e);
238
- return V(n) ? n : null;
238
+ let e = await m(t, "utf8"), n = JSON.parse(e);
239
+ return pe(n) ? n : null;
239
240
  } catch {
240
241
  return null;
241
242
  }
242
243
  }
243
- function V(e) {
244
+ function pe(e) {
244
245
  return !(typeof e != "object" || !e || !("version" in e) || typeof e.version != "number" || !("projectVersionId" in e) || typeof e.projectVersionId != "string" || !("workspaceId" in e) || typeof e.workspaceId != "string" || !("experiences" in e) || !Array.isArray(e.experiences));
245
246
  }
246
- function H(e) {
247
+ function me(e) {
247
248
  let t = /* @__PURE__ */ new Set();
248
- for (let n of R(e.steps)) n.layoutContentId && t.add(n.id);
249
+ for (let n of V(e.steps)) n.layoutContentId && t.add(n.id);
249
250
  if (t.size === 0) return [];
250
251
  let n = [];
251
- for (let r of R(e.experiences)) R(r.nodes).some((e) => e.type === "step" && t.has(e.stepId)) && n.push(r.id);
252
+ for (let r of V(e.experiences)) V(r.nodes).some((e) => e.type === "step" && t.has(e.stepId)) && n.push(r.id);
252
253
  return n;
253
254
  }
254
- async function U(n) {
255
- let { apiUrl: r, projectId: i, projectRoot: a, headers: o, previewToken: s, reuseWhenUnchanged: c = !0 } = n, l = B(a), d = await G(r, i, o, s), p = H(d);
256
- if (await u(l.experiencesDir, { recursive: !0 }), await f(l.projectConfigPath, JSON.stringify(d, null, 2)), c) {
257
- let t = await ce(l.manifestPath);
258
- if (t?.version === z && t.projectVersionId === d.versionId && t.workspaceId === d.workspaceId) {
259
- let n = W(l, p);
255
+ async function he(n) {
256
+ let { apiUrl: r, projectId: i, projectRoot: a, headers: o, previewToken: s, reuseWhenUnchanged: c = !0 } = n, l = U(a), u = await ge(r, i, o, s), d = me(u);
257
+ if (await p(l.experiencesDir, { recursive: !0 }), await h(l.projectConfigPath, JSON.stringify(u, null, 2)), c) {
258
+ let t = await fe(l.manifestPath);
259
+ if (t?.version === H && t.projectVersionId === u.versionId && t.workspaceId === u.workspaceId) {
260
+ let n = W(l, d);
260
261
  if (Object.values(n).every((t) => e(t))) return {
261
- config: d,
262
+ config: u,
262
263
  manifest: t,
263
264
  experienceContentPaths: n
264
265
  };
265
- M.info("a manifest-referenced content file is missing; refetching every experience");
266
+ I.info("a manifest-referenced content file is missing; refetching every experience");
266
267
  }
267
268
  }
268
- let m = (/* @__PURE__ */ new Date()).toISOString(), h = [];
269
- for (let e of p) {
270
- let n = await le(r, i, e, o, s), a = t(l.experiencesDir, `${e}.json`);
271
- await f(a, JSON.stringify(n, null, 2)), h.push({
269
+ let f = (/* @__PURE__ */ new Date()).toISOString(), m = [];
270
+ for (let e of d) {
271
+ let n = await _e(r, i, e, o, s), a = t(l.experiencesDir, `${e}.json`);
272
+ await h(a, JSON.stringify(n, null, 2)), m.push({
272
273
  id: e,
273
- fetchedAt: m
274
+ fetchedAt: f
274
275
  });
275
276
  }
276
277
  let g = {
277
- version: z,
278
- fetchedAt: m,
279
- projectVersionId: d.versionId,
280
- workspaceId: d.workspaceId,
281
- projectId: d.id,
282
- experiences: h
278
+ version: H,
279
+ fetchedAt: f,
280
+ projectVersionId: u.versionId,
281
+ workspaceId: u.workspaceId,
282
+ projectId: u.id,
283
+ experiences: m
283
284
  };
284
- return await f(l.manifestPath, JSON.stringify(g, null, 2)), {
285
- config: d,
285
+ return await h(l.manifestPath, JSON.stringify(g, null, 2)), {
286
+ config: u,
286
287
  manifest: g,
287
- experienceContentPaths: W(l, p)
288
+ experienceContentPaths: W(l, d)
288
289
  };
289
290
  }
290
291
  function W(e, n) {
@@ -292,22 +293,22 @@ function W(e, n) {
292
293
  for (let i of n) r[i] = t(e.experiencesDir, `${i}.json`);
293
294
  return r;
294
295
  }
295
- async function G(e, t, n, r) {
296
+ async function ge(e, t, n, r) {
296
297
  let i = () => a(e, t, {
297
298
  headers: n,
298
299
  previewToken: r
299
300
  }), o;
300
301
  try {
301
- o = I(e) ? await L(i, (e, t, n) => {
302
- M.info(`project config not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
302
+ o = z(e) ? await B(i, (e, t, n) => {
303
+ I.info(`project config not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
303
304
  }) : await i();
304
305
  } catch (n) {
305
- throw Error(`[picked] Build-time fetch of project config failed for "${t}" at ${e}: ${K(n)}`);
306
+ throw Error(`[picked] Build-time fetch of project config failed for "${t}" at ${e}: ${G(n)}`);
306
307
  }
307
308
  if (!o) throw Error(`[picked] Build-time fetch of project config returned no usable response for "${t}" at ${e}. Confirm the API is reachable and the project ID is correct.`);
308
309
  return o;
309
310
  }
310
- async function le(e, t, n, r, a) {
311
+ async function _e(e, t, n, r, a) {
311
312
  let o;
312
313
  try {
313
314
  o = await i(e, t, n, {
@@ -315,12 +316,12 @@ async function le(e, t, n, r, a) {
315
316
  previewToken: a
316
317
  });
317
318
  } catch (t) {
318
- throw Error(`[picked] Build-time fetch of content for experience "${n}" failed at ${e}: ${K(t)}`);
319
+ throw Error(`[picked] Build-time fetch of content for experience "${n}" failed at ${e}: ${G(t)}`);
319
320
  }
320
321
  if (!o) throw Error(`[picked] Build-time fetch of content for experience "${n}" returned no usable response. Confirm the experience id exists and the API is reachable.`);
321
322
  return o;
322
323
  }
323
- function K(e) {
324
+ function G(e) {
324
325
  if (e instanceof Error) return e.message;
325
326
  if (typeof e == "string") return e;
326
327
  try {
@@ -330,13 +331,98 @@ function K(e) {
330
331
  }
331
332
  }
332
333
  //#endregion
334
+ //#region src/telemetry.ts
335
+ var ve = /* @__PURE__ */ new Set(["resolveId", "load"]);
336
+ function ye(e = v()) {
337
+ let t = g(), n = Date.now(), r = [], i = /* @__PURE__ */ new Map();
338
+ return {
339
+ record: (n, a) => {
340
+ if (ve.has(n)) {
341
+ let e = i.get(n) ?? {
342
+ calls: 0,
343
+ totalMs: 0
344
+ };
345
+ i.set(n, {
346
+ calls: e.calls + 1,
347
+ totalMs: e.totalMs + a
348
+ });
349
+ return;
350
+ }
351
+ let o = Date.now();
352
+ r.push({
353
+ name: `picked.vite.${n}`,
354
+ traceId: e,
355
+ spanId: g(),
356
+ parentSpanId: t,
357
+ startTimeUnixNano: y(o - a),
358
+ endTimeUnixNano: y(o),
359
+ attributes: { "picked.vite.hook": n },
360
+ status: "ok"
361
+ });
362
+ },
363
+ flush: async (a) => {
364
+ let o = {};
365
+ for (let [e, t] of i) o[`picked.vite.${e}.calls`] = t.calls, o[`picked.vite.${e}.total_ms`] = Math.round(t.totalMs);
366
+ let c = s();
367
+ r.push({
368
+ name: "picked.vite.build",
369
+ traceId: e,
370
+ spanId: t,
371
+ startTimeUnixNano: y(n),
372
+ endTimeUnixNano: y(Date.now()),
373
+ attributes: {
374
+ "picked.env.provider": c.provider,
375
+ "picked.env.ci": c.ci,
376
+ ...a,
377
+ ...o
378
+ },
379
+ status: "ok"
380
+ });
381
+ try {
382
+ let e = _({
383
+ resource: { "service.name": "picked-vite-plugin" },
384
+ headers: { "Picked-Telemetry": "vite-plugin" },
385
+ maxBatchSize: r.length
386
+ });
387
+ for (let t of r) e.record(t);
388
+ await e.flush();
389
+ } catch {}
390
+ }
391
+ };
392
+ }
393
+ function be(e) {
394
+ return typeof e == "object" && !!e && "then" in e;
395
+ }
396
+ function K(e, t, n) {
397
+ return function(...r) {
398
+ let i = performance.now(), a = () => {
399
+ n.record(e, performance.now() - i);
400
+ }, o = t.apply(this, r);
401
+ return be(o) ? Promise.resolve(o).then(a, a) : a(), o;
402
+ };
403
+ }
404
+ function q(e) {
405
+ return typeof e == "function";
406
+ }
407
+ function xe(e, t) {
408
+ if (!e) return t;
409
+ for (let [n, r] of Object.entries(t)) if (n !== "name") {
410
+ if (q(r)) {
411
+ Reflect.set(t, n, K(n, r, e));
412
+ continue;
413
+ }
414
+ typeof r == "object" && r && "handler" in r && q(r.handler) && Reflect.set(r, "handler", K(n, r.handler, e));
415
+ }
416
+ return t;
417
+ }
418
+ //#endregion
333
419
  //#region src/virtual-module/api.ts
334
- function q() {
420
+ function Se() {
335
421
  return "export const manifestMetadata = {\n mode: 'api',\n fetchedAt: null,\n projectVersionId: null,\n workspaceId: null,\n}\n";
336
422
  }
337
423
  //#endregion
338
424
  //#region src/virtual-module/build.ts
339
- function ue(e) {
425
+ function Ce(e) {
340
426
  let { projectConfigPath: t, experienceContentPaths: n, manifestMetadata: r } = e, i = (e) => JSON.stringify(e), a = Object.entries(n).map(([e, t]) => ` ${JSON.stringify(e)}: () => import(${i(t)}).then((m) => m.default ?? m),`).join("\n");
341
427
  return `import { registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'
342
428
  import projectConfigJson from ${i(t)}
@@ -366,7 +452,7 @@ registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
366
452
  }
367
453
  //#endregion
368
454
  //#region src/virtual-module/dev.ts
369
- function de(e) {
455
+ function we(e) {
370
456
  let { apiUrl: t, projectId: n, projectConfig: r, previewToken: i } = e, a = r ? "import { fetchExperienceContent, registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'" : "import { fetchProject, fetchExperienceContent } from '@picked/client/plugins/dynamic-experiences'", o = r ? `export const projectConfig = ${JSON.stringify(r)}` : "export const projectConfig = await fetchProject(apiUrl, projectId, { previewToken: previewToken ?? undefined })", s = r ? "\nregisterPickedBundle({ projectConfig, experienceContent, manifestMetadata })\n" : "";
371
457
  return `${a}
372
458
 
@@ -392,10 +478,10 @@ ${s}`;
392
478
  }
393
479
  //#endregion
394
480
  //#region src/index.ts
395
- var fe = 5;
481
+ var Te = 5;
396
482
  function J(e, t, n) {
397
483
  if (t.length === 0) return;
398
- if (t.length > fe) {
484
+ if (t.length > Te) {
399
485
  console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
400
486
  return;
401
487
  }
@@ -410,10 +496,10 @@ function J(e, t, n) {
410
496
  ""
411
497
  ].join("\n"));
412
498
  }
413
- function pe(e, t) {
499
+ function Ee(e, t) {
414
500
  t.length !== 0 && console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
415
501
  }
416
- var me = [
502
+ var De = [
417
503
  {
418
504
  header: "Name",
419
505
  value: (e) => e.name
@@ -428,13 +514,13 @@ var me = [
428
514
  },
429
515
  {
430
516
  header: "Split",
431
- value: (e) => se(e)
517
+ value: (e) => de(e)
432
518
  },
433
519
  {
434
520
  header: "Ver",
435
521
  value: (e) => `v${e.version.toString()}`
436
522
  }
437
- ], he = [
523
+ ], Oe = [
438
524
  {
439
525
  header: "Name",
440
526
  value: (e) => e.name
@@ -455,7 +541,7 @@ var me = [
455
541
  header: "Targets",
456
542
  value: (e) => e.targets.length.toString()
457
543
  }
458
- ], ge = [
544
+ ], ke = [
459
545
  {
460
546
  header: "Name",
461
547
  value: (e) => e.name
@@ -468,7 +554,7 @@ var me = [
468
554
  header: "Fields",
469
555
  value: (e) => (e.fieldIds?.length ?? 0).toString()
470
556
  }
471
- ], _e = [
557
+ ], Ae = [
472
558
  {
473
559
  header: "Name",
474
560
  value: (e) => e.name
@@ -485,98 +571,101 @@ var me = [
485
571
  header: "Required",
486
572
  value: (e) => e.required ? "yes" : "no"
487
573
  }
488
- ], ve = [{
574
+ ], je = [{
489
575
  header: "Name",
490
576
  value: (e) => e.name
491
577
  }, {
492
578
  header: "Key",
493
579
  value: (e) => e.key
494
580
  }];
495
- function ye() {
496
- return "0.0.78-next.1";
581
+ function Me() {
582
+ return "0.0.78-next.3";
497
583
  }
498
- var be = "https://api.picked.app", Y = "virtual:picked/data", X = `\0${Y}`;
499
- function xe(e) {
584
+ var Ne = "https://api.picked.app", Y = "virtual:picked/data", X = `\0${Y}`;
585
+ function Pe(e) {
500
586
  for (let t of Object.values(e)) if (t.type === "chunk" && t.moduleIds.includes(X)) return t.fileName;
501
587
  }
502
- function Se(e, t) {
588
+ function Fe(e, t) {
503
589
  return e === "" || e.endsWith("/") ? `${e}${t}` : `${e}/${t}`;
504
590
  }
505
- async function Ce(e) {
591
+ async function Ie(e) {
506
592
  try {
507
593
  let t = await o({
508
594
  config: e,
509
595
  onWarn: (e) => {
510
- M.warn(e);
596
+ I.warn(e);
511
597
  }
512
598
  });
513
- M.info(`generated types at ${t.typesOutput}`);
599
+ I.info(`generated types at ${t.typesOutput}`);
514
600
  } catch (e) {
515
601
  let t = e instanceof Error ? e.message : String(e);
516
602
  throw Error(`type generation failed: ${t}. Fix the schema source, or set \`generateTypes: false\` on the picked plugin to skip it.`);
517
603
  }
518
604
  }
519
- async function we(e, t) {
520
- let n = await c(e, t);
605
+ function Le(e, t, n) {
606
+ return e && c(t, n) ? e : null;
607
+ }
608
+ async function Re(e, t) {
609
+ let n = await d(e, t);
521
610
  if (!n) throw Error("picked.config.{ts,js,json} is required. Add a picked.config.ts with projectId and apiUrl.");
522
611
  return n;
523
612
  }
524
613
  function Z(e, t, n) {
525
614
  if (t !== void 0 && n !== void 0 && t !== n) throw Error(`picked plugin option \`${e}\` is "${t}", and picked.config says "${n}". Remove the plugin option; picked.config is the one place this belongs.`);
526
615
  }
527
- function Te(e) {
616
+ function ze(e) {
528
617
  let t = [];
529
618
  if (e.projectId !== void 0 && t.push("`projectId`"), e.apiUrl !== void 0 && t.push("`apiUrl`"), t.length === 0) return;
530
619
  let n = t.length > 1;
531
- M.warn(`picked plugin option${n ? "s" : ""} ${t.join(" and ")} ${n ? "are" : "is"} deprecated, and a future release drops ${n ? "them" : "it"}. Move ${n ? "them" : "it"} to picked.config, which the CLI and the type generator read from too.`);
620
+ I.warn(`picked plugin option${n ? "s" : ""} ${t.join(" and ")} ${n ? "are" : "is"} deprecated, and a future release drops ${n ? "them" : "it"}. Move ${n ? "them" : "it"} to picked.config, which the CLI and the type generator read from too.`);
532
621
  }
533
- async function Ee(e, t) {
534
- let n = await s(e);
535
- n && n.projectId !== t && M.warn(`using project "${t}" (picked.config default: "${n.projectId}") — run 'picked status' to inspect`);
622
+ async function Be(e, t) {
623
+ let n = await u(e);
624
+ n && n.projectId !== t && I.warn(`using project "${t}" (picked.config default: "${n.projectId}") — run 'picked status' to inspect`);
536
625
  }
537
626
  var Q = /* @__PURE__ */ new Map();
538
- function De(e, t, n) {
627
+ function Ve(e, t, n) {
539
628
  return JSON.stringify([
540
629
  e,
541
630
  t,
542
631
  n
543
632
  ]);
544
633
  }
545
- function Oe(t = {}) {
546
- let i = t.mode ?? "bundle", o = t.generateTypes ?? !0, c = [], l = process.cwd(), u = "serve", d = "/", f = null, p = !1, m, h, g = null;
547
- return {
634
+ function He(t = {}) {
635
+ let i = t.mode ?? "bundle", o = t.generateTypes ?? !0, s = [], c = process.cwd(), d = "serve", f = "/", p = null, m = !1, h, g, _ = null, v = l() ? null : ye();
636
+ return xe(v, {
548
637
  name: "picked",
549
- config: async (d, _) => {
550
- u = _.command, l = d.root === void 0 ? process.cwd() : n(process.cwd(), d.root);
551
- let { projectId: v, apiUrl: y } = t, b = await s(l);
552
- Z("projectId", v, b?.projectId), Z("apiUrl", y, b?.apiUrl), Te({
553
- projectId: v,
554
- apiUrl: y
555
- }), f = await we(l, {
556
- projectId: v,
557
- apiUrl: y
638
+ config: async (l, f) => {
639
+ d = f.command, c = l.root === void 0 ? process.cwd() : n(process.cwd(), l.root);
640
+ let { projectId: y, apiUrl: b } = t, x = await u(c);
641
+ Z("projectId", y, x?.projectId), Z("apiUrl", b, x?.apiUrl), ze({
642
+ projectId: y,
643
+ apiUrl: b
644
+ }), p = await Re(c, {
645
+ projectId: y,
646
+ apiUrl: b
558
647
  });
559
- let { projectId: x, apiUrl: S, previewToken: C } = f;
560
- M.banner(), o && !p && (p = !0, await Ce(f)), S !== be && M.warn(`using custom API URL: ${S}`), await Ee(l, x);
561
- let w = r("vite-plugin", ye());
562
- if (i === "api") M.debug("mode is 'api': skipping the project-config prefetch");
563
- else if (_.command === "build") {
564
- let t = De(S, x, l);
565
- m = t;
648
+ let { projectId: S, apiUrl: C, previewToken: w } = p;
649
+ v = Le(v, p, t.telemetry), I.banner(), o && !m && (m = !0, await Ie(p)), C !== Ne && I.warn(`using custom API URL: ${C}`), await Be(c, S);
650
+ let T = r("vite-plugin", Me());
651
+ if (i === "api") I.debug("mode is 'api': skipping the project-config prefetch");
652
+ else if (f.command === "build") {
653
+ let t = Ve(C, S, c);
654
+ h = t;
566
655
  let n = Q.get(t);
567
656
  n === void 0 && (n = (async () => {
568
- M.info(`prefetching project config + content for "${x}"`);
569
- let t = B(l), n = e(t.pickedDir), r = performance.now(), i = await U({
570
- apiUrl: S,
571
- projectId: x,
572
- projectRoot: l,
573
- headers: w,
574
- previewToken: C ?? void 0
657
+ I.info(`prefetching project config + content for "${S}"`);
658
+ let t = U(c), n = e(t.pickedDir), r = performance.now(), i = await he({
659
+ apiUrl: C,
660
+ projectId: S,
661
+ projectRoot: c,
662
+ headers: T,
663
+ previewToken: w ?? void 0
575
664
  }), a = (performance.now() - r).toFixed(0);
576
- await ie(l, n);
665
+ await se(c, n);
577
666
  let o = i.config;
578
667
  return $(o, a), {
579
- virtualSource: ue({
668
+ virtualSource: Ce({
580
669
  projectConfigPath: t.projectConfigPath,
581
670
  experienceContentPaths: i.experienceContentPaths,
582
671
  manifestMetadata: {
@@ -586,36 +675,40 @@ function Oe(t = {}) {
586
675
  workspaceId: i.manifest.workspaceId
587
676
  }
588
677
  }),
589
- features: R(o.features)
678
+ features: V(o.features)
590
679
  };
591
680
  })(), n.catch(() => Q.delete(t)), Q.set(t, n));
592
681
  let r = await n;
593
- h = r.virtualSource, c = r.features;
594
- } else if (_.mode === "production") M.debug("skipping the dev project-config fetch for a production serve resolution");
682
+ g = r.virtualSource, s = r.features;
683
+ } else if (f.mode === "production") I.debug("skipping the dev project-config fetch for a production serve resolution");
595
684
  else {
596
- M.info(`fetching project config for "${x}" (dev)`);
597
- let e = performance.now(), t = () => a(S, x, {
598
- headers: w,
599
- previewToken: C ?? void 0
600
- }), n = I(S) ? await L(t, (e, t, n) => {
601
- M.info(`local API not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
685
+ I.info(`fetching project config for "${S}" (dev)`);
686
+ let e = performance.now(), t = () => a(C, S, {
687
+ headers: T,
688
+ previewToken: w ?? void 0
689
+ }), n = z(C) ? await B(t, (e, t, n) => {
690
+ I.info(`local API not ready, retrying in ${(n / 1e3).toString()}s (${e.toString()}/${t.toString()})`);
602
691
  }) : await t(), r = (performance.now() - e).toFixed(0);
603
- g = n, n ? (c = R(n.features), $(n, r)) : M.warn(`failed to fetch project config for "${x}" (${r}ms)`);
692
+ _ = n, n ? (s = V(n.features), $(n, r)) : I.warn(`failed to fetch project config for "${S}" (${r}ms)`);
604
693
  }
605
694
  },
606
695
  configResolved(e) {
607
- d = e.base;
696
+ f = e.base;
608
697
  },
609
698
  closeBundle() {
610
- m !== void 0 && Q.delete(m);
699
+ h !== void 0 && Q.delete(h), v?.flush({
700
+ "picked.vite.command": d,
701
+ "picked.data.mode": i,
702
+ "picked.source": p?.source ?? "unknown"
703
+ });
611
704
  },
612
705
  transformIndexHtml: {
613
706
  order: "post",
614
707
  handler(e, t) {
615
708
  if (i === "api" || t.bundle === void 0) return;
616
- let n = xe(t.bundle);
709
+ let n = Pe(t.bundle);
617
710
  if (n === void 0) return;
618
- let r = Se(d, n);
711
+ let r = Fe(f, n);
619
712
  if (!e.includes(`"${r}"`)) return [{
620
713
  tag: "link",
621
714
  attrs: {
@@ -632,20 +725,20 @@ function Oe(t = {}) {
632
725
  },
633
726
  load(e) {
634
727
  if (e === X) {
635
- if (i === "api") return q();
636
- if (u === "build") return h;
637
- if (!f) throw Error("picked plugin config hook must run before virtual module load");
638
- return de({
639
- apiUrl: f.apiUrl,
640
- projectId: f.projectId,
641
- projectConfig: g,
642
- previewToken: f.previewToken ?? void 0
728
+ if (i === "api") return Se();
729
+ if (d === "build") return g;
730
+ if (!p) throw Error("picked plugin config hook must run before virtual module load");
731
+ return we({
732
+ apiUrl: p.apiUrl,
733
+ projectId: p.projectId,
734
+ projectConfig: _,
735
+ previewToken: p.previewToken ?? void 0
643
736
  });
644
737
  }
645
738
  },
646
739
  configureServer(e) {
647
740
  if (t.disableLauncher) return;
648
- e.middlewares.use(re(() => y(c)));
741
+ e.middlewares.use(oe(() => E(s)));
649
742
  let n = e.printUrls.bind(e);
650
743
  e.printUrls = () => {
651
744
  let t = e.resolvedUrls?.local[0];
@@ -661,21 +754,21 @@ function Oe(t = {}) {
661
754
  handler(e, n) {
662
755
  if (!t.disableLauncher) {
663
756
  if ("index.html" in n) {
664
- M.debug("index.html came from the build; skipping the launcher page");
757
+ I.debug("index.html came from the build; skipping the launcher page");
665
758
  return;
666
759
  }
667
760
  this.emitFile({
668
761
  type: "asset",
669
762
  fileName: "index.html",
670
- source: y(c)
763
+ source: E(s)
671
764
  });
672
765
  }
673
766
  }
674
767
  }
675
- };
768
+ });
676
769
  }
677
770
  function $(e, t) {
678
- let n = R(e.features), r = R(e.experiences), i = R(e.steps), a = R(e.fields), o = R(e.conditions), s = R(e.actions), c = JSON.stringify(e).length, l = [
771
+ let n = V(e.features), r = V(e.experiences), i = V(e.steps), a = V(e.fields), o = V(e.conditions), s = V(e.actions), c = JSON.stringify(e).length, l = [
679
772
  `${n.length.toString()} features`,
680
773
  `${r.length.toString()} experiences`,
681
774
  `${i.length.toString()} steps`,
@@ -683,7 +776,7 @@ function $(e, t) {
683
776
  `${o.length.toString()} conditions`,
684
777
  `${s.length.toString()} actions`
685
778
  ].join(", ");
686
- M.info(`fetched config in ${t}ms (${l})`), J("Features", n, me), J("Experiences", r, he), J("Steps", i, ge), J("Fields", a, _e), J("Conditions", o, ve), pe("Actions", s), M.debug(`config size: ${c.toString()} bytes`);
779
+ I.info(`fetched config in ${t}ms (${l})`), J("Features", n, De), J("Experiences", r, Oe), J("Steps", i, ke), J("Fields", a, Ae), J("Conditions", o, je), Ee("Actions", s), I.debug(`config size: ${c.toString()} bytes`);
687
780
  }
688
781
  //#endregion
689
- export { Oe as picked };
782
+ export { He as picked };