@picked/vite-plugin-picked 0.0.46 → 0.0.47-next.1
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 +4 -1
- package/dist/esm/index.js +139 -12
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/log.d.ts +21 -0
- package/dist/types/log.d.ts.map +1 -0
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -1 +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
|
+
`];console.log(n.join(`
|
|
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,25 +1,152 @@
|
|
|
1
|
-
import { fetchProject as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { fetchProject as $ } from "@picked/client/plugins/dynamic-experiences";
|
|
2
|
+
const m = "picked", x = "\x1B[0m";
|
|
3
|
+
function L() {
|
|
4
|
+
const n = process.env.NO_COLOR;
|
|
5
|
+
return n === "1" || n === "true";
|
|
6
|
+
}
|
|
7
|
+
function l(n) {
|
|
8
|
+
return (e) => L() ? e : `${n}${e}${x}`;
|
|
9
|
+
}
|
|
10
|
+
const b = ["debug", "info", "warn", "error", "silent"], u = {
|
|
11
|
+
debug: {
|
|
12
|
+
color: l("\x1B[2m"),
|
|
13
|
+
log: console.debug,
|
|
14
|
+
enabled: !1
|
|
15
|
+
},
|
|
16
|
+
info: {
|
|
17
|
+
color: l("\x1B[36m"),
|
|
18
|
+
log: console.log,
|
|
19
|
+
enabled: !0
|
|
20
|
+
},
|
|
21
|
+
warn: {
|
|
22
|
+
color: l("\x1B[33m"),
|
|
23
|
+
log: console.warn,
|
|
24
|
+
enabled: !0
|
|
25
|
+
},
|
|
26
|
+
error: {
|
|
27
|
+
color: l("\x1B[31m"),
|
|
28
|
+
log: console.error,
|
|
29
|
+
enabled: !0
|
|
30
|
+
},
|
|
31
|
+
silent: {
|
|
32
|
+
log: () => {
|
|
33
|
+
},
|
|
34
|
+
enabled: !1
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function I(n, e) {
|
|
38
|
+
const o = (/* @__PURE__ */ new Date()).toLocaleTimeString(), t = e ? `${m}:${e}` : m;
|
|
39
|
+
return `${o} [${t}] ${n}`;
|
|
40
|
+
}
|
|
41
|
+
function g(n, e, o, t) {
|
|
42
|
+
if (!n.enabled)
|
|
43
|
+
return;
|
|
44
|
+
const r = I(e, t);
|
|
45
|
+
n.log(n.color ? n.color(r) : r), o !== void 0 && n.log(o);
|
|
46
|
+
}
|
|
47
|
+
function d(n) {
|
|
48
|
+
const e = u[n], o = /* @__PURE__ */ new Set();
|
|
49
|
+
return Object.assign(
|
|
50
|
+
(t, r, c) => {
|
|
51
|
+
g(e, t, r, c);
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
once(t, r, c) {
|
|
55
|
+
!e.enabled || o.has(t) || (o.add(t), g(e, t, r, c));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
function R(n) {
|
|
61
|
+
const e = b.indexOf(n);
|
|
62
|
+
if (e === -1) {
|
|
63
|
+
g(u.error, `invalid log level: ${n}`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
for (const [o, t] of b.entries())
|
|
67
|
+
u[t].enabled = o >= e;
|
|
68
|
+
}
|
|
69
|
+
const s = l("\x1B[34m"), h = l("\x1B[36m");
|
|
70
|
+
function y() {
|
|
71
|
+
const n = [
|
|
72
|
+
` ${s("_")} ${h("_")} _ _ _`,
|
|
73
|
+
`${s("(_)")} ${h("(_)")} _ __(_)__| |_____ __| |`,
|
|
74
|
+
` ${s("_")} ${s("_")} | '_ \\ / _| / / -_) _\` |`,
|
|
75
|
+
`${s("(_)")} ${s("(_)")} | .__/_\\__|_\\_\\___\\__,_|`,
|
|
76
|
+
` |_|
|
|
77
|
+
`
|
|
78
|
+
];
|
|
79
|
+
console.log(n.join(`
|
|
80
|
+
`));
|
|
81
|
+
}
|
|
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
|
+
};
|
|
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
|
+
}
|
|
100
|
+
function O(n) {
|
|
101
|
+
try {
|
|
102
|
+
const e = new URL(n).hostname;
|
|
103
|
+
return e === "localhost" || e === "127.0.0.1" || e === "::1";
|
|
104
|
+
} catch {
|
|
105
|
+
return !1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function T(n) {
|
|
109
|
+
return new Promise((e) => {
|
|
110
|
+
setTimeout(e, n);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
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);
|
|
122
|
+
if (r)
|
|
123
|
+
return r;
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
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;
|
|
6
130
|
return {
|
|
7
131
|
name: "picked",
|
|
8
132
|
config: async () => {
|
|
9
|
-
|
|
10
|
-
const o = await
|
|
11
|
-
if (!
|
|
12
|
-
|
|
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)`);
|
|
13
137
|
return;
|
|
14
138
|
}
|
|
15
|
-
|
|
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`), {
|
|
16
143
|
define: {
|
|
17
|
-
[
|
|
144
|
+
[C]: JSON.stringify(t)
|
|
18
145
|
}
|
|
19
146
|
};
|
|
20
147
|
}
|
|
21
148
|
};
|
|
22
149
|
}
|
|
23
150
|
export {
|
|
24
|
-
|
|
151
|
+
P as picked
|
|
25
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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
2
|
+
declare function setLevel(level: LogLevel): void;
|
|
3
|
+
declare function banner(): void;
|
|
4
|
+
export declare const log: {
|
|
5
|
+
banner: typeof banner;
|
|
6
|
+
debug: ((message: string, payload?: unknown, namespace?: string) => void) & {
|
|
7
|
+
once(message: string, payload?: unknown, namespace?: string): void;
|
|
8
|
+
};
|
|
9
|
+
info: ((message: string, payload?: unknown, namespace?: string) => void) & {
|
|
10
|
+
once(message: string, payload?: unknown, namespace?: string): void;
|
|
11
|
+
};
|
|
12
|
+
warn: ((message: string, payload?: unknown, namespace?: string) => void) & {
|
|
13
|
+
once(message: string, payload?: unknown, namespace?: string): void;
|
|
14
|
+
};
|
|
15
|
+
error: ((message: string, payload?: unknown, namespace?: string) => void) & {
|
|
16
|
+
once(message: string, payload?: unknown, namespace?: string): void;
|
|
17
|
+
};
|
|
18
|
+
setLevel: typeof setLevel;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":"AAcA,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAA;AA8E9D,iBAAS,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAWvC;AAKD,iBAAS,MAAM,IAAI,IAAI,CAStB;AAED,eAAO,MAAM,GAAG;;sBA3CF,MAAM,YAAY,OAAO,cAAc,MAAM,KAAG,IAAI;sBAI9C,MAAM,YAAY,OAAO,cAAc,MAAM,GAAG,IAAI;;qBAJ1D,MAAM,YAAY,OAAO,cAAc,MAAM,KAAG,IAAI;sBAI9C,MAAM,YAAY,OAAO,cAAc,MAAM,GAAG,IAAI;;qBAJ1D,MAAM,YAAY,OAAO,cAAc,MAAM,KAAG,IAAI;sBAI9C,MAAM,YAAY,OAAO,cAAc,MAAM,GAAG,IAAI;;sBAJ1D,MAAM,YAAY,OAAO,cAAc,MAAM,KAAG,IAAI;sBAI9C,MAAM,YAAY,OAAO,cAAc,MAAM,GAAG,IAAI;;;CA8CvE,CAAA"}
|
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.
|
|
4
|
+
"version": "0.0.47-next.1",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@picked/client": "0.0.
|
|
6
|
+
"@picked/client": "0.0.47-next.1"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@repo/eslint-config": "workspace:*",
|