@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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/api-DGFHHioX.js +22 -0
- package/dist/api-DrR9JbZX.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/how-to/authenticate-the-cli.md +97 -0
- package/dist/docs/how-to/create-and-revoke-an-api-key.md +7 -2
- package/dist/docs/how-to/debug-with-the-chrome-extension.md +1 -1
- package/dist/docs/how-to/install-the-sdk.md +31 -6
- package/dist/docs/how-to/install-the-vite-plugin.md +22 -9
- package/dist/docs/how-to/read-a-feature-flag.md +1 -1
- package/dist/docs/how-to/read-a-referenced-entry.md +4 -6
- package/dist/docs/how-to/register-a-component.md +2 -2
- package/dist/docs/how-to/register-an-action-handler.md +1 -1
- package/dist/docs/how-to/render-a-step-form.md +3 -4
- package/dist/docs/how-to/server-render-a-page.md +1 -1
- package/dist/docs/how-to/switch-workspaces.md +122 -0
- package/dist/docs/how-to/write-a-predicate.md +1 -1
- package/dist/docs/reference/dashboard/api-keys.mdx +5 -4
- package/dist/docs/reference/delivery-api/workspace-schema.md +74 -0
- package/dist/docs/reference/sdk/content.md +7 -10
- package/dist/docs/reference/sdk/features.md +1 -1
- package/dist/docs/reference/sdk/plugins/dynamic-experiences.md +1 -1
- package/dist/docs/reference/sdk/plugins/window-object.md +1 -1
- package/dist/docs/reference/sdk/ssr/serialize.md +1 -1
- package/dist/docs/reference/sdk/steps.md +3 -4
- package/dist/docs/reference/sdk/type-generation.md +169 -0
- package/dist/docs/reference/tools/cli.md +146 -0
- package/dist/docs/reference/tools/vite-plugin.md +28 -6
- package/dist/docs/tutorials/first-experience.mdx +6 -7
- package/dist/docs/tutorials/first-server-rendered-page.mdx +3 -3
- package/dist/esm/index.js +23 -14
- package/dist/esm/plugins/dynamic-experiences/index.js +5 -4
- package/dist/esm/server/index.js +1 -1
- package/dist/{plugin-DviILBha.js → plugin-B-c2VAl2.js} +24 -20
- package/dist/plugin-B8YrVbNq.cjs +1 -0
- package/dist/{provider-fU4mqyvT.js → provider-HpWMlxa0.js} +2 -1
- package/dist/provider-hQPGEy73.cjs +1 -0
- package/dist/registry-C1t8l3t9.cjs +1 -0
- package/dist/registry-CXZv0uLg.js +18 -0
- package/dist/types/data-source/api.d.ts +1 -1
- package/dist/types/data-source/api.d.ts.map +1 -1
- package/dist/types/data-source/provider.d.ts +11 -1
- package/dist/types/data-source/provider.d.ts.map +1 -1
- package/dist/types/entities/response/response.d.ts +22 -6
- package/dist/types/entities/response/response.d.ts.map +1 -1
- package/dist/types/form/create-submit-pipeline.d.ts +32 -3
- package/dist/types/form/create-submit-pipeline.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/picked.d.ts +5 -4
- package/dist/types/picked.d.ts.map +1 -1
- package/dist/types/ping.d.ts +4 -3
- package/dist/types/ping.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/index.d.ts +2 -1
- package/dist/types/plugins/dynamic-experiences/index.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts +1 -1
- package/dist/types/plugins/dynamic-experiences/plugin.d.ts.map +1 -1
- package/dist/types/plugins/dynamic-experiences/types.d.ts +6 -116
- package/dist/types/plugins/dynamic-experiences/types.d.ts.map +1 -1
- package/dist/types/schema-registry.d.ts +190 -0
- package/dist/types/schema-registry.d.ts.map +1 -0
- 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 +11 -1
- package/dist/types/server/serialize.d.ts.map +1 -1
- package/dist/types/typed-content.d.ts +17 -0
- package/dist/types/typed-content.d.ts.map +1 -0
- package/dist/types/utils/picked-config.d.ts +19 -1
- package/dist/types/utils/picked-config.d.ts.map +1 -1
- package/dist/version-BJFZwX5G.js +4 -0
- package/dist/version-DzA5_Ptz.cjs +1 -0
- package/package.json +3 -1
- package/dist/api-B6Ma2KAc.cjs +0 -1
- package/dist/api-BlxGTa53.js +0 -38
- package/dist/plugin-DkSWIASL.cjs +0 -1
- package/dist/provider-C8ONTzzL.cjs +0 -1
- package/dist/registry-BvoKbKKv.cjs +0 -1
- package/dist/registry-ZEiRsEkm.js +0 -74
- package/dist/types/utils/api.d.ts +0 -25
- package/dist/types/utils/api.d.ts.map +0 -1
- package/dist/types/utils/client-headers.d.ts +0 -2
- package/dist/types/utils/client-headers.d.ts.map +0 -1
|
@@ -13,21 +13,41 @@ ID from the dashboard.
|
|
|
13
13
|
:::code-group
|
|
14
14
|
|
|
15
15
|
```bash [React]
|
|
16
|
-
npm install
|
|
16
|
+
npm install picked @picked/react
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
```bash [Svelte]
|
|
20
|
-
npm install
|
|
20
|
+
npm install picked @picked/svelte
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
:::
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
`picked` gives you the client, the `picked.config` helpers, and the `picked` command. Your
|
|
26
|
+
package manager adds `@picked/client` with it, which carries the runtime and holds the
|
|
27
|
+
generated types.
|
|
28
|
+
|
|
29
|
+
## 2. Add `picked.config.ts`
|
|
30
|
+
|
|
31
|
+
Create this file in the root of your project. The `picked` command and the
|
|
32
|
+
[Vite plugin](/reference/tools/vite-plugin) read your project identity from it:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { defineConfig } from 'picked/config'
|
|
36
|
+
|
|
37
|
+
export default defineConfig({
|
|
38
|
+
projectId: 'your-project-id',
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
[Type generation](/reference/sdk/type-generation) reads this file, and gives your fields,
|
|
43
|
+
features and steps the types the workspace declares.
|
|
44
|
+
|
|
45
|
+
## 3. Create and start the client
|
|
26
46
|
|
|
27
47
|
:::code-group
|
|
28
48
|
|
|
29
49
|
```tsx [React]
|
|
30
|
-
import { createClient } from '
|
|
50
|
+
import { createClient } from 'picked'
|
|
31
51
|
import { dynamicExperiencesPlugin } from '@picked/client/plugins/dynamic-experiences'
|
|
32
52
|
import { reactFrameworkPlugin } from '@picked/react/plugins/framework'
|
|
33
53
|
|
|
@@ -40,7 +60,7 @@ picked.start()
|
|
|
40
60
|
```
|
|
41
61
|
|
|
42
62
|
```ts [Svelte]
|
|
43
|
-
import { createClient } from '
|
|
63
|
+
import { createClient } from 'picked'
|
|
44
64
|
import { dynamicExperiencesPlugin } from '@picked/client/plugins/dynamic-experiences'
|
|
45
65
|
import { svelteFrameworkPlugin } from '@picked/svelte/plugins/framework'
|
|
46
66
|
|
|
@@ -54,9 +74,13 @@ picked.start()
|
|
|
54
74
|
|
|
55
75
|
:::
|
|
56
76
|
|
|
77
|
+
`picked` carries the client's root entry. Each deeper import path, such as
|
|
78
|
+
`@picked/client/plugins/dynamic-experiences` and `@picked/client/server`, keeps its own
|
|
79
|
+
name.
|
|
80
|
+
|
|
57
81
|
`start()` is idempotent. A second call changes nothing on a client that started already.
|
|
58
82
|
|
|
59
|
-
##
|
|
83
|
+
## 4. Add the optional plugins
|
|
60
84
|
|
|
61
85
|
- `windowObjectPlugin()` puts the client on `window.Picked`, which helps when you debug.
|
|
62
86
|
- `singlePageAppPlugin()` starts the client again on a history event.
|
|
@@ -65,4 +89,5 @@ picked.start()
|
|
|
65
89
|
|
|
66
90
|
- [Add Picked to your application](/tutorials/first-experience) — the whole path.
|
|
67
91
|
- [SDK installation](/reference/sdk) — every client option.
|
|
92
|
+
- [Type generation](/reference/sdk/type-generation) — types from your workspace.
|
|
68
93
|
- [How to register a component](/how-to/register-a-component).
|
|
@@ -13,37 +13,49 @@ API request at runtime.
|
|
|
13
13
|
:::code-group
|
|
14
14
|
|
|
15
15
|
```bash [npm]
|
|
16
|
-
npm install @picked/vite-plugin-picked
|
|
16
|
+
npm install @picked/vite-plugin-picked picked
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
```bash [pnpm]
|
|
20
|
-
pnpm add @picked/vite-plugin-picked
|
|
20
|
+
pnpm add @picked/vite-plugin-picked picked
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
```bash [yarn]
|
|
24
|
-
yarn add @picked/vite-plugin-picked
|
|
24
|
+
yarn add @picked/vite-plugin-picked picked
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
:::
|
|
28
28
|
|
|
29
|
-
## 2.
|
|
29
|
+
## 2. Name your project
|
|
30
|
+
|
|
31
|
+
Create `picked.config.ts` in the root of your project. The plugin reads your project
|
|
32
|
+
identity from this file:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { defineConfig } from 'picked/config'
|
|
36
|
+
|
|
37
|
+
export default defineConfig({
|
|
38
|
+
projectId: 'your-project-id',
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 3. Add the plugin to your Vite config
|
|
30
43
|
|
|
31
44
|
```typescript
|
|
32
45
|
import { defineConfig } from 'vite'
|
|
33
46
|
import { picked } from '@picked/vite-plugin-picked'
|
|
34
47
|
|
|
35
48
|
export default defineConfig({
|
|
36
|
-
plugins: [
|
|
37
|
-
picked({
|
|
38
|
-
projectId: 'your-project-id',
|
|
39
|
-
}),
|
|
40
|
-
],
|
|
49
|
+
plugins: [picked()],
|
|
41
50
|
})
|
|
42
51
|
```
|
|
43
52
|
|
|
44
53
|
When Vite starts, the plugin reads your project configuration and embeds them in your bundle.
|
|
45
54
|
The SDK then reads the embedded configuration and makes no network request.
|
|
46
55
|
|
|
56
|
+
The plugin also writes `picked-env.d.ts`, which types your fields, features and steps
|
|
57
|
+
against the workspace. See [Type generation](/reference/sdk/type-generation).
|
|
58
|
+
|
|
47
59
|
:::note
|
|
48
60
|
When a preview token is there at runtime, the SDK ignores the embedded configuration and reads
|
|
49
61
|
fresh data from the API.
|
|
@@ -52,5 +64,6 @@ fresh data from the API.
|
|
|
52
64
|
## Related
|
|
53
65
|
|
|
54
66
|
- [Vite plugin](/reference/tools/vite-plugin) — every option.
|
|
67
|
+
- [Type generation](/reference/sdk/type-generation) — the `picked.config.ts` options.
|
|
55
68
|
- [About how Picked works](/explanation/how-picked-works) — where build-time configuration sit
|
|
56
69
|
in the startup order.
|
|
@@ -77,7 +77,7 @@ renders, and they commit the visitor to a bucket at that moment.
|
|
|
77
77
|
The event bus works with any framework, and with none:
|
|
78
78
|
|
|
79
79
|
```ts
|
|
80
|
-
import { createClient } from '
|
|
80
|
+
import { createClient } from 'picked'
|
|
81
81
|
|
|
82
82
|
const client = createClient({
|
|
83
83
|
/* Put your client options here. */
|
|
@@ -20,12 +20,11 @@ Pass the raw field value to `useReference()` in React, or to `getReference()` in
|
|
|
20
20
|
:::code-group
|
|
21
21
|
|
|
22
22
|
```tsx [React]
|
|
23
|
-
import {
|
|
24
|
-
import { useReference, useStepContent } from '@picked/react/hooks'
|
|
23
|
+
import { useReference, useStepContent, useStoreGlobal } from '@picked/react/hooks'
|
|
25
24
|
|
|
26
25
|
export function ProductCategory() {
|
|
27
26
|
const content = useStepContent()
|
|
28
|
-
const category =
|
|
27
|
+
const category = useStoreGlobal(useReference(content?.category))
|
|
29
28
|
|
|
30
29
|
if (!category) return null
|
|
31
30
|
|
|
@@ -58,12 +57,11 @@ Use `useReferences()` or `getReferences()`. They give a list in field order.
|
|
|
58
57
|
:::code-group
|
|
59
58
|
|
|
60
59
|
```tsx [React]
|
|
61
|
-
import {
|
|
62
|
-
import { useReferences, useStepContent } from '@picked/react/hooks'
|
|
60
|
+
import { useReferences, useStepContent, useStoreGlobal } from '@picked/react/hooks'
|
|
63
61
|
|
|
64
62
|
export function ProductCategories() {
|
|
65
63
|
const content = useStepContent()
|
|
66
|
-
const categories =
|
|
64
|
+
const categories = useStoreGlobal(useReferences(content?.categories))
|
|
67
65
|
|
|
68
66
|
return (
|
|
69
67
|
<ul>
|
|
@@ -17,7 +17,7 @@ the dashboard.
|
|
|
17
17
|
:::code-group
|
|
18
18
|
|
|
19
19
|
```tsx [React]
|
|
20
|
-
import { createClient } from '
|
|
20
|
+
import { createClient } from 'picked'
|
|
21
21
|
import { adaptReactComponent } from '@picked/react'
|
|
22
22
|
import { MyWidget } from './MyWidget'
|
|
23
23
|
|
|
@@ -30,7 +30,7 @@ const picked = createClient({
|
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
```ts [Svelte]
|
|
33
|
-
import { createClient } from '
|
|
33
|
+
import { createClient } from 'picked'
|
|
34
34
|
import { adaptSvelteComponent } from '@picked/svelte'
|
|
35
35
|
import MyWidget from './MyWidget.svelte'
|
|
36
36
|
|
|
@@ -15,7 +15,7 @@ Pass an `actions` object to `createClient()`. Each key must match an action key
|
|
|
15
15
|
dashboard:
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import { createClient } from '
|
|
18
|
+
import { createClient } from 'picked'
|
|
19
19
|
|
|
20
20
|
const picked = createClient({
|
|
21
21
|
projectId: 'your-project-id',
|
|
@@ -59,13 +59,12 @@ Bind `form.props` to your `<form>` element and map over the fields.
|
|
|
59
59
|
:::code-group
|
|
60
60
|
|
|
61
61
|
```tsx [React]
|
|
62
|
-
import { useStep } from '@picked/react/hooks'
|
|
63
|
-
import { useUnit } from 'effector-react'
|
|
62
|
+
import { useStep, useStoreGlobal } from '@picked/react/hooks'
|
|
64
63
|
|
|
65
64
|
function StepForm() {
|
|
66
65
|
const { fields, form } = useStep()
|
|
67
|
-
const currentFields =
|
|
68
|
-
const isSubmitting =
|
|
66
|
+
const currentFields = useStoreGlobal(fields)
|
|
67
|
+
const isSubmitting = useStoreGlobal(form.submitting)
|
|
69
68
|
|
|
70
69
|
return (
|
|
71
70
|
<form {...form.props}>
|
|
@@ -13,7 +13,7 @@ browser. You need a published Page and a server that renders React or Svelte.
|
|
|
13
13
|
Create one client for each request, then call `serialize()`:
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import { createClient } from '
|
|
16
|
+
import { createClient } from 'picked'
|
|
17
17
|
import { serialize } from '@picked/client/server'
|
|
18
18
|
|
|
19
19
|
const client = createClient(options)
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: how-to
|
|
3
|
+
layout: docs
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# How to switch workspaces
|
|
7
|
+
|
|
8
|
+
This guide shows you how to point your local tooling at a different project or workspace.
|
|
9
|
+
Your application then renders that workspace's content and types on your machine. It expects
|
|
10
|
+
a `picked.config.ts` and the [CLI](/reference/tools/cli).
|
|
11
|
+
|
|
12
|
+
Your tooling reads the project and surface named in the committed `picked.config.ts`. The
|
|
13
|
+
CLI writes your choice to `.picked/settings.json` instead. That file is per-developer and
|
|
14
|
+
Git ignores it, so the committed default stays as it is and one command puts it back.
|
|
15
|
+
|
|
16
|
+
See [Workspaces](/reference/dashboard/workspaces) for what Live, Draft, and Archived mean.
|
|
17
|
+
|
|
18
|
+
## 1. Sign in
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
picked login
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
This opens your browser for a one-time OAuth sign-in and stores a session under
|
|
25
|
+
`~/.picked/`. Confirm it with `picked whoami`. See
|
|
26
|
+
[CLI authentication](/how-to/authenticate-the-cli).
|
|
27
|
+
|
|
28
|
+
## 2. Find a workspace
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
picked workspace list
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
Acme Corp. (acme-corporation)
|
|
36
|
+
Storefront [proj_a1b2]
|
|
37
|
+
Default Storefront [LIVE] (live)
|
|
38
|
+
Checkout rework [DRAFT]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Note the **project id** (`proj_a1b2`) and the name or the id of the workspace you want.
|
|
42
|
+
|
|
43
|
+
## 3. Switch to the draft
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
picked workspace use --project proj_a1b2 --workspace ws_draft
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
Active workspace: Checkout rework [DRAFT] in project proj_a1b2 (source: preview)
|
|
51
|
+
Generated types at /app/src/picked-env.d.ts
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
A command that names **one specific workspace** (draft, live, or archived):
|
|
55
|
+
|
|
56
|
+
- writes the selection (and its [preview token](/reference/delivery-api/preview-caching-crawling)) to
|
|
57
|
+
`.picked/settings.json`,
|
|
58
|
+
- switches the resolved `source` to `preview` for that project, and
|
|
59
|
+
- regenerates `picked-env.d.ts` from that workspace's schema (skip with `--no-generate`).
|
|
60
|
+
|
|
61
|
+
To browse instead, run `picked workspace use` with no flags. The interactive picker lists
|
|
62
|
+
every project, with **Published (live version)** and each of its workspaces.
|
|
63
|
+
|
|
64
|
+
## 4. See the draft in your app
|
|
65
|
+
|
|
66
|
+
Both readers of the selection use `.picked/settings.json` with no change to your
|
|
67
|
+
configuration:
|
|
68
|
+
|
|
69
|
+
- **Type generation** now reads the draft schema. Rerun `picked generate types` after more
|
|
70
|
+
edits.
|
|
71
|
+
- The **[Vite plugin](/reference/tools/vite-plugin)** reads the draft's configuration and
|
|
72
|
+
content in development and in a build. It sends the preview token to the
|
|
73
|
+
[Delivery API](/reference/delivery-api). Restart the dev server to apply a switch.
|
|
74
|
+
|
|
75
|
+
Your application renders the unpublished draft on your machine, with types.
|
|
76
|
+
|
|
77
|
+
## 5. Switch back to live
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
picked workspace use --project proj_a1b2
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
A command that names a project with no `--workspace`, or **Published (live version)** in the
|
|
84
|
+
picker, discards the preview token and returns `source` to `published`. To confirm what is
|
|
85
|
+
active:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
picked status
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
Config default: project proj_a1b2 (source: published)
|
|
93
|
+
Active selection: none (using the config default).
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## CI and headless runs
|
|
97
|
+
|
|
98
|
+
`.picked/settings.json` is a local, per-developer file. Do not commit it. To choose one
|
|
99
|
+
workspace in CI with no selection file, set the environment directly:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
PICKED_PROJECT_ID=proj_a1b2 \
|
|
103
|
+
PICKED_PREVIEW_TOKEN="$DRAFT_TOKEN" \
|
|
104
|
+
picked generate types --check
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`PICKED_PREVIEW_TOKEN` applies only when the resolved `source` is `preview`. See the
|
|
108
|
+
[CLI environment variables](/reference/tools/cli#environment-variables) for the full
|
|
109
|
+
precedence order.
|
|
110
|
+
|
|
111
|
+
:::note
|
|
112
|
+
A preview token is a long-lived credential for one workspace. Keep it out of the version
|
|
113
|
+
control system, as you do with each other credential. Git ignores `.picked/settings.json`
|
|
114
|
+
for this reason, because `picked workspace use` writes a token there.
|
|
115
|
+
:::
|
|
116
|
+
|
|
117
|
+
## Related
|
|
118
|
+
|
|
119
|
+
- [CLI](/reference/tools/cli) — every command and flag.
|
|
120
|
+
- [Workspaces](/reference/dashboard/workspaces) — Live, Draft, and Archived states.
|
|
121
|
+
- [Type generation](/reference/sdk/type-generation) — how the schema becomes types.
|
|
122
|
+
- [Preview, cache, and crawlers](/reference/delivery-api/preview-caching-crawling) — preview tokens on the Delivery API.
|
|
@@ -13,7 +13,7 @@ such as a cart total or an account level.
|
|
|
13
13
|
Pass a `predicates` object to `createClient()`:
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import { createClient } from '
|
|
16
|
+
import { createClient } from 'picked'
|
|
17
17
|
|
|
18
18
|
const client = createClient({
|
|
19
19
|
projectId: 'your-project-id',
|
|
@@ -7,8 +7,9 @@ import { Screenshot } from '../../../../components/Screenshot'
|
|
|
7
7
|
|
|
8
8
|
# API keys
|
|
9
9
|
|
|
10
|
-
An API key lets your code reach the Picked API. Use one
|
|
11
|
-
|
|
10
|
+
An API key lets your code reach the Picked API. Use one where your own code calls the API,
|
|
11
|
+
such as a server-side integration. It does not sign the
|
|
12
|
+
[CLI](/reference/tools/cli) in.
|
|
12
13
|
|
|
13
14
|
<Screenshot
|
|
14
15
|
route="/{orgSlug}/api-keys"
|
|
@@ -17,11 +18,11 @@ or for a CI/CD workflow.
|
|
|
17
18
|
|
|
18
19
|
## Use an API key
|
|
19
20
|
|
|
20
|
-
Put your API key in the `
|
|
21
|
+
Put your API key in the `x-api-key` header of each request to the
|
|
21
22
|
[Picked API](/tutorials/first-api-call).
|
|
22
23
|
|
|
23
24
|
```
|
|
24
|
-
|
|
25
|
+
x-api-key: your-api-key
|
|
25
26
|
```
|
|
26
27
|
|
|
27
28
|
## Scopes
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: reference
|
|
3
|
+
layout: docs
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Workspace Schema Endpoint
|
|
7
|
+
|
|
8
|
+
A JSON Schema document for the structure of your project: content models, fields, feature keys, experience keys, and step keys. Tooling reads this endpoint to generate TypeScript types for your application.
|
|
9
|
+
|
|
10
|
+
## Request
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
GET /api/v1/projects/:projectId/schema
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
| Parameter | In | Description |
|
|
17
|
+
| --- | --- | --- |
|
|
18
|
+
| `projectId` | path | The project whose schema to fetch. |
|
|
19
|
+
| `preview_token` | query | Optional. Returns the preview (unpublished) schema when you send it. |
|
|
20
|
+
|
|
21
|
+
## Response
|
|
22
|
+
|
|
23
|
+
The response is a [JSON Schema draft 2020-12](https://json-schema.org/draft/2020-12/schema) document with Picked-specific extension fields:
|
|
24
|
+
|
|
25
|
+
| Field | Description |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| `x-picked-schema-version` | Schema document version (currently `1`). |
|
|
28
|
+
| `x-picked-source` | `"published"` or `"preview"` — mirrors the surface you requested. |
|
|
29
|
+
| `x-picked-version-id` | Published workspace version id, or `null` on preview. |
|
|
30
|
+
| `x-picked-step-content-models` | Map of step key → content model key, which gives each layout its type. |
|
|
31
|
+
| `$defs.contentModels` | JSON Schema definitions for each content model. |
|
|
32
|
+
| `$defs.contentBlocks` | JSON Schema definitions for reusable content blocks. |
|
|
33
|
+
| `$defs.fields` | Object schema for project field values. |
|
|
34
|
+
| `$defs.featureKeys` | String enum of feature keys. |
|
|
35
|
+
| `$defs.experienceKeys` | String enum of experience keys. |
|
|
36
|
+
| `$defs.stepKeys` | String enum of step keys. |
|
|
37
|
+
|
|
38
|
+
## Published and preview
|
|
39
|
+
|
|
40
|
+
On the published surface, the schema reflects your last published workspace. On the preview surface (`?preview_token=...`), the schema reflects the current draft workspace. See [Preview, cache, and crawlers](/reference/delivery-api/preview-caching-crawling).
|
|
41
|
+
|
|
42
|
+
When no published schema exists, the published endpoint returns `404` and tells you to publish the workspace.
|
|
43
|
+
|
|
44
|
+
## Example
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
curl https://api.picked.app/api/v1/projects/proj_123/schema
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
53
|
+
"$id": "picked:project/proj_123/schema",
|
|
54
|
+
"x-picked-schema-version": 1,
|
|
55
|
+
"x-picked-source": "published",
|
|
56
|
+
"x-picked-version-id": "ver_456",
|
|
57
|
+
"x-picked-step-content-models": {
|
|
58
|
+
"intro": "welcome-page"
|
|
59
|
+
},
|
|
60
|
+
"$defs": {
|
|
61
|
+
"contentModels": {},
|
|
62
|
+
"contentBlocks": {},
|
|
63
|
+
"fields": { "type": "object", "additionalProperties": false, "properties": {} },
|
|
64
|
+
"featureKeys": { "type": "string", "enum": ["default"] },
|
|
65
|
+
"experienceKeys": { "type": "string", "enum": ["welcome-survey"] },
|
|
66
|
+
"stepKeys": { "type": "string", "enum": ["intro"] }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Related
|
|
72
|
+
|
|
73
|
+
- [Type generation](/reference/sdk/type-generation) — Generate TypeScript types from this schema in your app.
|
|
74
|
+
- [Project Config](/reference/delivery-api/project-config) — Runtime project configuration for the SDK.
|
|
@@ -68,11 +68,10 @@ changes. `getStepContent()` returns a store, which you read with the `$` prefix.
|
|
|
68
68
|
:::code-group
|
|
69
69
|
|
|
70
70
|
```tsx [React]
|
|
71
|
-
import {
|
|
72
|
-
import { useContent } from '@picked/react/hooks'
|
|
71
|
+
import { useContent, useStoreGlobal } from '@picked/react/hooks'
|
|
73
72
|
|
|
74
73
|
export function Banner() {
|
|
75
|
-
const banner =
|
|
74
|
+
const banner = useStoreGlobal(useContent('entry_42'))
|
|
76
75
|
|
|
77
76
|
return <h1>{String(banner?.data.headline ?? '')}</h1>
|
|
78
77
|
}
|
|
@@ -99,12 +98,11 @@ index.
|
|
|
99
98
|
:::code-group
|
|
100
99
|
|
|
101
100
|
```tsx [React]
|
|
102
|
-
import {
|
|
103
|
-
import { useReference, useStepContent } from '@picked/react/hooks'
|
|
101
|
+
import { useReference, useStepContent, useStoreGlobal } from '@picked/react/hooks'
|
|
104
102
|
|
|
105
103
|
export function ProductCategory() {
|
|
106
104
|
const content = useStepContent()
|
|
107
|
-
const category =
|
|
105
|
+
const category = useStoreGlobal(useReference(content?.category))
|
|
108
106
|
|
|
109
107
|
return <span>{String(category?.data.name ?? '')}</span>
|
|
110
108
|
}
|
|
@@ -129,12 +127,11 @@ a list in field order.
|
|
|
129
127
|
:::code-group
|
|
130
128
|
|
|
131
129
|
```tsx [React]
|
|
132
|
-
import {
|
|
133
|
-
import { useReferences, useStepContent } from '@picked/react/hooks'
|
|
130
|
+
import { useReferences, useStepContent, useStoreGlobal } from '@picked/react/hooks'
|
|
134
131
|
|
|
135
132
|
export function ProductCategories() {
|
|
136
133
|
const content = useStepContent()
|
|
137
|
-
const categories =
|
|
134
|
+
const categories = useStoreGlobal(useReferences(content?.categories))
|
|
138
135
|
|
|
139
136
|
return (
|
|
140
137
|
<ul>
|
|
@@ -201,7 +198,7 @@ React and Svelte.
|
|
|
201
198
|
| `deriveReferences(contents, value)` | `Store<Content[]>` | The store behind `useReferences` and `getReferences`. |
|
|
202
199
|
|
|
203
200
|
```ts
|
|
204
|
-
import { createClient, readReferenceIds } from '
|
|
201
|
+
import { createClient, readReferenceIds } from 'picked'
|
|
205
202
|
|
|
206
203
|
const client = createClient({ projectId: 'proj_123' })
|
|
207
204
|
const content = client.contents.getById('entry_789').getState()
|
|
@@ -41,7 +41,7 @@ unique identifier, a version key, a name that a person can read, and a `decide`
|
|
|
41
41
|
function:
|
|
42
42
|
|
|
43
43
|
```ts
|
|
44
|
-
import { createClient } from '
|
|
44
|
+
import { createClient } from 'picked'
|
|
45
45
|
|
|
46
46
|
const client = createClient({
|
|
47
47
|
projectId: 'your-project-id',
|
|
@@ -32,7 +32,7 @@ content the same version.
|
|
|
32
32
|
:::code-group
|
|
33
33
|
|
|
34
34
|
```ts [app.ts]
|
|
35
|
-
import { createClient } from '
|
|
35
|
+
import { createClient } from 'picked'
|
|
36
36
|
import { dynamicExperiencesPlugin } from '@picked/client/plugins/dynamic-experiences'
|
|
37
37
|
|
|
38
38
|
const client = createClient({
|
|
@@ -10,7 +10,7 @@ A plugin to add the Picked client to the window object
|
|
|
10
10
|
## Setup Plugin
|
|
11
11
|
|
|
12
12
|
```ts
|
|
13
|
-
import { createClient } from '
|
|
13
|
+
import { createClient } from 'picked'
|
|
14
14
|
import { windowObjectPlugin } from '@picked/client/plugins/window-object'
|
|
15
15
|
|
|
16
16
|
const client = createClient({
|
|
@@ -16,13 +16,12 @@ Inside a `Step` component, or inside any component that a `Step` renders, call
|
|
|
16
16
|
:::code-group
|
|
17
17
|
|
|
18
18
|
```tsx [React]
|
|
19
|
-
import { useStep } from '@picked/react/hooks'
|
|
20
|
-
import { useUnit } from 'effector-react'
|
|
19
|
+
import { useStep, useStoreGlobal } from '@picked/react/hooks'
|
|
21
20
|
|
|
22
21
|
function ContactForm() {
|
|
23
22
|
const { step, fields } = useStep()
|
|
24
|
-
const currentStep =
|
|
25
|
-
const currentFields =
|
|
23
|
+
const currentStep = useStoreGlobal(step)
|
|
24
|
+
const currentFields = useStoreGlobal(fields)
|
|
26
25
|
|
|
27
26
|
return (
|
|
28
27
|
<>
|