@picked/vite-plugin-picked 0.0.1-dev.1772152395613 → 0.0.1-dev.1772162264282
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/cjs/index.js +3 -2
- package/dist/esm/index.js +74 -66
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=require("@picked/client/plugins/dynamic-experiences"),m="picked",x="\x1B[0m";function L(){const n=process.env.NO_COLOR;return n==="1"||n==="true"}function l(n){return e=>L()?e:`${n}${e}${x}`}const b=["debug","info","warn","error","silent"],_={debug:{color:l("\x1B[2m"),log:console.debug,enabled:!1},info:{color:l("\x1B[36m"),log:console.log,enabled:!0},warn:{color:l("\x1B[33m"),log:console.warn,enabled:!0},error:{color:l("\x1B[31m"),log:console.error,enabled:!0},silent:{log:()=>{},enabled:!1}};function y(n,e){const o=new Date().toLocaleTimeString(),t=e?`${m}:${e}`:m;return`${o} [${t}] ${n}`}function g(n,e,o,t){if(!n.enabled)return;const r=y(e,t);n.log(n.color?n.color(r):r),o!==void 0&&n.log(o)}function d(n){const e=_[n],o=new Set;return Object.assign((t,r,i)=>{g(e,t,r,i)},{once(t,r,i){!e.enabled||o.has(t)||(o.add(t),g(e,t,r,i))}})}function I(n){const e=b.indexOf(n);if(e===-1){g(_.error,`invalid log level: ${n}`);return}for(const[o,t]of b.entries())_[t].enabled=o>=e}const s=l("\x1B[34m"),h=l("\x1B[36m");function O(){const n=[` ${s("_")} ${h("_")} _ _ _`,`${s("(_)")} ${h("(_)")} _ __(_)__| |_____ __| |`,` ${s("_")} ${s("_")} | '_ \\ / _| / / -_) _\` |`,`${s("(_)")} ${s("(_)")} | .__/_\\__|_\\_\\___\\__,_|`,` |_|
|
|
2
2
|
`];console.log(n.join(`
|
|
3
|
-
`))}const
|
|
3
|
+
`))}const a={banner:O,debug:d("debug"),info:d("info"),warn:d("warn"),error:d("error"),setLevel:I};function R(n){if(n.length===0)return;const e=Math.max(4,...n.map(c=>c.name.length)),o=Math.max(2,...n.map(c=>c.id.length)),t=` ${"Name".padEnd(e)} ${"ID".padEnd(o)} Status Weight Ver`,r=` ${"─".repeat(e)} ${"─".repeat(o)} ──────── ────── ───`,i=n.map(c=>{const f=c.enabled?"\x1B[32m enabled\x1B[0m":"\x1B[2mdisabled\x1B[0m",u=`${c.weight.toString()}%`.padStart(6),E=`v${c.version.toString()}`;return` ${c.name.padEnd(e)} ${c.id.padEnd(o)} ${f} ${u} ${E}`});console.log([""," Features:","",t,r,...i,""].join(`
|
|
4
|
+
`))}function T(n){try{const e=new URL(n).hostname;return e==="localhost"||e==="127.0.0.1"||e==="::1"}catch{return!1}}function j(n){return new Promise(e=>{setTimeout(e,n)})}async function v(n,e){const o=await $.fetchProject(n,e);if(o||!T(n))return o;for(let t=1;t<=S;t++){a.info(`local API not ready, retrying in ${(w/1e3).toString()}s (${t.toString()}/${S.toString()})`),await j(w);const r=await $.fetchProject(n,e);if(r)return r}return null}const p="https://api.picked.app",B="__PICKED_PROJECT_CONFIG__",S=5,w=2e3;function P(n){const e=n.apiUrl??p;return{name:"picked",config:async()=>{a.banner(),a.info(`fetching project config for "${n.projectId}"`),e!==p&&a.warn(`using custom API URL: ${e}`);const o=performance.now(),t=await v(e,n.projectId),r=(performance.now()-o).toFixed(0);if(!t){a.warn(`failed to fetch project config for "${n.projectId}" (${r}ms)`);return}const i=t.features.length,c=t.features.filter(u=>u.enabled).length,f=JSON.stringify(t).length;return a.info(`fetched ${i.toString()} features (${c.toString()} enabled) for "${n.projectId}" in ${r}ms`),R(t.features),a.debug(`config size: ${f.toString()} bytes`),{define:{[B]:JSON.stringify(t)}}}}}exports.picked=P;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { fetchProject as
|
|
2
|
-
const
|
|
3
|
-
function
|
|
1
|
+
import { fetchProject as $ } from "@picked/client/plugins/dynamic-experiences";
|
|
2
|
+
const m = "picked", x = "\x1B[0m";
|
|
3
|
+
function L() {
|
|
4
4
|
const n = process.env.NO_COLOR;
|
|
5
5
|
return n === "1" || n === "true";
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
return (e) =>
|
|
7
|
+
function l(n) {
|
|
8
|
+
return (e) => L() ? e : `${n}${e}${x}`;
|
|
9
9
|
}
|
|
10
|
-
const
|
|
10
|
+
const b = ["debug", "info", "warn", "error", "silent"], u = {
|
|
11
11
|
debug: {
|
|
12
|
-
color:
|
|
12
|
+
color: l("\x1B[2m"),
|
|
13
13
|
log: console.debug,
|
|
14
14
|
enabled: !1
|
|
15
15
|
},
|
|
16
16
|
info: {
|
|
17
|
-
color:
|
|
17
|
+
color: l("\x1B[36m"),
|
|
18
18
|
log: console.log,
|
|
19
19
|
enabled: !0
|
|
20
20
|
},
|
|
21
21
|
warn: {
|
|
22
|
-
color:
|
|
22
|
+
color: l("\x1B[33m"),
|
|
23
23
|
log: console.warn,
|
|
24
24
|
enabled: !0
|
|
25
25
|
},
|
|
26
26
|
error: {
|
|
27
|
-
color:
|
|
27
|
+
color: l("\x1B[31m"),
|
|
28
28
|
log: console.error,
|
|
29
29
|
enabled: !0
|
|
30
30
|
},
|
|
@@ -34,59 +34,69 @@ const $ = ["debug", "info", "warn", "error", "silent"], _ = {
|
|
|
34
34
|
enabled: !1
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
function
|
|
38
|
-
const
|
|
39
|
-
return `${
|
|
37
|
+
function I(n, e) {
|
|
38
|
+
const o = (/* @__PURE__ */ new Date()).toLocaleTimeString(), t = e ? `${m}:${e}` : m;
|
|
39
|
+
return `${o} [${t}] ${n}`;
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function g(n, e, o, t) {
|
|
42
42
|
if (!n.enabled)
|
|
43
43
|
return;
|
|
44
|
-
const r =
|
|
45
|
-
n.log(n.color ? n.color(r) : r),
|
|
44
|
+
const r = I(e, t);
|
|
45
|
+
n.log(n.color ? n.color(r) : r), o !== void 0 && n.log(o);
|
|
46
46
|
}
|
|
47
|
-
function
|
|
48
|
-
const e =
|
|
47
|
+
function d(n) {
|
|
48
|
+
const e = u[n], o = /* @__PURE__ */ new Set();
|
|
49
49
|
return Object.assign(
|
|
50
|
-
(
|
|
51
|
-
|
|
50
|
+
(t, r, c) => {
|
|
51
|
+
g(e, t, r, c);
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
|
-
once(
|
|
55
|
-
!e.enabled ||
|
|
54
|
+
once(t, r, c) {
|
|
55
|
+
!e.enabled || o.has(t) || (o.add(t), g(e, t, r, c));
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
|
-
function
|
|
61
|
-
const e =
|
|
60
|
+
function R(n) {
|
|
61
|
+
const e = b.indexOf(n);
|
|
62
62
|
if (e === -1) {
|
|
63
|
-
u
|
|
63
|
+
g(u.error, `invalid log level: ${n}`);
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
for (const [
|
|
67
|
-
|
|
66
|
+
for (const [o, t] of b.entries())
|
|
67
|
+
u[t].enabled = o >= e;
|
|
68
68
|
}
|
|
69
|
-
const s =
|
|
70
|
-
function
|
|
69
|
+
const s = l("\x1B[34m"), h = l("\x1B[36m");
|
|
70
|
+
function y() {
|
|
71
71
|
const n = [
|
|
72
|
-
` ${s("_")} ${
|
|
73
|
-
`${s("(_)")} ${
|
|
74
|
-
` ${s("_")} ${s("_")}
|
|
75
|
-
`${s("(_)")} ${s("(_)")}
|
|
76
|
-
`
|
|
72
|
+
` ${s("_")} ${h("_")} _ _ _`,
|
|
73
|
+
`${s("(_)")} ${h("(_)")} _ __(_)__| |_____ __| |`,
|
|
74
|
+
` ${s("_")} ${s("_")} | '_ \\ / _| / / -_) _\` |`,
|
|
75
|
+
`${s("(_)")} ${s("(_)")} | .__/_\\__|_\\_\\___\\__,_|`,
|
|
76
|
+
` |_|
|
|
77
77
|
`
|
|
78
78
|
];
|
|
79
79
|
console.log(n.join(`
|
|
80
80
|
`));
|
|
81
81
|
}
|
|
82
|
-
const
|
|
83
|
-
banner:
|
|
84
|
-
debug:
|
|
85
|
-
info:
|
|
86
|
-
warn:
|
|
87
|
-
error:
|
|
88
|
-
setLevel:
|
|
82
|
+
const a = {
|
|
83
|
+
banner: y,
|
|
84
|
+
debug: d("debug"),
|
|
85
|
+
info: d("info"),
|
|
86
|
+
warn: d("warn"),
|
|
87
|
+
error: d("error"),
|
|
88
|
+
setLevel: R
|
|
89
89
|
};
|
|
90
|
+
function B(n) {
|
|
91
|
+
if (n.length === 0)
|
|
92
|
+
return;
|
|
93
|
+
const e = Math.max(4, ...n.map((i) => i.name.length)), o = Math.max(2, ...n.map((i) => i.id.length)), t = ` ${"Name".padEnd(e)} ${"ID".padEnd(o)} Status Weight Ver`, r = ` ${"─".repeat(e)} ${"─".repeat(o)} ──────── ────── ───`, c = n.map((i) => {
|
|
94
|
+
const f = i.enabled ? "\x1B[32m enabled\x1B[0m" : "\x1B[2mdisabled\x1B[0m", _ = `${i.weight.toString()}%`.padStart(6), S = `v${i.version.toString()}`;
|
|
95
|
+
return ` ${i.name.padEnd(e)} ${i.id.padEnd(o)} ${f} ${_} ${S}`;
|
|
96
|
+
});
|
|
97
|
+
console.log(["", " Features:", "", t, r, ...c, ""].join(`
|
|
98
|
+
`));
|
|
99
|
+
}
|
|
90
100
|
function O(n) {
|
|
91
101
|
try {
|
|
92
102
|
const e = new URL(n).hostname;
|
|
@@ -95,50 +105,48 @@ function O(n) {
|
|
|
95
105
|
return !1;
|
|
96
106
|
}
|
|
97
107
|
}
|
|
98
|
-
function
|
|
108
|
+
function T(n) {
|
|
99
109
|
return new Promise((e) => {
|
|
100
110
|
setTimeout(e, n);
|
|
101
111
|
});
|
|
102
112
|
}
|
|
103
|
-
async function
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
return
|
|
107
|
-
for (let
|
|
108
|
-
|
|
109
|
-
`local API not ready, retrying in ${(
|
|
110
|
-
), await
|
|
111
|
-
const r = await
|
|
113
|
+
async function v(n, e) {
|
|
114
|
+
const o = await $(n, e);
|
|
115
|
+
if (o || !O(n))
|
|
116
|
+
return o;
|
|
117
|
+
for (let t = 1; t <= w; t++) {
|
|
118
|
+
a.info(
|
|
119
|
+
`local API not ready, retrying in ${(E / 1e3).toString()}s (${t.toString()}/${w.toString()})`
|
|
120
|
+
), await T(E);
|
|
121
|
+
const r = await $(n, e);
|
|
112
122
|
if (r)
|
|
113
123
|
return r;
|
|
114
124
|
}
|
|
115
125
|
return null;
|
|
116
126
|
}
|
|
117
|
-
const
|
|
118
|
-
function
|
|
119
|
-
const e = n.apiUrl ??
|
|
127
|
+
const p = "https://api.picked.app", C = "__PICKED_PROJECT_CONFIG__", w = 5, E = 2e3;
|
|
128
|
+
function P(n) {
|
|
129
|
+
const e = n.apiUrl ?? p;
|
|
120
130
|
return {
|
|
121
131
|
name: "picked",
|
|
122
132
|
config: async () => {
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
if (!
|
|
126
|
-
|
|
133
|
+
a.banner(), a.info(`fetching project config for "${n.projectId}"`), e !== p && a.warn(`using custom API URL: ${e}`);
|
|
134
|
+
const o = performance.now(), t = await v(e, n.projectId), r = (performance.now() - o).toFixed(0);
|
|
135
|
+
if (!t) {
|
|
136
|
+
a.warn(`failed to fetch project config for "${n.projectId}" (${r}ms)`);
|
|
127
137
|
return;
|
|
128
138
|
}
|
|
129
|
-
const
|
|
130
|
-
return
|
|
131
|
-
`fetched ${
|
|
132
|
-
|
|
133
|
-
"fetch"
|
|
134
|
-
), i.debug(`config size: ${L.toString()} bytes`), {
|
|
139
|
+
const c = t.features.length, i = t.features.filter((_) => _.enabled).length, f = JSON.stringify(t).length;
|
|
140
|
+
return a.info(
|
|
141
|
+
`fetched ${c.toString()} features (${i.toString()} enabled) for "${n.projectId}" in ${r}ms`
|
|
142
|
+
), B(t.features), a.debug(`config size: ${f.toString()} bytes`), {
|
|
135
143
|
define: {
|
|
136
|
-
[
|
|
144
|
+
[C]: JSON.stringify(t)
|
|
137
145
|
}
|
|
138
146
|
};
|
|
139
147
|
}
|
|
140
148
|
};
|
|
141
149
|
}
|
|
142
150
|
export {
|
|
143
|
-
|
|
151
|
+
P as picked
|
|
144
152
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAoElC,MAAM,WAAW,mBAAmB;IAClC,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAA;IACjB,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAuC3D"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picked/vite-plugin-picked",
|
|
3
3
|
"description": "Vite plugin for build-time config injection",
|
|
4
|
-
"version": "0.0.1-dev.
|
|
4
|
+
"version": "0.0.1-dev.1772162264282",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@picked/client": "0.0.1-dev.
|
|
6
|
+
"@picked/client": "0.0.1-dev.1772162264282"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@repo/eslint-config": "workspace:*",
|