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