@picked/vite-plugin-picked 0.0.1-dev.1772083499814 → 0.0.1-dev.1772085077346
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 +1 -3
- package/dist/esm/index.js +11 -130
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/types/log.d.ts +0 -21
- package/dist/types/log.d.ts.map +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@picked/client/plugins/dynamic-experiences"),o=require("vite"),n="https://api.picked.app",f="__PICKED_PROJECT_CONFIG__";function p(e){const r=e.apiUrl??n,c=o.createLogger("info",{prefix:"[picked]"});return{name:"picked",config:async()=>{c.info(`Fetching project config for "${e.projectId}" from ${r}`);const t=await i.fetchProject(r,e.projectId);if(!t){c.warn(`Failed to fetch project config for "${e.projectId}"`);return}return c.info(`Project config fetched successfully for "${e.projectId}"`),{define:{[f]:JSON.stringify(t)}}}}}exports.picked=p;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,144 +1,25 @@
|
|
|
1
|
-
import { fetchProject as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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;
|
|
1
|
+
import { fetchProject as t } from "@picked/client/plugins/dynamic-experiences";
|
|
2
|
+
import { createLogger as f } from "vite";
|
|
3
|
+
const i = "https://api.picked.app", n = "__PICKED_PROJECT_CONFIG__";
|
|
4
|
+
function d(c) {
|
|
5
|
+
const r = c.apiUrl ?? i, e = f("info", { prefix: "[picked]" });
|
|
120
6
|
return {
|
|
121
7
|
name: "picked",
|
|
122
8
|
config: async () => {
|
|
123
|
-
|
|
124
|
-
const
|
|
9
|
+
e.info(`Fetching project config for "${c.projectId}" from ${r}`);
|
|
10
|
+
const o = await t(r, c.projectId);
|
|
125
11
|
if (!o) {
|
|
126
|
-
|
|
12
|
+
e.warn(`Failed to fetch project config for "${c.projectId}"`);
|
|
127
13
|
return;
|
|
128
14
|
}
|
|
129
|
-
|
|
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`), {
|
|
15
|
+
return e.info(`Project config fetched successfully for "${c.projectId}"`), {
|
|
135
16
|
define: {
|
|
136
|
-
[
|
|
17
|
+
[n]: JSON.stringify(o)
|
|
137
18
|
}
|
|
138
19
|
};
|
|
139
20
|
}
|
|
140
21
|
};
|
|
141
22
|
}
|
|
142
23
|
export {
|
|
143
|
-
|
|
24
|
+
d as picked
|
|
144
25
|
};
|
|
@@ -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":"AACA,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,MAAM,CAAA;AAKhD,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,CAwB3D"}
|
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.1772085077346",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@picked/client": "0.0.1-dev.
|
|
6
|
+
"@picked/client": "0.0.1-dev.1772085077346"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@repo/eslint-config": "workspace:*",
|
package/dist/types/log.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
package/dist/types/log.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|