@picked/client 0.0.71 → 0.0.72-next.2
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/{api-CkWvU-fy.js → api-B8SVav6V.js} +1 -1
- package/dist/api-D9899KCk.cjs +1 -0
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
- package/dist/cjs/server/index.js +1 -1
- package/dist/docs/explanation/how-picked-works.md +25 -3
- package/dist/docs/reference/sdk/plugins/dynamic-experiences.md +50 -2
- package/dist/docs/reference/tools/vite-plugin.md +90 -8
- package/dist/esm/index.js +22 -1
- package/dist/esm/plugins/dynamic-experiences/index.js +4 -3
- package/dist/esm/server/index.js +43 -46
- package/dist/plugin-EFn9ALEF.cjs +1 -0
- package/dist/plugin-YytfMG0n.js +153 -0
- package/dist/provider-DmXJ58nW.cjs +1 -0
- package/dist/provider-GuxX7UDO.js +68 -0
- package/dist/registry-CMsN5pHn.cjs +1 -0
- package/dist/registry-DzpNnRIF.js +74 -0
- package/dist/types/data-source/api.d.ts +60 -0
- package/dist/types/data-source/api.d.ts.map +1 -0
- package/dist/types/data-source/provider.d.ts +90 -0
- package/dist/types/data-source/provider.d.ts.map +1 -0
- package/dist/types/data-source/registry.d.ts +26 -0
- package/dist/types/data-source/registry.d.ts.map +1 -0
- package/dist/types/data-source/virtual-data.d.ts +19 -0
- package/dist/types/data-source/virtual-data.d.ts.map +1 -0
- package/dist/types/picked.d.ts +65 -1
- package/dist/types/picked.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/index.d.ts +1 -0
- package/dist/types/plugins/dynamic-experiences/index.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts +9 -40
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/types.d.ts +15 -23
- package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
- package/dist/types/server/index.d.ts +1 -1
- package/dist/types/server/index.d.ts.map +1 -1
- package/dist/types/server/serialize.d.ts +21 -33
- package/dist/types/server/serialize.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/api-Du5sDt-A.cjs +0 -1
- package/dist/plugin-DaGxLHkq.js +0 -252
- package/dist/plugin-nhx7zYeB.cjs +0 -1
|
@@ -6,8 +6,8 @@ layout: docs
|
|
|
6
6
|
# Vite Plugin
|
|
7
7
|
|
|
8
8
|
`@picked/vite-plugin-picked` adds Picked to your Vite project. It reads the options
|
|
9
|
-
of your project at build time. It then
|
|
10
|
-
|
|
9
|
+
of your project at build time. It then puts them in a module that gives them to the
|
|
10
|
+
SDK, so the SDK makes no API request at runtime. In development it also serves a
|
|
11
11
|
launcher page. On that page you can see a preview of an experience with your own
|
|
12
12
|
feature flag values.
|
|
13
13
|
|
|
@@ -19,11 +19,75 @@ When Vite starts, in both `dev` and `build`, the plugin does this:
|
|
|
19
19
|
|
|
20
20
|
1. It reads the configuration of your project from the Picked API.
|
|
21
21
|
2. It embeds those options in your bundle.
|
|
22
|
-
3. The
|
|
22
|
+
3. The module gives the options to the SDK as the browser loads it.
|
|
23
|
+
4. The SDK reads the embedded configuration at runtime and makes no network request.
|
|
24
|
+
|
|
25
|
+
Step 3 is a function call. The module gives the options to the SDK as it loads, and does
|
|
26
|
+
not wait for the SDK to ask.
|
|
23
27
|
|
|
24
28
|
When a preview token is there at runtime, the SDK ignores the embedded configuration and
|
|
25
29
|
reads fresh data from the API.
|
|
26
30
|
|
|
31
|
+
### Preload of the data file
|
|
32
|
+
|
|
33
|
+
Vite puts the options of your project in their own JavaScript file. For each HTML page
|
|
34
|
+
in your build, the plugin adds a `<link rel="modulepreload">` for that file. The
|
|
35
|
+
browser then gets it while it reads the page, and not later when the SDK starts.
|
|
36
|
+
|
|
37
|
+
The CMS content of an experience stays in its own file and gets no preload. The
|
|
38
|
+
browser gets it only when an experience needs it.
|
|
39
|
+
|
|
40
|
+
Some applications make their HTML from the code, and not from an HTML file in your
|
|
41
|
+
project. React Router in server mode is one of these. Such a build has no page for the
|
|
42
|
+
plugin to add the link to. Add this line to the code that runs in the browser instead:
|
|
43
|
+
|
|
44
|
+
:::code-group
|
|
45
|
+
|
|
46
|
+
```ts [entry.client.ts]
|
|
47
|
+
import 'virtual:picked/data'
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
:::
|
|
51
|
+
|
|
52
|
+
Your framework then sees the file in its own list and adds the preload for you.
|
|
53
|
+
|
|
54
|
+
The line reads no value from the module. It is there for the work the module does as it
|
|
55
|
+
loads. A bundler removes a module that only declares values, and removes the line with
|
|
56
|
+
it. This module gives your project options to the SDK, which is work, so the bundler
|
|
57
|
+
keeps both.
|
|
58
|
+
|
|
59
|
+
Your application is correct without this line. The SDK gets the same data later, as it
|
|
60
|
+
starts. The line moves that work earlier.
|
|
61
|
+
|
|
62
|
+
### Types for the data file
|
|
63
|
+
|
|
64
|
+
The plugin makes `virtual:picked/data` at build time. Because the module is not a file in
|
|
65
|
+
your project, TypeScript cannot find its types. The plugin gives you a type file for the
|
|
66
|
+
module. Point your project at that type file to import from the module:
|
|
67
|
+
|
|
68
|
+
:::code-group
|
|
69
|
+
|
|
70
|
+
```json [tsconfig.json]
|
|
71
|
+
{
|
|
72
|
+
"compilerOptions": {
|
|
73
|
+
"types": ["@picked/vite-plugin-picked/client"]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```ts [picked-data.ts]
|
|
79
|
+
/// <reference types="@picked/vite-plugin-picked/client" />
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
:::
|
|
83
|
+
|
|
84
|
+
Use one of the two. The `types` option applies to all files in your project. The
|
|
85
|
+
`reference` comment applies to one file.
|
|
86
|
+
|
|
87
|
+
The module gives three values: `projectConfig`, `experienceContent` and
|
|
88
|
+
`manifestMetadata`. You do not give these values to the SDK. The module gives them to
|
|
89
|
+
the SDK itself as the browser loads it.
|
|
90
|
+
|
|
27
91
|
### Dev launcher
|
|
28
92
|
|
|
29
93
|
In development, the plugin serves an HTML page at `/`. On that page you can:
|
|
@@ -42,11 +106,23 @@ After the dev server starts, the launcher URL appears next to the Vite output:
|
|
|
42
106
|
|
|
43
107
|
## Options
|
|
44
108
|
|
|
45
|
-
| Option | Type
|
|
46
|
-
| ---------------- |
|
|
47
|
-
| `projectId` | `string`
|
|
48
|
-
| `apiUrl` | `string`
|
|
49
|
-
| `disableLauncher`| `boolean`
|
|
109
|
+
| Option | Type | Default | Description |
|
|
110
|
+
| ---------------- | --------------------- | ------------------------ | --------------------------------------------------------- |
|
|
111
|
+
| `projectId` | `string` | — | **Required.** The ID of your Picked project. |
|
|
112
|
+
| `apiUrl` | `string` | `https://api.picked.app` | Your own API URL, for a self-hosted or local API. |
|
|
113
|
+
| `disableLauncher`| `boolean` | `false` | Turns the launcher page off in both dev and build output. |
|
|
114
|
+
| `mode` | `'bundle' \| 'api'` | `'bundle'` | Whether the build carries your project data. |
|
|
115
|
+
|
|
116
|
+
### mode
|
|
117
|
+
|
|
118
|
+
`'bundle'` reads your project options at build time and puts them in your bundle.
|
|
119
|
+
|
|
120
|
+
`'api'` does not read them. Your build then makes no request to the Picked API, and
|
|
121
|
+
writes no `.picked` directory. The SDK reads your project options from the API at
|
|
122
|
+
runtime instead. Use this when your build must not depend on the Picked API.
|
|
123
|
+
|
|
124
|
+
The SDK has no equivalent option. It uses the data your build gives it, and the API when
|
|
125
|
+
your build gives none.
|
|
50
126
|
|
|
51
127
|
## Build output
|
|
52
128
|
|
|
@@ -54,6 +130,12 @@ For a production build, `vite build`, the plugin writes an `index.html` file tha
|
|
|
54
130
|
holds the launcher page. Set `disableLauncher` to stop this. The file lets you deploy
|
|
55
131
|
the launcher next to your application, so that a stakeholder can see a preview.
|
|
56
132
|
|
|
133
|
+
The plugin writes that file only when your build made no `index.html` of its own. An
|
|
134
|
+
application that has an HTML entry keeps its own page at the root of the output.
|
|
135
|
+
|
|
136
|
+
The plugin also writes a `.picked` directory next to your Vite `root`. It holds the
|
|
137
|
+
options of your project and the CMS content of each experience.
|
|
138
|
+
|
|
57
139
|
## Related
|
|
58
140
|
|
|
59
141
|
- [How to install the Vite plugin](/how-to/install-the-vite-plugin)
|
package/dist/esm/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { a as i, c as a, d as o, f as s, i as c, l, m as u, n as d, o as f, r as
|
|
|
5
5
|
import { a as _, i as v, r as y, s as b, t as x } from "../dom-BqcToNL0.js";
|
|
6
6
|
import { l as S, n as C, r as w, u as T } from "../experience-instance-DGk11d8a.js";
|
|
7
7
|
import { i as E, n as D, r as O, t as k } from "../storage-1MW3-_As.js";
|
|
8
|
-
import { n as ee, r as te } from "../api-
|
|
8
|
+
import { n as ee, r as te } from "../api-B8SVav6V.js";
|
|
9
9
|
import { t as ne } from "../id-Bo4RBeOs.js";
|
|
10
10
|
import { n as re, r as ie, t as ae } from "../inert-script-report-B_bMPRzp.js";
|
|
11
11
|
import { attach as A, combine as j, createApi as M, createDomain as N, createEffect as P, createEvent as F, createStore as I, sample as L } from "effector";
|
|
@@ -1717,9 +1717,12 @@ var Ut = class {
|
|
|
1717
1717
|
static logger = r;
|
|
1718
1718
|
options;
|
|
1719
1719
|
dataSource = null;
|
|
1720
|
+
seededVersionId = null;
|
|
1721
|
+
versionSkew = null;
|
|
1720
1722
|
contentLoader;
|
|
1721
1723
|
previewEmbedderOrigins = null;
|
|
1722
1724
|
plugins = {};
|
|
1725
|
+
dataProviders = /* @__PURE__ */ new Map();
|
|
1723
1726
|
eventBus = F();
|
|
1724
1727
|
events;
|
|
1725
1728
|
projectId;
|
|
@@ -1767,6 +1770,24 @@ var Ut = class {
|
|
|
1767
1770
|
version: te()
|
|
1768
1771
|
}), this.maybeStartPreviewChannel();
|
|
1769
1772
|
}
|
|
1773
|
+
dataProviderFor(e) {
|
|
1774
|
+
let t = e ?? "", n = this.dataProviders.get(t);
|
|
1775
|
+
if (n) return n;
|
|
1776
|
+
let r = import("../provider-GuxX7UDO.js").then((t) => t.createPickedDataProvider({
|
|
1777
|
+
apiUrl: this.apiUrl,
|
|
1778
|
+
projectId: this.projectId,
|
|
1779
|
+
...e !== void 0 && { previewToken: e }
|
|
1780
|
+
}));
|
|
1781
|
+
return this.dataProviders.set(t, r), r;
|
|
1782
|
+
}
|
|
1783
|
+
async getProjectConfig(e) {
|
|
1784
|
+
let t = await this.dataProviderFor(e?.previewToken), n = await t.getProjectConfig();
|
|
1785
|
+
if (this.dataSource = t.meta.manifest, n === null) throw Error(`Picked could not resolve the configuration for project "${this.projectId}" from ${this.apiUrl}.`);
|
|
1786
|
+
return n;
|
|
1787
|
+
}
|
|
1788
|
+
async getExperienceContent(e, t) {
|
|
1789
|
+
return (await this.dataProviderFor(t?.previewToken)).getContent(e, t?.signal === void 0 ? void 0 : { signal: t.signal });
|
|
1790
|
+
}
|
|
1770
1791
|
maybeStartPreviewChannel() {
|
|
1771
1792
|
Ht() && import("../preview-channel-CSr96XAo.js").then((e) => e.initPreviewChannel(this)).catch(() => void 0);
|
|
1772
1793
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { i as e } from "../../../api-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { i as e } from "../../../api-B8SVav6V.js";
|
|
2
|
+
import { t } from "../../../plugin-YytfMG0n.js";
|
|
3
|
+
import { a as n, i as r, n as i } from "../../../registry-DzpNnRIF.js";
|
|
4
|
+
export { e as createClientHeaders, t as dynamicExperiencesPlugin, r as fetchExperienceContent, n as fetchProject, i as registerPickedBundle };
|
package/dist/esm/server/index.js
CHANGED
|
@@ -1,44 +1,41 @@
|
|
|
1
1
|
import { a as e, c as t, i as n, o as r, s as i, t as a, u as o } from "../../experience-instance-DGk11d8a.js";
|
|
2
|
-
import {
|
|
3
|
-
import { attach as
|
|
2
|
+
import { n as s } from "../../plugin-YytfMG0n.js";
|
|
3
|
+
import { attach as c, createEffect as l, createEvent as u, createStore as d, sample as f } from "effector";
|
|
4
4
|
//#region src/server/serialize.ts
|
|
5
|
-
var
|
|
6
|
-
function
|
|
5
|
+
var p = 1e4;
|
|
6
|
+
function m(e) {
|
|
7
7
|
if (e?.location !== void 0) return { location: e.location };
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function h(e, t) {
|
|
10
10
|
return e.nodes.filter(o).some((e) => t.get(e.stepId) === !0);
|
|
11
11
|
}
|
|
12
|
-
async function
|
|
13
|
-
let {
|
|
14
|
-
e.conditionResults.reset(), s(e,
|
|
12
|
+
async function g(e, n = {}) {
|
|
13
|
+
let i = n.previewToken === void 0 ? void 0 : { previewToken: n.previewToken }, a = await e.getProjectConfig(i), o = e.session.store.getState().id;
|
|
14
|
+
e.conditionResults.reset(), s(e, a, {
|
|
15
15
|
isPreview: !1,
|
|
16
|
-
sessionId:
|
|
16
|
+
sessionId: o
|
|
17
17
|
});
|
|
18
|
-
let
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
if (r) for (let e of r.content) d.set(e.id, e);
|
|
31
|
-
}
|
|
18
|
+
let c = m(n.attributes), l = n.timeoutMs ?? p, u = new Map(a.steps.map((e) => [e.id, e.layoutContentId !== void 0 && e.layoutContentId !== null])), d = Object.fromEntries(a.conditions.map((e) => [e.key, e])), f = a.experiences.filter((e) => !t(e.condition, d)), g = (await Promise.all(f.map(async (t) => ({
|
|
19
|
+
experience: t,
|
|
20
|
+
active: await r(e, { condition: t.condition }, { context: c })
|
|
21
|
+
})))).filter((e) => e.active).map((e) => e.experience), _ = await Promise.all(g.filter((e) => h(e, u)).map((t) => e.getExperienceContent({
|
|
22
|
+
id: t.id,
|
|
23
|
+
key: t.key
|
|
24
|
+
}, {
|
|
25
|
+
...i,
|
|
26
|
+
signal: AbortSignal.timeout(l)
|
|
27
|
+
}))), v = /* @__PURE__ */ new Map();
|
|
28
|
+
for (let e of _) if (e) for (let t of e.content) v.set(t.id, t);
|
|
32
29
|
return {
|
|
33
|
-
versionId:
|
|
34
|
-
projectConfig:
|
|
35
|
-
content: Array.from(
|
|
30
|
+
versionId: a.versionId,
|
|
31
|
+
projectConfig: a,
|
|
32
|
+
content: Array.from(v.values()),
|
|
36
33
|
conditionResults: e.conditionResults.store.getState()
|
|
37
34
|
};
|
|
38
35
|
}
|
|
39
36
|
//#endregion
|
|
40
37
|
//#region src/server/index.ts
|
|
41
|
-
function
|
|
38
|
+
function _() {
|
|
42
39
|
let e, t;
|
|
43
40
|
return {
|
|
44
41
|
promise: new Promise((n, r) => {
|
|
@@ -48,16 +45,16 @@ function v() {
|
|
|
48
45
|
reject: (e) => t(e)
|
|
49
46
|
};
|
|
50
47
|
}
|
|
51
|
-
function
|
|
52
|
-
let { promise: n, resolve: r } =
|
|
48
|
+
function v(e, t) {
|
|
49
|
+
let { promise: n, resolve: r } = _(), i = u(), o = u(), s = u(), p = u(), m = u(), h = e.experiences.listStore.map((t) => t.map((t) => a({
|
|
53
50
|
client: e,
|
|
54
51
|
experience: t
|
|
55
|
-
}))), g =
|
|
52
|
+
}))), g = d({
|
|
56
53
|
currentExperienceIndex: 0,
|
|
57
54
|
renderedExperiences: [],
|
|
58
55
|
isComplete: !1
|
|
59
|
-
}),
|
|
60
|
-
let n =
|
|
56
|
+
}), v = l(async (t) => {
|
|
57
|
+
let n = c({
|
|
61
58
|
source: t.experience.componentStore,
|
|
62
59
|
effect: async (n, r) => {
|
|
63
60
|
let i = t.availableRenderers[r];
|
|
@@ -72,7 +69,7 @@ function y(e, t) {
|
|
|
72
69
|
if (t) return t;
|
|
73
70
|
}
|
|
74
71
|
return null;
|
|
75
|
-
}), y =
|
|
72
|
+
}), y = l(async ({ experience: e, availableRenderers: t, startRendererIndex: n = 0 }) => e ? v({
|
|
76
73
|
experience: e,
|
|
77
74
|
availableRenderers: t,
|
|
78
75
|
startRendererIndex: n
|
|
@@ -84,13 +81,13 @@ function y(e, t) {
|
|
|
84
81
|
})).on(m, (e) => ({
|
|
85
82
|
...e,
|
|
86
83
|
currentExperienceIndex: e.currentExperienceIndex + 1
|
|
87
|
-
})).on(
|
|
84
|
+
})).on(p, (e) => ({
|
|
88
85
|
...e,
|
|
89
86
|
isComplete: !0
|
|
90
|
-
})).reset(i),
|
|
87
|
+
})).reset(i), f({
|
|
91
88
|
clock: i,
|
|
92
89
|
target: o
|
|
93
|
-
}),
|
|
90
|
+
}), f({
|
|
94
91
|
clock: o,
|
|
95
92
|
source: {
|
|
96
93
|
experiences: h,
|
|
@@ -103,22 +100,22 @@ function y(e, t) {
|
|
|
103
100
|
startRendererIndex: 0
|
|
104
101
|
}),
|
|
105
102
|
target: y
|
|
106
|
-
}),
|
|
103
|
+
}), f({
|
|
107
104
|
clock: y.doneData,
|
|
108
105
|
filter: (e) => e !== null,
|
|
109
106
|
fn: (e) => e.rendered.body,
|
|
110
107
|
target: s
|
|
111
|
-
}),
|
|
108
|
+
}), f({
|
|
112
109
|
clock: s,
|
|
113
110
|
target: o
|
|
114
|
-
}),
|
|
111
|
+
}), f({
|
|
115
112
|
clock: y.doneData,
|
|
116
113
|
filter: (e) => e === null,
|
|
117
114
|
target: m
|
|
118
|
-
}),
|
|
115
|
+
}), f({
|
|
119
116
|
clock: m,
|
|
120
117
|
target: o
|
|
121
|
-
}),
|
|
118
|
+
}), f({
|
|
122
119
|
clock: [
|
|
123
120
|
o,
|
|
124
121
|
m,
|
|
@@ -129,18 +126,18 @@ function y(e, t) {
|
|
|
129
126
|
state: g
|
|
130
127
|
},
|
|
131
128
|
filter: ({ experiences: e, state: t }) => t.currentExperienceIndex >= e.length,
|
|
132
|
-
target:
|
|
129
|
+
target: p
|
|
133
130
|
});
|
|
134
|
-
let b =
|
|
131
|
+
let b = c({
|
|
135
132
|
source: g,
|
|
136
133
|
effect: (e) => {
|
|
137
134
|
e.isComplete && r(e.renderedExperiences);
|
|
138
135
|
}
|
|
139
136
|
});
|
|
140
|
-
return
|
|
141
|
-
clock:
|
|
137
|
+
return f({
|
|
138
|
+
clock: p,
|
|
142
139
|
target: b
|
|
143
140
|
}), i(), n;
|
|
144
141
|
}
|
|
145
142
|
//#endregion
|
|
146
|
-
export { a as createExperienceInstance, n as evaluateConditionMemo, e as hashRule, r as isExperienceActive, s as registerProjectConfig,
|
|
143
|
+
export { a as createExperienceInstance, n as evaluateConditionMemo, e as hashRule, r as isExperienceActive, s as registerProjectConfig, v as render, i as ruleReferencesAction, t as ruleReferencesActionDeep, g as serialize };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("./logger-CSTvAyyB.cjs");let e=require("effector");function t(e){let t=2166136261;for(let n of e)t^=n.codePointAt(0)??0,t=Math.imul(t,16777619);return t>>>0}function n(e){let t=e;return t^=t>>>16,t=Math.imul(t,2246822507),t^=t>>>13,t=Math.imul(t,3266489909),t^=t>>>16,t>>>0}function r(e,r){return n(t(`${e}:${r}`))%100}function i(e,t){return t<=0?!1:t>=100||e<t}function a(e,t){if(Array.isArray(t.conditions))for(let n of t.conditions)e.registerCondition(n)}function o(e,t){e.registerExperience({id:t.id,key:t.key,name:t.name,targets:t.targets,nodes:t.nodes,edges:t.edges,condition:t.condition,initializeOpen:t.initializeOpen,componentName:t.componentName})}function s(e,t){if(Array.isArray(t.fields))for(let n of t.fields)e.registerField(n)}function c(e,t){if(!Array.isArray(t.steps))return;let n=new Map(t.fields.map(e=>[e.id,e.key]));for(let r of t.steps){let t=[];for(let e of r.fieldIds??[]){let i=n.get(e);if(i===void 0){`${r.key}${e}`;continue}t.push(i)}let i=r.layoutContentId?e.contents.getById(r.layoutContentId):null;e.registerStep({id:r.id,key:r.key,name:r.name,fieldKeys:t,layoutName:r.layoutName,...r.layoutContentId!==void 0&&{layoutContentId:r.layoutContentId,layoutContentStore:i}})}}function l(e,t){if(Array.isArray(t.experiences))for(let n of t.experiences)o(e,n)}function u(e,t,n){p(e,t,n.isPreview,n.sessionId),a(e,t),s(e,t),c(e,t),l(e,t)}function d(e){let t=e.searchParams[`preview-token`];if(t&&t.length>0)return t[0]}function f(e){let t=new Set,n=e.searchParams.feature;if(!n)return t;for(let e of n){let n=e.indexOf(`:`);n>0&&t.add(e.substring(0,n))}return t}function p(e,t,n,r){let i=f(e);for(let a of t.features)i.has(a.id)||m(e,a,n,r)}function m(e,t,n,a){let o=r(a,t.id);e.registerFeature(t.id,{key:`v${t.version}`,name:t.name,enabled:t.enabled,weight:t.weight,storage:n?`session`:`local`,decide:()=>i(o,t.weight)})}function h(e,t){for(let n of t.content)e.registerContent({id:n.id,contentModelKey:n.contentModelKey,data:n.data})}function g(e,t){let n=new Map;return(r,i)=>{let a=n.get(r.id);if(a)return a;let o=(async()=>{try{let n=await t(r,i);return n&&h(e,n),n}finally{n.delete(r.id)}})();return n.set(r.id,o),o}}function _(e,t){let n=new Set(t&&Array.isArray(t.experiences)?t.experiences.map(e=>e.id):[]);return(t,r)=>n.has(t.id)?e(t,r):Promise.resolve(null)}function v(){return{name:`dynamic-experiences`,setup:t=>({onStart:(0,e.attach)({source:t.session.store.map(e=>e.id),effect:async e=>{let n=d(t),r=n!==void 0,i=n===void 0?void 0:{previewToken:n},a=await t.getProjectConfig(n===void 0?void 0:{previewToken:n}).catch(e=>null);if(t.contentLoader=g(t,_(e=>t.getExperienceContent(e,i),a)),!a)return;let o=t.seededVersionId;if(o!==null&&o!==a.versionId){t.versionSkew={seeded:o,resolved:a.versionId},`${a.versionId}${o}`;return}t.previewEmbedderOrigins=a.previewEmbedderOrigins??null,u(t,a,{isPreview:r,sessionId:e})}})})}}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return v}});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import "./logger-DMN6TxJJ.js";
|
|
2
|
+
import { attach as e } from "effector";
|
|
3
|
+
//#region src/plugins/dynamic-experiences/hash.ts
|
|
4
|
+
function t(e) {
|
|
5
|
+
let t = 2166136261;
|
|
6
|
+
for (let n of e) t ^= n.codePointAt(0) ?? 0, t = Math.imul(t, 16777619);
|
|
7
|
+
return t >>> 0;
|
|
8
|
+
}
|
|
9
|
+
function n(e) {
|
|
10
|
+
let t = e;
|
|
11
|
+
return t ^= t >>> 16, t = Math.imul(t, 2246822507), t ^= t >>> 13, t = Math.imul(t, 3266489909), t ^= t >>> 16, t >>> 0;
|
|
12
|
+
}
|
|
13
|
+
function r(e, r) {
|
|
14
|
+
return n(t(`${e}:${r}`)) % 100;
|
|
15
|
+
}
|
|
16
|
+
function i(e, t) {
|
|
17
|
+
return t <= 0 ? !1 : t >= 100 || e < t;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/plugins/dynamic-experiences/plugin.ts
|
|
21
|
+
function a(e, t) {
|
|
22
|
+
if (Array.isArray(t.conditions)) for (let n of t.conditions) e.registerCondition(n);
|
|
23
|
+
}
|
|
24
|
+
function o(e, t) {
|
|
25
|
+
e.registerExperience({
|
|
26
|
+
id: t.id,
|
|
27
|
+
key: t.key,
|
|
28
|
+
name: t.name,
|
|
29
|
+
targets: t.targets,
|
|
30
|
+
nodes: t.nodes,
|
|
31
|
+
edges: t.edges,
|
|
32
|
+
condition: t.condition,
|
|
33
|
+
initializeOpen: t.initializeOpen,
|
|
34
|
+
componentName: t.componentName
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function s(e, t) {
|
|
38
|
+
if (Array.isArray(t.fields)) for (let n of t.fields) e.registerField(n);
|
|
39
|
+
}
|
|
40
|
+
function c(e, t) {
|
|
41
|
+
if (!Array.isArray(t.steps)) return;
|
|
42
|
+
let n = new Map(t.fields.map((e) => [e.id, e.key]));
|
|
43
|
+
for (let r of t.steps) {
|
|
44
|
+
let t = [];
|
|
45
|
+
for (let e of r.fieldIds ?? []) {
|
|
46
|
+
let i = n.get(e);
|
|
47
|
+
if (i === void 0) {
|
|
48
|
+
`${r.key}${e}`;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
t.push(i);
|
|
52
|
+
}
|
|
53
|
+
let i = r.layoutContentId ? e.contents.getById(r.layoutContentId) : null;
|
|
54
|
+
e.registerStep({
|
|
55
|
+
id: r.id,
|
|
56
|
+
key: r.key,
|
|
57
|
+
name: r.name,
|
|
58
|
+
fieldKeys: t,
|
|
59
|
+
layoutName: r.layoutName,
|
|
60
|
+
...r.layoutContentId !== void 0 && {
|
|
61
|
+
layoutContentId: r.layoutContentId,
|
|
62
|
+
layoutContentStore: i
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function l(e, t) {
|
|
68
|
+
if (Array.isArray(t.experiences)) for (let n of t.experiences) o(e, n);
|
|
69
|
+
}
|
|
70
|
+
function u(e, t, n) {
|
|
71
|
+
p(e, t, n.isPreview, n.sessionId), a(e, t), s(e, t), c(e, t), l(e, t);
|
|
72
|
+
}
|
|
73
|
+
function d(e) {
|
|
74
|
+
let t = e.searchParams["preview-token"];
|
|
75
|
+
if (t && t.length > 0) return t[0];
|
|
76
|
+
}
|
|
77
|
+
function f(e) {
|
|
78
|
+
let t = /* @__PURE__ */ new Set(), n = e.searchParams.feature;
|
|
79
|
+
if (!n) return t;
|
|
80
|
+
for (let e of n) {
|
|
81
|
+
let n = e.indexOf(":");
|
|
82
|
+
n > 0 && t.add(e.substring(0, n));
|
|
83
|
+
}
|
|
84
|
+
return t;
|
|
85
|
+
}
|
|
86
|
+
function p(e, t, n, r) {
|
|
87
|
+
let i = f(e);
|
|
88
|
+
for (let a of t.features) i.has(a.id) || m(e, a, n, r);
|
|
89
|
+
}
|
|
90
|
+
function m(e, t, n, a) {
|
|
91
|
+
let o = r(a, t.id);
|
|
92
|
+
e.registerFeature(t.id, {
|
|
93
|
+
key: `v${t.version}`,
|
|
94
|
+
name: t.name,
|
|
95
|
+
enabled: t.enabled,
|
|
96
|
+
weight: t.weight,
|
|
97
|
+
storage: n ? "session" : "local",
|
|
98
|
+
decide: () => i(o, t.weight)
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function h(e, t) {
|
|
102
|
+
for (let n of t.content) e.registerContent({
|
|
103
|
+
id: n.id,
|
|
104
|
+
contentModelKey: n.contentModelKey,
|
|
105
|
+
data: n.data
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function g(e, t) {
|
|
109
|
+
let n = /* @__PURE__ */ new Map();
|
|
110
|
+
return (r, i) => {
|
|
111
|
+
let a = n.get(r.id);
|
|
112
|
+
if (a) return a;
|
|
113
|
+
let o = (async () => {
|
|
114
|
+
try {
|
|
115
|
+
let n = await t(r, i);
|
|
116
|
+
return n && h(e, n), n;
|
|
117
|
+
} finally {
|
|
118
|
+
n.delete(r.id);
|
|
119
|
+
}
|
|
120
|
+
})();
|
|
121
|
+
return n.set(r.id, o), o;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function _(e, t) {
|
|
125
|
+
let n = new Set(t && Array.isArray(t.experiences) ? t.experiences.map((e) => e.id) : []);
|
|
126
|
+
return (t, r) => n.has(t.id) ? e(t, r) : Promise.resolve(null);
|
|
127
|
+
}
|
|
128
|
+
function v() {
|
|
129
|
+
return {
|
|
130
|
+
name: "dynamic-experiences",
|
|
131
|
+
setup: (t) => ({ onStart: e({
|
|
132
|
+
source: t.session.store.map((e) => e.id),
|
|
133
|
+
effect: async (e) => {
|
|
134
|
+
let n = d(t), r = n !== void 0, i = n === void 0 ? void 0 : { previewToken: n }, a = await t.getProjectConfig(n === void 0 ? void 0 : { previewToken: n }).catch((e) => null);
|
|
135
|
+
if (t.contentLoader = g(t, _((e) => t.getExperienceContent(e, i), a)), !a) return;
|
|
136
|
+
let o = t.seededVersionId;
|
|
137
|
+
if (o !== null && o !== a.versionId) {
|
|
138
|
+
t.versionSkew = {
|
|
139
|
+
seeded: o,
|
|
140
|
+
resolved: a.versionId
|
|
141
|
+
}, `${a.versionId}${o}`;
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
t.previewEmbedderOrigins = a.previewEmbedderOrigins ?? null, u(t, a, {
|
|
145
|
+
isPreview: r,
|
|
146
|
+
sessionId: e
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}) })
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
export { u as n, v as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("./logger-CSTvAyyB.cjs");const e=require("./registry-CMsN5pHn.cjs");var t=`bundle`,n=`api`;async function r(){try{let t=await import(`virtual:picked/data`);return e.r(t)?t:null}catch{return null}}function i(t){if(t===void 0||e.r(t))return t}function a(a){let{apiUrl:o,projectId:s,previewToken:c,signal:l}=a,u=!!c,d=u?n:a.mode,f=i(u?void 0:a.bundle),p=u?void 0:a.projectConfig,m=a.getContent,h={mode:d??n,manifest:null},g,_,v=new Map;function y(){if(d===n)return Promise.resolve(null);if(f)return Promise.resolve(f);let t=e.t();return t?Promise.resolve(t):(g??=r(),g)}function b(e){h.mode=e?t:n,h.manifest=e?e.manifestMetadata:null}async function x(){if(p)return b(await y()),p;let n=await y();return b(n),n?n.projectConfig:d===t?null:e.a(o,s,{...c!==void 0&&{previewToken:c},...l!==void 0&&{signal:l}})}async function S(n,r){let i=c===void 0?void 0:{previewToken:c};if(m)return m(n,i);let a=await y();if(b(a),a)try{return await a.experienceContent(n,i)}catch{return`${n.id}`,null}if(d===t)return null;let u=r??l;return e.i(o,s,n.id,{...c!==void 0&&{previewToken:c},...u!==void 0&&{signal:u}})}return{meta:h,getProjectConfig:()=>(_??=x(),_),getContent:(e,t)=>{let n=v.get(e.id);if(n)return n;let r=S(e,t?.signal).finally(()=>{v.delete(e.id)});return v.set(e.id,r),r}}}exports.createPickedDataProvider=a;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import "./logger-DMN6TxJJ.js";
|
|
2
|
+
import { a as e, i as t, r as n, t as r } from "./registry-DzpNnRIF.js";
|
|
3
|
+
//#region src/data-source/provider.ts
|
|
4
|
+
var i = "bundle", a = "api";
|
|
5
|
+
async function o() {
|
|
6
|
+
try {
|
|
7
|
+
let e = await import("virtual:picked/data");
|
|
8
|
+
return n(e) ? e : null;
|
|
9
|
+
} catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function s(e) {
|
|
14
|
+
if (e === void 0 || n(e)) return e;
|
|
15
|
+
}
|
|
16
|
+
function c(n) {
|
|
17
|
+
let { apiUrl: c, projectId: l, previewToken: u, signal: d } = n, f = !!u, p = f ? a : n.mode, m = s(f ? void 0 : n.bundle), h = f ? void 0 : n.projectConfig, g = n.getContent, _ = {
|
|
18
|
+
mode: p ?? a,
|
|
19
|
+
manifest: null
|
|
20
|
+
}, v, y, b = /* @__PURE__ */ new Map();
|
|
21
|
+
function x() {
|
|
22
|
+
if (p === a) return Promise.resolve(null);
|
|
23
|
+
if (m) return Promise.resolve(m);
|
|
24
|
+
let e = r();
|
|
25
|
+
return e ? Promise.resolve(e) : (v ??= o(), v);
|
|
26
|
+
}
|
|
27
|
+
function S(e) {
|
|
28
|
+
_.mode = e ? i : a, _.manifest = e ? e.manifestMetadata : null;
|
|
29
|
+
}
|
|
30
|
+
async function C() {
|
|
31
|
+
if (h) return S(await x()), h;
|
|
32
|
+
let t = await x();
|
|
33
|
+
return S(t), t ? t.projectConfig : p === i ? null : e(c, l, {
|
|
34
|
+
...u !== void 0 && { previewToken: u },
|
|
35
|
+
...d !== void 0 && { signal: d }
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async function w(e, n) {
|
|
39
|
+
let r = u === void 0 ? void 0 : { previewToken: u };
|
|
40
|
+
if (g) return g(e, r);
|
|
41
|
+
let a = await x();
|
|
42
|
+
if (S(a), a) try {
|
|
43
|
+
return await a.experienceContent(e, r);
|
|
44
|
+
} catch {
|
|
45
|
+
return `${e.id}`, null;
|
|
46
|
+
}
|
|
47
|
+
if (p === i) return null;
|
|
48
|
+
let o = n ?? d;
|
|
49
|
+
return t(c, l, e.id, {
|
|
50
|
+
...u !== void 0 && { previewToken: u },
|
|
51
|
+
...o !== void 0 && { signal: o }
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
meta: _,
|
|
56
|
+
getProjectConfig: () => (y ??= C(), y),
|
|
57
|
+
getContent: (e, t) => {
|
|
58
|
+
let n = b.get(e.id);
|
|
59
|
+
if (n) return n;
|
|
60
|
+
let r = w(e, t?.signal).finally(() => {
|
|
61
|
+
b.delete(e.id);
|
|
62
|
+
});
|
|
63
|
+
return b.set(e.id, r), r;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { c as createPickedDataProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("./logger-CSTvAyyB.cjs");const e=require("./api-D9899KCk.cjs");function t(e){return typeof e==`object`&&!!e}function n(e){return t(e)&&`features`in e&&Array.isArray(e.features)}function r(e){return!t(e)||!(`experienceId`in e)||!(`content`in e)?!1:Array.isArray(e.content)}function i(e){try{let t=new URL(e).hostname;return t===`localhost`||t===`127.0.0.1`||t===`::1`}catch{return!1}}function a(e){if(!t(e)||!(`cause`in e))return!1;let{cause:n}=e;return!t(n)||!(`code`in n)?!1:n.code===`ECONNREFUSED`}async function o(t,r,o){let s=o?.previewToken?`projects/${r}?preview_token=${encodeURIComponent(o.previewToken)}`:`projects/${r}`,c;try{c=await e.t(t,s,o?.headers,o?.signal)}catch(e){return i(t)&&a(e),null}if(!c.ok)return`${c.status.toString()}`,null;let l;try{l=await c.json()}catch{return null}return n(l)?l:null}async function s(t,n,o,s){let c=s?.previewToken?`projects/${n}/experiences/${o}/content?preview_token=${encodeURIComponent(s.previewToken)}`:`projects/${n}/experiences/${o}/content`,l;try{l=await e.t(t,c,s?.headers,s?.signal)}catch(e){return i(t)&&a(e)||`${o}`,null}if(!l.ok)return`${o}${l.status.toString()}`,null;let u;try{u=await l.json()}catch{return`${o}`,null}return r(u)?u:(`${o}`,null)}function c(e){if(typeof e!=`object`||!e||!(`projectConfig`in e)||!(`experienceContent`in e)||!(`manifestMetadata`in e))return!1;let{experienceContent:t}=e;return typeof t==`function`}var l=null;function u(e){c(e)&&(l=e)}function d(){return l}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return d}});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import "./logger-DMN6TxJJ.js";
|
|
2
|
+
import { t as e } from "./api-B8SVav6V.js";
|
|
3
|
+
function t(e) {
|
|
4
|
+
return typeof e == "object" && !!e;
|
|
5
|
+
}
|
|
6
|
+
function n(e) {
|
|
7
|
+
return t(e) && "features" in e && Array.isArray(e.features);
|
|
8
|
+
}
|
|
9
|
+
function r(e) {
|
|
10
|
+
return !t(e) || !("experienceId" in e) || !("content" in e) ? !1 : Array.isArray(e.content);
|
|
11
|
+
}
|
|
12
|
+
function i(e) {
|
|
13
|
+
try {
|
|
14
|
+
let t = new URL(e).hostname;
|
|
15
|
+
return t === "localhost" || t === "127.0.0.1" || t === "::1";
|
|
16
|
+
} catch {
|
|
17
|
+
return !1;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function a(e) {
|
|
21
|
+
if (!t(e) || !("cause" in e)) return !1;
|
|
22
|
+
let { cause: n } = e;
|
|
23
|
+
return !t(n) || !("code" in n) ? !1 : n.code === "ECONNREFUSED";
|
|
24
|
+
}
|
|
25
|
+
async function o(t, r, o) {
|
|
26
|
+
let s = o?.previewToken ? `projects/${r}?preview_token=${encodeURIComponent(o.previewToken)}` : `projects/${r}`, c;
|
|
27
|
+
try {
|
|
28
|
+
c = await e(t, s, o?.headers, o?.signal);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return i(t) && a(e), null;
|
|
31
|
+
}
|
|
32
|
+
if (!c.ok) return `${c.status.toString()}`, null;
|
|
33
|
+
let l;
|
|
34
|
+
try {
|
|
35
|
+
l = await c.json();
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return n(l) ? l : null;
|
|
40
|
+
}
|
|
41
|
+
async function s(t, n, o, s) {
|
|
42
|
+
let c = s?.previewToken ? `projects/${n}/experiences/${o}/content?preview_token=${encodeURIComponent(s.previewToken)}` : `projects/${n}/experiences/${o}/content`, l;
|
|
43
|
+
try {
|
|
44
|
+
l = await e(t, c, s?.headers, s?.signal);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return i(t) && a(e) || `${o}`, null;
|
|
47
|
+
}
|
|
48
|
+
if (!l.ok) return `${o}${l.status.toString()}`, null;
|
|
49
|
+
let u;
|
|
50
|
+
try {
|
|
51
|
+
u = await l.json();
|
|
52
|
+
} catch {
|
|
53
|
+
return `${o}`, null;
|
|
54
|
+
}
|
|
55
|
+
return r(u) ? u : (`${o}`, null);
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/data-source/virtual-data.ts
|
|
59
|
+
function c(e) {
|
|
60
|
+
if (typeof e != "object" || !e || !("projectConfig" in e) || !("experienceContent" in e) || !("manifestMetadata" in e)) return !1;
|
|
61
|
+
let { experienceContent: t } = e;
|
|
62
|
+
return typeof t == "function";
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/data-source/registry.ts
|
|
66
|
+
var l = null;
|
|
67
|
+
function u(e) {
|
|
68
|
+
c(e) && (l = e);
|
|
69
|
+
}
|
|
70
|
+
function d() {
|
|
71
|
+
return l;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { o as a, s as i, u as n, c as r, d as t };
|