@picked/client 0.0.73 → 0.0.74

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.
Files changed (84) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/api-DGFHHioX.js +22 -0
  3. package/dist/api-DrR9JbZX.cjs +1 -0
  4. package/dist/cjs/index.js +2 -2
  5. package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
  6. package/dist/cjs/server/index.js +1 -1
  7. package/dist/docs/how-to/authenticate-the-cli.md +97 -0
  8. package/dist/docs/how-to/create-and-revoke-an-api-key.md +7 -2
  9. package/dist/docs/how-to/debug-with-the-chrome-extension.md +1 -1
  10. package/dist/docs/how-to/install-the-sdk.md +31 -6
  11. package/dist/docs/how-to/install-the-vite-plugin.md +22 -9
  12. package/dist/docs/how-to/read-a-feature-flag.md +1 -1
  13. package/dist/docs/how-to/read-a-referenced-entry.md +4 -6
  14. package/dist/docs/how-to/register-a-component.md +2 -2
  15. package/dist/docs/how-to/register-an-action-handler.md +1 -1
  16. package/dist/docs/how-to/render-a-step-form.md +3 -4
  17. package/dist/docs/how-to/server-render-a-page.md +1 -1
  18. package/dist/docs/how-to/switch-workspaces.md +122 -0
  19. package/dist/docs/how-to/write-a-predicate.md +1 -1
  20. package/dist/docs/reference/dashboard/api-keys.mdx +5 -4
  21. package/dist/docs/reference/delivery-api/workspace-schema.md +74 -0
  22. package/dist/docs/reference/sdk/content.md +7 -10
  23. package/dist/docs/reference/sdk/features.md +1 -1
  24. package/dist/docs/reference/sdk/plugins/dynamic-experiences.md +1 -1
  25. package/dist/docs/reference/sdk/plugins/window-object.md +1 -1
  26. package/dist/docs/reference/sdk/ssr/serialize.md +1 -1
  27. package/dist/docs/reference/sdk/steps.md +3 -4
  28. package/dist/docs/reference/sdk/type-generation.md +169 -0
  29. package/dist/docs/reference/tools/cli.md +146 -0
  30. package/dist/docs/reference/tools/vite-plugin.md +28 -6
  31. package/dist/docs/tutorials/first-experience.mdx +6 -7
  32. package/dist/docs/tutorials/first-server-rendered-page.mdx +3 -3
  33. package/dist/esm/index.js +23 -14
  34. package/dist/esm/plugins/dynamic-experiences/index.js +5 -4
  35. package/dist/esm/server/index.js +1 -1
  36. package/dist/{plugin-DviILBha.js → plugin-B-c2VAl2.js} +24 -20
  37. package/dist/plugin-B8YrVbNq.cjs +1 -0
  38. package/dist/{provider-fU4mqyvT.js → provider-HpWMlxa0.js} +2 -1
  39. package/dist/provider-hQPGEy73.cjs +1 -0
  40. package/dist/registry-C1t8l3t9.cjs +1 -0
  41. package/dist/registry-CXZv0uLg.js +18 -0
  42. package/dist/types/data-source/api.d.ts +1 -1
  43. package/dist/types/data-source/api.d.ts.map +1 -1
  44. package/dist/types/data-source/provider.d.ts +11 -1
  45. package/dist/types/data-source/provider.d.ts.map +1 -1
  46. package/dist/types/entities/response/response.d.ts +22 -6
  47. package/dist/types/entities/response/response.d.ts.map +1 -1
  48. package/dist/types/form/create-submit-pipeline.d.ts +32 -3
  49. package/dist/types/form/create-submit-pipeline.d.ts.map +1 -1
  50. package/dist/types/index.d.ts +2 -0
  51. package/dist/types/index.d.ts.map +1 -1
  52. package/dist/types/picked.d.ts +5 -4
  53. package/dist/types/picked.d.ts.map +1 -1
  54. package/dist/types/ping.d.ts +4 -3
  55. package/dist/types/ping.d.ts.map +1 -1
  56. package/dist/types/plugins/dynamic-experiences/index.d.ts +2 -1
  57. package/dist/types/plugins/dynamic-experiences/index.d.ts.map +1 -1
  58. package/dist/types/plugins/dynamic-experiences/plugin.d.ts +1 -1
  59. package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
  60. package/dist/types/plugins/dynamic-experiences/types.d.ts +6 -116
  61. package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
  62. package/dist/types/schema-registry.d.ts +190 -0
  63. package/dist/types/schema-registry.d.ts.map +1 -0
  64. package/dist/types/server/index.d.ts +1 -1
  65. package/dist/types/server/index.d.ts.map +1 -1
  66. package/dist/types/server/serialize.d.ts +11 -1
  67. package/dist/types/server/serialize.d.ts.map +1 -1
  68. package/dist/types/typed-content.d.ts +17 -0
  69. package/dist/types/typed-content.d.ts.map +1 -0
  70. package/dist/types/utils/picked-config.d.ts +19 -1
  71. package/dist/types/utils/picked-config.d.ts.map +1 -1
  72. package/dist/version-BJFZwX5G.js +4 -0
  73. package/dist/version-DzA5_Ptz.cjs +1 -0
  74. package/package.json +3 -1
  75. package/dist/api-B6Ma2KAc.cjs +0 -1
  76. package/dist/api-BlxGTa53.js +0 -38
  77. package/dist/plugin-DkSWIASL.cjs +0 -1
  78. package/dist/provider-C8ONTzzL.cjs +0 -1
  79. package/dist/registry-BvoKbKKv.cjs +0 -1
  80. package/dist/registry-ZEiRsEkm.js +0 -74
  81. package/dist/types/utils/api.d.ts +0 -25
  82. package/dist/types/utils/api.d.ts.map +0 -1
  83. package/dist/types/utils/client-headers.d.ts +0 -2
  84. package/dist/types/utils/client-headers.d.ts.map +0 -1
@@ -0,0 +1,169 @@
1
+ ---
2
+ type: reference
3
+ layout: docs
4
+ ---
5
+
6
+ # Type Generation
7
+
8
+ Picked can generate TypeScript types from your workspace schema so field values, feature keys, content models, and step layouts are typed in your app.
9
+
10
+ ## Quick start
11
+
12
+ ### 1. Add `picked.config.ts`
13
+
14
+ Create a `picked.config.ts` in your project root:
15
+
16
+ ```typescript
17
+ import { defineConfig } from 'picked/config'
18
+
19
+ export default defineConfig({
20
+ projectId: 'your-project-id',
21
+ typesOutput: './src/picked-env.d.ts',
22
+ })
23
+ ```
24
+
25
+ | Option | Description |
26
+ | --- | --- |
27
+ | `projectId` | **Required.** Your Picked project id. |
28
+ | `typesOutput` | Path for generated types (defaults to `./src/picked-env.d.ts`). |
29
+ | `source` | Schema surface to type against: `'published'` (default) or `'preview'`. |
30
+ | `previewToken` | Workspace preview token. Required when `source` is `'preview'`, and read only then. |
31
+
32
+ The `source` value matches the `x-picked-source` field on the [workspace schema](/reference/delivery-api/workspace-schema) document — it controls whether tooling fetches the published or preview workspace shape.
33
+
34
+ A preview token reads one workspace, and it does not expire. Leave both `source` and
35
+ `previewToken` out of the committed file, and pick a workspace instead:
36
+
37
+ ```bash
38
+ picked login
39
+ picked workspace use
40
+ ```
41
+
42
+ That writes the choice, and that workspace's token, to `.picked/settings.json`, which is
43
+ per-developer and which Git ignores. Each developer points at their own workspace, and the
44
+ committed file holds no token.
45
+
46
+ You can also set the values here. Every developer then reads the same workspace:
47
+
48
+ ```typescript
49
+ export default defineConfig({
50
+ projectId: 'your-project-id',
51
+ source: 'preview',
52
+ previewToken: 'the-workspace-preview-token',
53
+ })
54
+ ```
55
+
56
+ Three places can give the token. Tooling reads the first of them that has one: the
57
+ `PICKED_PREVIEW_TOKEN` environment variable, then the workspace that
58
+ [`picked workspace use`](/reference/tools/cli) chose, then this `previewToken` option.
59
+
60
+ ### 2. Enable the Vite plugin (recommended)
61
+
62
+ If you use Vite, add `@picked/vite-plugin-picked`. Type generation runs automatically on `dev` and `build` when `generateTypes` is enabled (the default):
63
+
64
+ ```typescript
65
+ import { picked } from '@picked/vite-plugin-picked'
66
+
67
+ export default defineConfig({
68
+ plugins: [picked()],
69
+ })
70
+ ```
71
+
72
+ The project id comes from `picked.config.ts`. A failure stops the
73
+ run. See [the plugin reference](/reference/tools/vite-plugin) for `generateTypes` and every
74
+ other option.
75
+
76
+ ### 3. Or use the CLI
77
+
78
+ Install [`picked`](/reference/tools/cli) and run:
79
+
80
+ ```bash
81
+ picked generate types
82
+ ```
83
+
84
+ ## Keep the types current
85
+
86
+ Commit `picked-env.d.ts`. A workspace changes after you commit it, so the file goes stale,
87
+ and stale types describe fields your workspace no longer has.
88
+
89
+ Run this check in CI, next to your other checks:
90
+
91
+ ```bash
92
+ picked generate types --check
93
+ ```
94
+
95
+ `--check` writes no file. It reads the live workspace schema and compares it with the
96
+ committed file. A match gives status `0`. A difference gives status `1` and names the file:
97
+
98
+ ```
99
+ Types are out of date: /home/runner/work/your-app/src/picked-env.d.ts
100
+ ```
101
+
102
+ To clear it, run `picked generate types` and commit the result. The check reads no cached
103
+ schema, so an API it cannot reach fails the check.
104
+
105
+ :::note
106
+ `--check` reads the workspace that the resolved configuration names. A CI run that has no
107
+ `.picked/settings.json` reads the workspace your committed `picked.config.ts` names.
108
+ :::
109
+
110
+ ## Workspace selection
111
+
112
+ Tooling reads `projectId` and `source` from your committed `picked.config.ts`. The Picked [CLI](/reference/tools/cli) points that tooling at a different project or a draft workspace, and leaves the file as it is. It writes the selection to `.picked/settings.json`, which is per-developer and which Git ignores. That selection supersedes the committed default.
113
+
114
+ See [How to switch workspaces](/how-to/switch-workspaces) for the full set of steps.
115
+
116
+ ## Generated output
117
+
118
+ The generated `picked-env.d.ts` file looks like:
119
+
120
+ ```typescript
121
+ // GENERATED by `@picked/typegen` — do not edit by hand.
122
+ // source: published `x-picked-version-id`: `ver_456`
123
+ // Reference: `https://docs.picked.app/reference/sdk/type-generation`
124
+
125
+ export interface WelcomePage { /* ... */ }
126
+ export interface FieldValues { /* ... */ }
127
+ export type FeatureKey = 'default' | 'winter-sale'
128
+
129
+ declare module '@picked/client' {
130
+ interface PickedSchemaRegistry {
131
+ contentModels: { 'welcome-page': WelcomePage }
132
+ stepContentModels: { intro: 'welcome-page' }
133
+ fieldValues: FieldValues
134
+ featureKeys: FeatureKey
135
+ }
136
+ }
137
+ ```
138
+
139
+ Commit this file to the version control system, or regenerate it in CI after you publish a workspace change.
140
+
141
+ ## Keys the application defines
142
+
143
+ An application can define a feature, an action, a field, a step, or an experience of its
144
+ own. It does this through `createClient` options or through a `register` method. The
145
+ workspace has no record of such a key, so the generated types have none either.
146
+
147
+ A hook still accepts one. Each key type holds the keys of the workspace and any other
148
+ string. Your editor shows the workspace keys, and no local key is an error:
149
+
150
+ ```typescript
151
+ useFeature('winter-sale') // from the workspace, and suggested
152
+ useFeature('summer-sales-experiment') // from createClient, and accepted
153
+ ```
154
+
155
+ Each key type has a `Known` form that holds the workspace keys alone —
156
+ `KnownFeatureKeys`, `KnownActionKeys`, `KnownFieldKeys`, `KnownStepKeys`, and
157
+ `KnownExperienceKeys`. Use one where you want the workspace set and nothing else.
158
+
159
+ ## Cache
160
+
161
+ Type generation writes its artefacts under `.picked/`: the schema JSON and a manifest. The first run adds this directory to `.gitignore` for you.
162
+
163
+ ## Related
164
+
165
+ - [CLI](/reference/tools/cli) — commands, authentication, and environment variables.
166
+ - [How to switch workspaces](/how-to/switch-workspaces) — read a draft workspace on your machine.
167
+ - [Vite plugin](/reference/tools/vite-plugin) — the build-time prefetch and the dev launcher.
168
+ - [Workspace schema](/reference/delivery-api/workspace-schema) — the schema endpoint.
169
+ - [Delivery API](/reference/delivery-api) — the published surface and the preview surface.
@@ -0,0 +1,146 @@
1
+ ---
2
+ type: reference
3
+ layout: docs
4
+ ---
5
+
6
+ # CLI
7
+
8
+ `picked` is the command-line tool for local Picked development. It generates TypeScript
9
+ types from your workspace schema and lets you switch which project or workspace your local
10
+ tooling loads — without hand-editing `picked.config.ts`.
11
+
12
+ ## Installation
13
+
14
+ The [`picked`](/reference/sdk) package holds this command, the client, and the
15
+ `picked.config` helpers:
16
+
17
+ ```bash
18
+ npm install picked
19
+ ```
20
+
21
+ The command reads `picked.config.ts` from the current directory, so run it from your
22
+ project root. See [How to authenticate the CLI](/how-to/authenticate-the-cli) to sign in.
23
+
24
+ `@picked/cli` holds the command on its own, for a project that wants no other part of the
25
+ package.
26
+
27
+ ## Commands
28
+
29
+ | Command | Description |
30
+ | --- | --- |
31
+ | `picked login` | Sign in with your browser (OAuth) to the API origin of the current directory. Stores a session under `~/.picked/auth/`. |
32
+ | `picked logout` | Clear the stored session for the current directory's API origin. |
33
+ | `picked whoami` | Print the identity signed in to the API origin of the current directory. |
34
+ | `picked status` | Print the resolved selection and the committed `picked.config` default. |
35
+ | `picked workspace list` | List each org, project, and workspace that you can read. Alias `ls`. `--json` gives machine output. |
36
+ | `picked workspace use` | Set the active project or workspace. Alias `picked use`. Interactive, or `--project` and `--workspace`. |
37
+ | `picked generate types` | Read the workspace schema and write `picked-env.d.ts`. `--check` verifies and writes nothing. |
38
+
39
+ ### `picked generate types`
40
+
41
+ Writes the typed schema declaration. See [Type generation](/reference/sdk/type-generation)
42
+ for the `picked.config.ts` reference and the generated output.
43
+
44
+ ```bash
45
+ picked generate types
46
+ ```
47
+
48
+ In CI, `--check` writes nothing and fails when the committed types are stale:
49
+
50
+ ```bash
51
+ picked generate types --check
52
+ # → "Types are up to date (`…/src/picked-env.d.ts`)." (status 0)
53
+ # → "Types are out of date: `…/src/picked-env.d.ts`" (status 1)
54
+ ```
55
+
56
+ ### `picked workspace list`
57
+
58
+ ```bash
59
+ picked workspace list
60
+ ```
61
+
62
+ ```
63
+ Acme Corp. (acme-corporation)
64
+ Storefront [proj_a1b2]
65
+ Default Storefront [LIVE] (live)
66
+ Checkout rework [DRAFT]
67
+ ```
68
+
69
+ `--json` gives a machine-readable tree. Each prompt and heading goes to `stderr`, so the
70
+ `stdout` of `--json` stays clean when you send it to another command.
71
+
72
+ ### `picked workspace use`
73
+
74
+ Sets the active selection, then regenerates types. See
75
+ [How to switch workspaces](/how-to/switch-workspaces) for the full set of steps.
76
+
77
+ ```bash
78
+ picked workspace use # interactive picker
79
+ picked workspace use --project proj_a1b2 # the project's published (live) version
80
+ picked workspace use --project proj_a1b2 --workspace ws_id # preview a specific workspace via its token
81
+ ```
82
+
83
+ ```
84
+ Active workspace: Checkout rework [DRAFT] in project proj_a1b2 (source: preview)
85
+ Generated types at /app/src/picked-env.d.ts
86
+ ```
87
+
88
+ `--no-generate` sets the selection and leaves the types as they are.
89
+
90
+ :::warning
91
+ `picked workspace use` regenerates types by default. Types that no longer match the
92
+ workspace give no error, and a developer can fail to see the problem for a long time. Use
93
+ `--no-generate` only when you regenerate the types yourself.
94
+ :::
95
+
96
+ ## Authentication
97
+
98
+ `picked login` signs in through the browser. It uses an authorization-code flow with PKCE
99
+ against the Picked OAuth server. `picked whoami` prints the identity for the current origin.
100
+ `picked logout` clears it.
101
+
102
+ The CLI holds one auth config file for each API origin, outside each repository. Every
103
+ command reads and writes only the origin that the current directory resolves to, and never
104
+ a session for another API.
105
+
106
+ | File | Contents |
107
+ | --- | --- |
108
+ | `~/.picked/auth/<origin>.json` | The OAuth session for one API origin — access token, refresh token, expiry — with the CLI's registered client id for that origin. File mode `600`. Refreshed as it nears expiry. |
109
+
110
+ An API deployment with no OAuth client registration rejects `picked login`, and has no
111
+ other flow.
112
+
113
+ A CLI session is a developer credential. It is not an
114
+ [API key](/reference/dashboard/api-keys), which authenticates server-to-server calls, and
115
+ not [dashboard sign-in](/reference/management-api/authentication).
116
+
117
+ ## Environment variables
118
+
119
+ | Variable | Effect |
120
+ | --- | --- |
121
+ | `PICKED_API_URL` | The API origin that the CLI reads. Supersedes `picked.config` `apiUrl` and the `https://api.picked.app` default. |
122
+ | `PICKED_PROJECT_ID` | Supersedes the resolved project id, above the active selection and the committed configuration. |
123
+ | `PICKED_PREVIEW_TOKEN` | Supersedes the preview token. Applies only when the resolved source is `preview`. |
124
+
125
+ ### How the selection resolves
126
+
127
+ Tooling — `picked generate types` and the
128
+ [Vite plugin](/reference/tools/vite-plugin) — resolves the configuration in this order. Each
129
+ layer supersedes the layer before it:
130
+
131
+ 1. **`picked.config.ts`** — the committed default: `projectId`, `source`, and
132
+ `previewToken`.
133
+ 2. **`.picked/settings.json`** — the per-developer active selection that
134
+ `picked workspace use` writes. It supersedes `projectId` and `source`, and Git ignores it.
135
+ 3. **Environment variables** — `PICKED_PROJECT_ID` and `PICKED_PREVIEW_TOKEN` supersede
136
+ both, for a CI or headless run.
137
+
138
+ `picked status` prints the resolved result.
139
+
140
+ ## Related
141
+
142
+ - [How to authenticate the CLI](/how-to/authenticate-the-cli) — install and sign in.
143
+ - [How to switch workspaces](/how-to/switch-workspaces) — the draft-preview workflow.
144
+ - [Type generation](/reference/sdk/type-generation) — `picked.config.ts` and the generated types.
145
+ - [Vite plugin](/reference/tools/vite-plugin) — reads the same selection in development and in a build.
146
+ - [Preview, cache, and crawlers](/reference/delivery-api/preview-caching-crawling) — how a preview token behaves.
@@ -106,12 +106,34 @@ After the dev server starts, the launcher URL appears next to the Vite output:
106
106
 
107
107
  ## Options
108
108
 
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. |
109
+ Project identity belongs in [`picked.config.ts`](/reference/sdk/type-generation). The two
110
+ options that carry it are deprecated, and the table marks them.
111
+
112
+ | Option | Type | Default | Description |
113
+ | ---------------- | --------------------- | ------------------------ | ---------------------------------------------------------- |
114
+ | `disableLauncher`| `boolean` | `false` | Turns the launcher page off in both dev and build output. |
115
+ | `generateTypes` | `boolean` | `true` | Whether the plugin writes types from the workspace schema. |
116
+ | `mode` | `'bundle' \| 'api'` | `'bundle'` | Whether the build carries your project data. |
117
+ | `projectId` | `string` | — | **Deprecated.** Use `picked.config.ts`. |
118
+ | `apiUrl` | `string` | — | **Deprecated.** Use `picked.config.ts`. |
119
+
120
+ ### projectId and apiUrl
121
+
122
+ These two options moved to [`picked.config.ts`](/reference/sdk/type-generation), which the
123
+ `picked` command and type generation also read. A later release removes them.
124
+
125
+ The plugin still reads an option for a field that `picked.config.ts` leaves out, so a
126
+ project that has yet to move needs no change. It stops when the two values are different,
127
+ rather than choose one for you.
128
+
129
+ ### generateTypes
130
+
131
+ The plugin reads the workspace schema and writes `picked-env.d.ts`, on `vite dev` and on
132
+ `vite build`. [Type generation](/reference/sdk/type-generation) describes the output and
133
+ the `picked.config.ts` options that control it.
134
+
135
+ A failure stops the run. Set `generateTypes: false` for a build that must not write types,
136
+ such as a build for one more entry point.
115
137
 
116
138
  ### mode
117
139
 
@@ -102,11 +102,11 @@ Install the client and the adapter for your framework.
102
102
  :::code-group
103
103
 
104
104
  ```bash [React]
105
- npm install @picked/client @picked/react effector effector-react
105
+ npm install picked @picked/react
106
106
  ```
107
107
 
108
108
  ```bash [Svelte]
109
- npm install @picked/client @picked/svelte effector
109
+ npm install picked @picked/svelte
110
110
  ```
111
111
 
112
112
  :::
@@ -118,12 +118,11 @@ puts each one in a form.
118
118
  :::code-group
119
119
 
120
120
  ```tsx [React]
121
- import { useStep } from '@picked/react/hooks'
122
- import { useUnit } from 'effector-react'
121
+ import { useStep, useStoreGlobal } from '@picked/react/hooks'
123
122
 
124
123
  export function ColorSurvey() {
125
124
  const { fields, form } = useStep()
126
- const currentFields = useUnit(fields)
125
+ const currentFields = useStoreGlobal(fields)
127
126
 
128
127
  return (
129
128
  <form {...form.props}>
@@ -177,7 +176,7 @@ match the component name that you entered in step 4.
177
176
  :::code-group
178
177
 
179
178
  ```tsx [React]
180
- import { createClient } from '@picked/client'
179
+ import { createClient } from 'picked'
181
180
  import { dynamicExperiencesPlugin } from '@picked/client/plugins/dynamic-experiences'
182
181
  import { adaptReactComponent } from '@picked/react'
183
182
  import { reactFrameworkPlugin } from '@picked/react/plugins/framework'
@@ -195,7 +194,7 @@ picked.start()
195
194
  ```
196
195
 
197
196
  ```ts [Svelte]
198
- import { createClient } from '@picked/client'
197
+ import { createClient } from 'picked'
199
198
  import { dynamicExperiencesPlugin } from '@picked/client/plugins/dynamic-experiences'
200
199
  import { adaptSvelteComponent } from '@picked/svelte'
201
200
  import { svelteFrameworkPlugin } from '@picked/svelte/plugins/framework'
@@ -76,7 +76,7 @@ a snapshot as plain JSON.
76
76
  Make one client for each request, in `server.ts`:
77
77
 
78
78
  ```ts
79
- import { createClient } from '@picked/client'
79
+ import { createClient } from 'picked'
80
80
  import { serialize } from '@picked/client/server'
81
81
 
82
82
  const client = createClient(options)
@@ -107,7 +107,7 @@ Register the component under the same name that the page uses. Here it is `CMSPa
107
107
  :::code-group
108
108
 
109
109
  ```tsx [React]
110
- import type { CreateClientOptions } from '@picked/client'
110
+ import type { CreateClientOptions } from 'picked'
111
111
  import { dynamicExperiencesPlugin } from '@picked/client/plugins/dynamic-experiences'
112
112
  import { adaptReactComponent, ExperienceSlot, PickedProvider } from '@picked/react'
113
113
  import { reactFrameworkPlugin } from '@picked/react/plugins/framework'
@@ -136,7 +136,7 @@ export function Page({ snapshot }) {
136
136
 
137
137
  ```svelte [Svelte]
138
138
  <script lang="ts">
139
- import type { CreateClientOptions } from '@picked/client'
139
+ import type { CreateClientOptions } from 'picked'
140
140
  import { dynamicExperiencesPlugin } from '@picked/client/plugins/dynamic-experiences'
141
141
  import { adaptSvelteComponent, ExperienceSlot, setPickedContext } from '@picked/svelte'
142
142
  import { svelteFrameworkPlugin } from '@picked/svelte/plugins/framework'
package/dist/esm/index.js CHANGED
@@ -5,11 +5,12 @@ 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 ee, s as y, t as b } from "../dom-BqcToNL0.js";
6
6
  import { l as x, n as S, r as C, u as w } from "../experience-instance-DGk11d8a.js";
7
7
  import { i as T, n as E, r as D, t as O } from "../storage-1MW3-_As.js";
8
- import { n as te, r as ne } from "../api-BlxGTa53.js";
9
- import { t as re } from "../id-Bo4RBeOs.js";
10
- import { n as ie, r as ae, t as oe } from "../inert-script-report-B_bMPRzp.js";
11
- import { attach as k, combine as A, createApi as j, createDomain as M, createEffect as N, createEvent as P, createStore as F, is as se, sample as I } from "effector";
8
+ import { t as te } from "../id-Bo4RBeOs.js";
9
+ import { t as ne } from "../version-BJFZwX5G.js";
10
+ import { n as re, r as ie, t as ae } from "../inert-script-report-B_bMPRzp.js";
11
+ import { attach as k, combine as A, createApi as j, createDomain as M, createEffect as N, createEvent as P, createStore as F, is as oe, sample as I } from "effector";
12
12
  import { createFactory as L, invoke as R } from "@withease/factories";
13
+ import { sendPing as se } from "@picked/delivery-api-client";
13
14
  //#region src/entities/experience/experience.ts
14
15
  var z = M("experience"), ce = L(({ client: e, experience: r }) => {
15
16
  let i = z.store(r), a = j(i, { merge(e, t) {
@@ -572,13 +573,13 @@ var Fe = 6e3, Ie = O("last_ping", "global"), Le = async (e) => {
572
573
  try {
573
574
  let t = Date.now(), n = E.get(Ie), r = 0;
574
575
  if (n.isSet() && (r = n.json() ?? 0), r && t - r < Fe) return !0;
575
- let i = {
576
+ let i = {}, a = document.getElementById("picked_script")?.dataset.verceltoken;
577
+ a && (i["x-vercel-protection-bypass"] = a);
578
+ let o = await se(e.apiUrl, {
576
579
  projectId: e.projectId,
577
580
  path: window.location.pathname
578
- }, a = {}, o = document.getElementById("picked_script")?.dataset.verceltoken;
579
- o && (a["x-vercel-protection-bypass"] = o);
580
- let s = (await te(e.apiUrl, "ping", i, a)).ok;
581
- return s && n.set(t), s;
581
+ }, { headers: i });
582
+ return o && n.set(t), o;
582
583
  } catch {
583
584
  return !1;
584
585
  }
@@ -1041,7 +1042,7 @@ var Je = (e, t, n) => {
1041
1042
  }, J = M("history");
1042
1043
  function Ye(e, t) {
1043
1044
  return {
1044
- id: re(`history-entry-${Date.now()}-${Math.random()}}`),
1045
+ id: te(`history-entry-${Date.now()}-${Math.random()}}`),
1045
1046
  node: t,
1046
1047
  at: Date.now(),
1047
1048
  experienceId: e
@@ -1773,7 +1774,7 @@ var Kt = class {
1773
1774
  dataProviderFor(e) {
1774
1775
  let t = e ?? "", n = this.dataProviders.get(t);
1775
1776
  if (n) return n;
1776
- let r = import("../provider-fU4mqyvT.js").then((t) => t.createPickedDataProvider({
1777
+ let r = import("../provider-HpWMlxa0.js").then((t) => t.createPickedDataProvider({
1777
1778
  apiUrl: this.apiUrl,
1778
1779
  projectId: this.projectId,
1779
1780
  ...e !== void 0 && { previewToken: e }
@@ -1983,12 +1984,12 @@ function rn(e, t) {
1983
1984
  return n;
1984
1985
  }
1985
1986
  function an(e, t) {
1986
- if (se.store(t)) return A(t, e.indexStore, (e, t) => nn(t, $(e)));
1987
+ if (oe.store(t)) return A(t, e.indexStore, (e, t) => nn(t, $(e)));
1987
1988
  let n = $(t);
1988
1989
  return e.indexStore.map((e) => nn(e, n), { skipVoid: !1 });
1989
1990
  }
1990
1991
  function on(e, t) {
1991
- if (se.store(t)) return A(t, e.indexStore, (e, t) => rn(t, tn(e)));
1992
+ if (oe.store(t)) return A(t, e.indexStore, (e, t) => rn(t, tn(e)));
1992
1993
  let n = tn(t);
1993
1994
  return e.indexStore.map((e) => rn(e, n), { skipVoid: !1 });
1994
1995
  }
@@ -1999,4 +2000,12 @@ var sn = (e) => {
1999
2000
  return u(t), t;
2000
2001
  };
2001
2002
  //#endregion
2002
- export { Yt as PICKED_HYDRATED_ATTR, Jt as PICKED_MODULE_SCRIPT_TYPE, qt as PICKED_SCRIPT_TYPE, Wt as PREVIEW_TOKEN_PARAM, Kt as Picked, Zt as buildRehydrateBootstrap, sn as createClient, pe as createPluginEffect, O as createStorageKey, an as deriveReference, on as deriveReferences, n as evaluateRuleLogic, Ft as getPickedConfig, Q as isContentReference, Qt as isHtmlAssetValue, h as isInsideIframe, en as isLazyLoader, _ as isPickedRoot, Gt as isPreviewSession, $t as lazyComponent, E as localStore, oe as onInertScriptSubtrees, $ as readReferenceId, tn as readReferenceIds, Xt as rehydrateScripts, ie as reportInertScriptSubtrees, ae as resetInertScriptReport, D as sessionStore, T as subscribe, d as supportsCookies, p as supportsCryptoRandomUUID, c as supportsDocument, i as supportsHistory, f as supportsIntersectionObserver, m as supportsLocalStorage, a as supportsLocation, l as supportsSessionStorage, g as supportsShadowRoot, o as supportsWebComponents, s as supportsWindow };
2003
+ //#region src/typed-content.ts
2004
+ function cn(e) {
2005
+ return typeof e.data == "object";
2006
+ }
2007
+ function ln(e) {
2008
+ return e.map((e) => !e || !cn(e) ? null : e, { skipVoid: !1 });
2009
+ }
2010
+ //#endregion
2011
+ export { Yt as PICKED_HYDRATED_ATTR, Jt as PICKED_MODULE_SCRIPT_TYPE, qt as PICKED_SCRIPT_TYPE, Wt as PREVIEW_TOKEN_PARAM, Kt as Picked, Zt as buildRehydrateBootstrap, sn as createClient, pe as createPluginEffect, O as createStorageKey, an as deriveReference, on as deriveReferences, n as evaluateRuleLogic, Ft as getPickedConfig, Q as isContentReference, Qt as isHtmlAssetValue, h as isInsideIframe, en as isLazyLoader, _ as isPickedRoot, Gt as isPreviewSession, $t as lazyComponent, E as localStore, ae as onInertScriptSubtrees, $ as readReferenceId, tn as readReferenceIds, Xt as rehydrateScripts, re as reportInertScriptSubtrees, ie as resetInertScriptReport, D as sessionStore, T as subscribe, d as supportsCookies, p as supportsCryptoRandomUUID, c as supportsDocument, i as supportsHistory, f as supportsIntersectionObserver, m as supportsLocalStorage, a as supportsLocation, l as supportsSessionStorage, g as supportsShadowRoot, o as supportsWebComponents, s as supportsWindow, ln as toTypedContentStore };
@@ -1,4 +1,5 @@
1
- import { i as e } from "../../../api-BlxGTa53.js";
2
- import { t } from "../../../plugin-DviILBha.js";
3
- import { a as n, i as r, n as i } from "../../../registry-ZEiRsEkm.js";
4
- export { e as createClientHeaders, t as dynamicExperiencesPlugin, r as fetchExperienceContent, n as fetchProject, i as registerPickedBundle };
1
+ import { t as e } from "../../../plugin-B-c2VAl2.js";
2
+ import { n as t, t as n } from "../../../api-DGFHHioX.js";
3
+ import { n as r } from "../../../registry-CXZv0uLg.js";
4
+ import { createClientHeaders as i, fetchSchema as a } from "@picked/delivery-api-client";
5
+ export { i as createClientHeaders, e as dynamicExperiencesPlugin, n as fetchExperienceContent, t as fetchProject, a as fetchSchema, r as registerPickedBundle };
@@ -1,5 +1,5 @@
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 { n as s } from "../../plugin-DviILBha.js";
2
+ import { n as s } from "../../plugin-B-c2VAl2.js";
3
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
5
  var p = 1e4;
@@ -1,4 +1,5 @@
1
1
  import "./logger-DMN6TxJJ.js";
2
+ import "./api-DGFHHioX.js";
2
3
  import { attach as e } from "effector";
3
4
  //#region src/plugins/dynamic-experiences/hash.ts
4
5
  function t(e) {
@@ -34,10 +35,13 @@ function o(e, t) {
34
35
  componentName: t.componentName
35
36
  });
36
37
  }
37
- function s(e, t) {
38
- if (Array.isArray(t.fields)) for (let n of t.fields) e.registerField(n);
38
+ function s(e) {
39
+ return typeof e != "object" || !e ? !1 : "id" in e && "key" in e && "type" in e && "name" in e;
39
40
  }
40
41
  function c(e, t) {
42
+ if (Array.isArray(t.fields)) for (let n of t.fields) s(n) && e.registerField(n);
43
+ }
44
+ function l(e, t) {
41
45
  if (!Array.isArray(t.steps)) return;
42
46
  let n = new Map(t.fields.map((e) => [e.id, e.key]));
43
47
  for (let r of t.steps) {
@@ -64,17 +68,17 @@ function c(e, t) {
64
68
  });
65
69
  }
66
70
  }
67
- function l(e, t) {
71
+ function u(e, t) {
68
72
  if (Array.isArray(t.experiences)) for (let n of t.experiences) o(e, n);
69
73
  }
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);
74
+ function d(e, t, n) {
75
+ m(e, t, n.isPreview, n.sessionId), a(e, t), c(e, t), l(e, t), u(e, t);
72
76
  }
73
- function d(e) {
77
+ function f(e) {
74
78
  let t = e.searchParams["preview-token"];
75
79
  if (t && t.length > 0) return t[0];
76
80
  }
77
- function f(e) {
81
+ function p(e) {
78
82
  let t = /* @__PURE__ */ new Set(), n = e.searchParams.feature;
79
83
  if (!n) return t;
80
84
  for (let e of n) {
@@ -83,11 +87,11 @@ function f(e) {
83
87
  }
84
88
  return t;
85
89
  }
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);
90
+ function m(e, t, n, r) {
91
+ let i = p(e);
92
+ for (let a of t.features) i.has(a.id) || h(e, a, n, r);
89
93
  }
90
- function m(e, t, n, a) {
94
+ function h(e, t, n, a) {
91
95
  let o = r(a, t.id);
92
96
  e.registerFeature(t.id, {
93
97
  key: `v${t.version}`,
@@ -98,14 +102,14 @@ function m(e, t, n, a) {
98
102
  decide: () => i(o, t.weight)
99
103
  });
100
104
  }
101
- function h(e, t) {
105
+ function g(e, t) {
102
106
  for (let n of [...t.references ?? [], ...t.content]) e.registerContent({
103
107
  id: n.id,
104
108
  contentModelKey: n.contentModelKey,
105
109
  data: n.data
106
110
  });
107
111
  }
108
- function g(e, t) {
112
+ function _(e, t) {
109
113
  let n = /* @__PURE__ */ new Map();
110
114
  return (r, i) => {
111
115
  let a = n.get(r.id);
@@ -113,7 +117,7 @@ function g(e, t) {
113
117
  let o = (async () => {
114
118
  try {
115
119
  let n = await t(r, i);
116
- return n && h(e, n), n;
120
+ return n && g(e, n), n;
117
121
  } finally {
118
122
  n.delete(r.id);
119
123
  }
@@ -121,18 +125,18 @@ function g(e, t) {
121
125
  return n.set(r.id, o), o;
122
126
  };
123
127
  }
124
- function _(e, t) {
128
+ function v(e, t) {
125
129
  let n = new Set(t && Array.isArray(t.experiences) ? t.experiences.map((e) => e.id) : []);
126
130
  return (t, r) => n.has(t.id) ? e(t, r) : Promise.resolve(null);
127
131
  }
128
- function v() {
132
+ function y() {
129
133
  return {
130
134
  name: "dynamic-experiences",
131
135
  setup: (t) => ({ onStart: e({
132
136
  source: t.session.store.map((e) => e.id),
133
137
  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;
138
+ let n = f(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);
139
+ if (t.contentLoader = _(t, v((e) => t.getExperienceContent(e, i), a)), !a) return;
136
140
  let o = t.seededVersionId;
137
141
  if (o !== null && o !== a.versionId) {
138
142
  t.versionSkew = {
@@ -141,7 +145,7 @@ function v() {
141
145
  }, `${a.versionId}${o}`;
142
146
  return;
143
147
  }
144
- t.previewEmbedderOrigins = a.previewEmbedderOrigins ?? null, u(t, a, {
148
+ t.previewEmbedderOrigins = a.previewEmbedderOrigins ?? null, d(t, a, {
145
149
  isPreview: r,
146
150
  sessionId: e
147
151
  });
@@ -150,4 +154,4 @@ function v() {
150
154
  };
151
155
  }
152
156
  //#endregion
153
- export { u as n, v as t };
157
+ export { d as n, y as t };
@@ -0,0 +1 @@
1
+ require("./logger-CSTvAyyB.cjs"),require("./api-DrR9JbZX.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){return typeof e!=`object`||!e?!1:`id`in e&&`key`in e&&`type`in e&&`name`in e}function c(e,t){if(Array.isArray(t.fields))for(let n of t.fields)s(n)&&e.registerField(n)}function l(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 u(e,t){if(Array.isArray(t.experiences))for(let n of t.experiences)o(e,n)}function d(e,t,n){m(e,t,n.isPreview,n.sessionId),a(e,t),c(e,t),l(e,t),u(e,t)}function f(e){let t=e.searchParams[`preview-token`];if(t&&t.length>0)return t[0]}function p(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 m(e,t,n,r){let i=p(e);for(let a of t.features)i.has(a.id)||h(e,a,n,r)}function h(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 g(e,t){for(let n of[...t.references??[],...t.content])e.registerContent({id:n.id,contentModelKey:n.contentModelKey,data:n.data})}function _(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&&g(e,n),n}finally{n.delete(r.id)}})();return n.set(r.id,o),o}}function v(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 y(){return{name:`dynamic-experiences`,setup:t=>({onStart:(0,e.attach)({source:t.session.store.map(e=>e.id),effect:async e=>{let n=f(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=_(t,v(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,d(t,a,{isPreview:r,sessionId:e})}})})}}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return y}});