@picked/vite-plugin-picked 0.0.78-next.2 → 0.0.78
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/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +15 -15
- package/dist/esm/index.js +288 -195
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/telemetry.d.ts +44 -0
- package/dist/types/telemetry.d.ts.map +1 -0
- package/package.json +6 -5
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 {
|
|
6
|
-
import { appendFile as
|
|
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
|
|
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
|
|
14
|
-
function
|
|
14
|
+
var x, S = ["true", "false"], C = "false";
|
|
15
|
+
function w(e) {
|
|
15
16
|
let t = e.variants;
|
|
16
|
-
return !t || t.length === 0 ?
|
|
17
|
+
return !t || t.length === 0 ? S : t.map((e) => String(e.value));
|
|
17
18
|
}
|
|
18
|
-
function
|
|
19
|
-
let t =
|
|
20
|
-
return t.map((e, t) => `<option value="${
|
|
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
|
|
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="${
|
|
27
|
-
<span class="feature-name">${
|
|
28
|
-
<span class="feature-id">${
|
|
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="${
|
|
31
|
-
${
|
|
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(
|
|
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 \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, '&').replace(/\"/g, '"').replace(/</g, '<').replace(/>/g, '>');\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, '&').replace(/\"/g, '"').replace(/</g, '<').replace(/>/g, '>');\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
|
|
45
|
+
function D(e) {
|
|
45
46
|
return e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """);
|
|
46
47
|
}
|
|
47
|
-
function
|
|
48
|
+
function O(e) {
|
|
48
49
|
return e.replaceAll("&", "&").replaceAll("\"", """).replaceAll("<", "<").replaceAll(">", ">");
|
|
49
50
|
}
|
|
50
51
|
//#endregion
|
|
51
52
|
//#region src/log.ts
|
|
52
|
-
var
|
|
53
|
-
function
|
|
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
|
|
58
|
-
return (t) =>
|
|
58
|
+
function A(e) {
|
|
59
|
+
return (t) => te() ? t : `${e}${t}${ee}`;
|
|
59
60
|
}
|
|
60
|
-
var
|
|
61
|
+
var j = [
|
|
61
62
|
"debug",
|
|
62
63
|
"info",
|
|
63
64
|
"warn",
|
|
64
65
|
"error",
|
|
65
66
|
"silent"
|
|
66
|
-
],
|
|
67
|
+
], M = {
|
|
67
68
|
debug: {
|
|
68
|
-
color:
|
|
69
|
+
color: A("\x1B[2m"),
|
|
69
70
|
log: console.debug,
|
|
70
71
|
enabled: !1
|
|
71
72
|
},
|
|
72
73
|
info: {
|
|
73
|
-
color:
|
|
74
|
+
color: A("\x1B[36m"),
|
|
74
75
|
log: console.log,
|
|
75
76
|
enabled: !0
|
|
76
77
|
},
|
|
77
78
|
warn: {
|
|
78
|
-
color:
|
|
79
|
+
color: A("\x1B[33m"),
|
|
79
80
|
log: console.warn,
|
|
80
81
|
enabled: !0
|
|
81
82
|
},
|
|
82
83
|
error: {
|
|
83
|
-
color:
|
|
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
|
|
93
|
-
return `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${t ? `${
|
|
93
|
+
function ne(e, t) {
|
|
94
|
+
return `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${t ? `${k}:${t}` : k}] ${e}`;
|
|
94
95
|
}
|
|
95
|
-
function
|
|
96
|
+
function N(e, t, n, r) {
|
|
96
97
|
if (!e.enabled) return;
|
|
97
|
-
let i =
|
|
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
|
|
101
|
-
let t =
|
|
101
|
+
function P(e) {
|
|
102
|
+
let t = M[e], n = /* @__PURE__ */ new Set();
|
|
102
103
|
return Object.assign((e, n, r) => {
|
|
103
|
-
|
|
104
|
+
N(t, e, n, r);
|
|
104
105
|
}, { once(e, r, i) {
|
|
105
|
-
!t.enabled || n.has(e) || (n.add(e),
|
|
106
|
+
!t.enabled || n.has(e) || (n.add(e), N(t, e, r, i));
|
|
106
107
|
} });
|
|
107
108
|
}
|
|
108
|
-
function
|
|
109
|
-
let t =
|
|
109
|
+
function re(e) {
|
|
110
|
+
let t = j.indexOf(e);
|
|
110
111
|
if (t === -1) {
|
|
111
|
-
|
|
112
|
+
N(M.error, `invalid log level: ${e}`);
|
|
112
113
|
return;
|
|
113
114
|
}
|
|
114
|
-
for (let [e, n] of
|
|
115
|
+
for (let [e, n] of j.entries()) M[n].enabled = e >= t;
|
|
115
116
|
}
|
|
116
|
-
var
|
|
117
|
-
function
|
|
117
|
+
var F = A("\x1B[34m"), ie = A("\x1B[36m");
|
|
118
|
+
function ae() {
|
|
118
119
|
let e = [
|
|
119
|
-
` ${
|
|
120
|
-
`${
|
|
121
|
-
` ${
|
|
122
|
-
`${
|
|
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
|
|
128
|
-
banner:
|
|
129
|
-
debug:
|
|
130
|
-
info:
|
|
131
|
-
warn:
|
|
132
|
-
error:
|
|
133
|
-
setLevel:
|
|
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
|
|
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
|
|
155
|
-
async function
|
|
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
|
|
160
|
+
await h(i, `${L}
|
|
160
161
|
`);
|
|
161
162
|
return;
|
|
162
163
|
}
|
|
163
|
-
let a = await
|
|
164
|
-
if (
|
|
165
|
-
let o = `${a.length > 0 && !a.endsWith("\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
|
|
168
|
+
await f(i, o);
|
|
168
169
|
}
|
|
169
|
-
function
|
|
170
|
-
return e.split(/\r?\n/).map((e) => e.trim()).some((e) => e ===
|
|
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
|
|
175
|
-
function
|
|
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
|
|
185
|
+
function ue(e) {
|
|
185
186
|
return new Promise((t) => {
|
|
186
187
|
setTimeout(t, e);
|
|
187
188
|
});
|
|
188
189
|
}
|
|
189
|
-
async function
|
|
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 <=
|
|
198
|
-
let a =
|
|
199
|
-
t(i,
|
|
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
|
|
213
|
+
function V(e) {
|
|
213
214
|
return Array.isArray(e) ? e : [];
|
|
214
215
|
}
|
|
215
|
-
function
|
|
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
|
|
225
|
-
function
|
|
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
|
|
235
|
+
async function fe(t) {
|
|
235
236
|
if (!e(t)) return null;
|
|
236
237
|
try {
|
|
237
|
-
let e = await
|
|
238
|
-
return
|
|
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
|
|
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
|
|
247
|
+
function me(e) {
|
|
247
248
|
let t = /* @__PURE__ */ new Set();
|
|
248
|
-
for (let n of
|
|
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
|
|
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
|
|
255
|
-
let { apiUrl: r, projectId: i, projectRoot: a, headers: o, previewToken: s, reuseWhenUnchanged: c = !0 } = n, l =
|
|
256
|
-
if (await
|
|
257
|
-
let t = await
|
|
258
|
-
if (t?.version ===
|
|
259
|
-
let n = W(l,
|
|
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:
|
|
262
|
+
config: u,
|
|
262
263
|
manifest: t,
|
|
263
264
|
experienceContentPaths: n
|
|
264
265
|
};
|
|
265
|
-
|
|
266
|
+
I.info("a manifest-referenced content file is missing; refetching every experience");
|
|
266
267
|
}
|
|
267
268
|
}
|
|
268
|
-
let
|
|
269
|
-
for (let e of
|
|
270
|
-
let n = await
|
|
271
|
-
await
|
|
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:
|
|
274
|
+
fetchedAt: f
|
|
274
275
|
});
|
|
275
276
|
}
|
|
276
277
|
let g = {
|
|
277
|
-
version:
|
|
278
|
-
fetchedAt:
|
|
279
|
-
projectVersionId:
|
|
280
|
-
workspaceId:
|
|
281
|
-
projectId:
|
|
282
|
-
experiences:
|
|
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
|
|
285
|
-
config:
|
|
285
|
+
return await h(l.manifestPath, JSON.stringify(g, null, 2)), {
|
|
286
|
+
config: u,
|
|
286
287
|
manifest: g,
|
|
287
|
-
experienceContentPaths: W(l,
|
|
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
|
|
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 =
|
|
302
|
-
|
|
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}: ${
|
|
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
|
|
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}: ${
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
481
|
+
var Te = 5;
|
|
396
482
|
function J(e, t, n) {
|
|
397
483
|
if (t.length === 0) return;
|
|
398
|
-
if (t.length >
|
|
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
|
|
499
|
+
function Ee(e, t) {
|
|
414
500
|
t.length !== 0 && console.log(`\n ${e}: ${t.length.toString()} loaded\n`);
|
|
415
501
|
}
|
|
416
|
-
var
|
|
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) =>
|
|
517
|
+
value: (e) => de(e)
|
|
432
518
|
},
|
|
433
519
|
{
|
|
434
520
|
header: "Ver",
|
|
435
521
|
value: (e) => `v${e.version.toString()}`
|
|
436
522
|
}
|
|
437
|
-
],
|
|
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
|
-
],
|
|
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
|
-
],
|
|
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
|
-
],
|
|
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
|
|
496
|
-
return "0.0.78
|
|
581
|
+
function Me() {
|
|
582
|
+
return "0.0.78";
|
|
497
583
|
}
|
|
498
|
-
var
|
|
499
|
-
function
|
|
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
|
|
588
|
+
function Fe(e, t) {
|
|
503
589
|
return e === "" || e.endsWith("/") ? `${e}${t}` : `${e}/${t}`;
|
|
504
590
|
}
|
|
505
|
-
async function
|
|
591
|
+
async function Ie(e) {
|
|
506
592
|
try {
|
|
507
593
|
let t = await o({
|
|
508
594
|
config: e,
|
|
509
595
|
onWarn: (e) => {
|
|
510
|
-
|
|
596
|
+
I.warn(e);
|
|
511
597
|
}
|
|
512
598
|
});
|
|
513
|
-
|
|
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
|
-
|
|
520
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
534
|
-
let n = await
|
|
535
|
-
n && n.projectId !== t &&
|
|
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
|
|
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
|
|
546
|
-
let i = t.mode ?? "bundle", o = t.generateTypes ?? !0,
|
|
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 (
|
|
550
|
-
|
|
551
|
-
let { projectId:
|
|
552
|
-
Z("projectId",
|
|
553
|
-
projectId:
|
|
554
|
-
apiUrl:
|
|
555
|
-
}),
|
|
556
|
-
projectId:
|
|
557
|
-
apiUrl:
|
|
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:
|
|
560
|
-
|
|
561
|
-
let
|
|
562
|
-
if (i === "api")
|
|
563
|
-
else if (
|
|
564
|
-
let t =
|
|
565
|
-
|
|
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
|
-
|
|
569
|
-
let t =
|
|
570
|
-
apiUrl:
|
|
571
|
-
projectId:
|
|
572
|
-
projectRoot:
|
|
573
|
-
headers:
|
|
574
|
-
previewToken:
|
|
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
|
|
665
|
+
await se(c, n);
|
|
577
666
|
let o = i.config;
|
|
578
667
|
return $(o, a), {
|
|
579
|
-
virtualSource:
|
|
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:
|
|
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
|
-
|
|
594
|
-
} else if (
|
|
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
|
-
|
|
597
|
-
let e = performance.now(), t = () => a(
|
|
598
|
-
headers:
|
|
599
|
-
previewToken:
|
|
600
|
-
}), n =
|
|
601
|
-
|
|
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
|
-
|
|
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
|
-
|
|
696
|
+
f = e.base;
|
|
608
697
|
},
|
|
609
698
|
closeBundle() {
|
|
610
|
-
|
|
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 =
|
|
709
|
+
let n = Pe(t.bundle);
|
|
617
710
|
if (n === void 0) return;
|
|
618
|
-
let r =
|
|
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
|
|
636
|
-
if (
|
|
637
|
-
if (!
|
|
638
|
-
return
|
|
639
|
-
apiUrl:
|
|
640
|
-
projectId:
|
|
641
|
-
projectConfig:
|
|
642
|
-
previewToken:
|
|
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(
|
|
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
|
-
|
|
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:
|
|
763
|
+
source: E(s)
|
|
671
764
|
});
|
|
672
765
|
}
|
|
673
766
|
}
|
|
674
767
|
}
|
|
675
|
-
};
|
|
768
|
+
});
|
|
676
769
|
}
|
|
677
770
|
function $(e, t) {
|
|
678
|
-
let n =
|
|
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
|
-
|
|
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 {
|
|
782
|
+
export { He as picked };
|