picked 0.0.101-next.2 → 0.0.101
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/README.md +27 -12
- package/docs/explanation/conditions-and-the-logic-engine.md +94 -0
- package/docs/explanation/content-references.md +99 -0
- package/docs/explanation/feature-flag-allocation.md +218 -0
- package/docs/explanation/how-picked-works.md +124 -0
- package/docs/explanation/how-pickedql-works.md +76 -0
- package/docs/explanation/pages-and-flows.md +64 -0
- package/docs/explanation/the-content-model.md +87 -0
- package/docs/explanation/the-two-apis.md +68 -0
- package/docs/explanation/why-server-side-rendering.md +76 -0
- package/docs/explanation/workspaces-and-versions.md +71 -0
- package/docs/how-to/add-a-step-field-or-action.md +56 -0
- package/docs/how-to/analytics/index.md +324 -0
- package/docs/how-to/archive-or-delete-a-workspace.md +59 -0
- package/docs/how-to/authenticate-the-cli.md +101 -0
- package/docs/how-to/authenticate-with-a-magic-link.md +56 -0
- package/docs/how-to/authenticate-with-a-password.md +68 -0
- package/docs/how-to/authenticate-with-an-api-key.md +60 -0
- package/docs/how-to/authenticate-with-oauth.md +49 -0
- package/docs/how-to/build-a-flow.md +106 -0
- package/docs/how-to/call-an-external-api-from-a-workflow.md +116 -0
- package/docs/how-to/connect-the-mcp-server.md +46 -0
- package/docs/how-to/create-a-content-entry.md +58 -0
- package/docs/how-to/create-a-project.md +40 -0
- package/docs/how-to/create-an-experience.md +51 -0
- package/docs/how-to/create-and-revoke-an-api-key.md +54 -0
- package/docs/how-to/debug-with-the-chrome-extension.md +57 -0
- package/docs/how-to/define-a-page-layout.md +54 -0
- package/docs/how-to/fill-and-publish-a-page.md +82 -0
- package/docs/how-to/install-the-gtm-template.md +84 -0
- package/docs/how-to/install-the-sdk.md +93 -0
- package/docs/how-to/install-the-vite-plugin.md +69 -0
- package/docs/how-to/invite-and-remove-members.md +45 -0
- package/docs/how-to/point-one-entry-at-another.md +75 -0
- package/docs/how-to/preview-a-workspace.md +39 -0
- package/docs/how-to/publish-a-workspace.md +42 -0
- package/docs/how-to/read-a-feature-flag.md +113 -0
- package/docs/how-to/read-a-referenced-entry.md +109 -0
- package/docs/how-to/register-a-component.md +55 -0
- package/docs/how-to/register-an-action-handler.md +85 -0
- package/docs/how-to/register-an-api-that-uses-oauth2.md +107 -0
- package/docs/how-to/render-a-step-form.md +131 -0
- package/docs/how-to/render-an-unpublished-preview.md +41 -0
- package/docs/how-to/retry-a-failed-call-with-a-loop.md +81 -0
- package/docs/how-to/reuse-a-section.md +64 -0
- package/docs/how-to/reuse-a-step-field-or-action.md +39 -0
- package/docs/how-to/roll-back-a-published-version.md +39 -0
- package/docs/how-to/run-an-ab-test.md +59 -0
- package/docs/how-to/run-code-on-a-form-submission.md +125 -0
- package/docs/how-to/server-render-a-page.md +81 -0
- package/docs/how-to/set-a-content-security-policy.md +32 -0
- package/docs/how-to/set-up-mfa.md +126 -0
- package/docs/how-to/switch-workspaces.md +122 -0
- package/docs/how-to/upload-and-use-an-asset.mdx +87 -0
- package/docs/how-to/validate-a-field.md +52 -0
- package/docs/how-to/wait-for-an-action-response.md +182 -0
- package/docs/how-to/write-a-condition.md +57 -0
- package/docs/how-to/write-a-predicate.md +60 -0
- package/docs/index.md +59 -0
- package/docs/reference/dashboard/actions.mdx +65 -0
- package/docs/reference/dashboard/api-keys.mdx +47 -0
- package/docs/reference/dashboard/conditions.mdx +51 -0
- package/docs/reference/dashboard/content/asset-library.mdx +74 -0
- package/docs/reference/dashboard/content/blocks.mdx +66 -0
- package/docs/reference/dashboard/content/content-entries.mdx +109 -0
- package/docs/reference/dashboard/content/models.mdx +119 -0
- package/docs/reference/dashboard/content/pages.mdx +72 -0
- package/docs/reference/dashboard/experiences.mdx +61 -0
- package/docs/reference/dashboard/external-apis.md +182 -0
- package/docs/reference/dashboard/features.mdx +165 -0
- package/docs/reference/dashboard/fields.mdx +120 -0
- package/docs/reference/dashboard/flow-builder/canvas.mdx +58 -0
- package/docs/reference/dashboard/flow-builder/condition-builder.md +69 -0
- package/docs/reference/dashboard/flow-builder/keyboard-shortcuts.md +72 -0
- package/docs/reference/dashboard/flow-builder/nodes.md +74 -0
- package/docs/reference/dashboard/labels.md +321 -0
- package/docs/reference/dashboard/lead-search.md +235 -0
- package/docs/reference/dashboard/projects.mdx +53 -0
- package/docs/reference/dashboard/reports.mdx +53 -0
- package/docs/reference/dashboard/steps.mdx +47 -0
- package/docs/reference/dashboard/team-management.md +38 -0
- package/docs/reference/dashboard/workflow-runs.md +157 -0
- package/docs/reference/dashboard/workflow-templates.md +182 -0
- package/docs/reference/dashboard/workflow-test-runs.md +85 -0
- package/docs/reference/dashboard/workspace-versioning.mdx +42 -0
- package/docs/reference/dashboard/workspaces.mdx +91 -0
- package/docs/reference/delivery-api/experience-content.md +152 -0
- package/docs/reference/delivery-api/index.md +45 -0
- package/docs/reference/delivery-api/preview-caching-crawling.md +79 -0
- package/docs/reference/delivery-api/project-config.md +65 -0
- package/docs/reference/delivery-api/workspace-schema.md +107 -0
- package/docs/reference/glossary.md +201 -0
- package/docs/reference/management-api/authentication.md +87 -0
- package/docs/reference/management-api/authorization-and-scopes.md +291 -0
- package/docs/reference/management-api/error-handling.md +232 -0
- package/docs/reference/management-api/pagination.md +192 -0
- package/docs/reference/management-api/schema/action.md +261 -0
- package/docs/reference/management-api/schema/analytics-session.md +363 -0
- package/docs/reference/management-api/schema/analytics.md +73 -0
- package/docs/reference/management-api/schema/api-key.md +170 -0
- package/docs/reference/management-api/schema/auth.md +1177 -0
- package/docs/reference/management-api/schema/cms-fields.md +954 -0
- package/docs/reference/management-api/schema/cms-models.md +1155 -0
- package/docs/reference/management-api/schema/common.md +362 -0
- package/docs/reference/management-api/schema/condition.md +254 -0
- package/docs/reference/management-api/schema/design-system.md +199 -0
- package/docs/reference/management-api/schema/experience.md +1098 -0
- package/docs/reference/management-api/schema/external-api.md +637 -0
- package/docs/reference/management-api/schema/feature.md +350 -0
- package/docs/reference/management-api/schema/feedback.md +103 -0
- package/docs/reference/management-api/schema/field.md +400 -0
- package/docs/reference/management-api/schema/index.md +243 -0
- package/docs/reference/management-api/schema/integration.md +272 -0
- package/docs/reference/management-api/schema/label.md +349 -0
- package/docs/reference/management-api/schema/lead.md +340 -0
- package/docs/reference/management-api/schema/mcp-server.md +299 -0
- package/docs/reference/management-api/schema/metric.md +223 -0
- package/docs/reference/management-api/schema/operation.md +96 -0
- package/docs/reference/management-api/schema/organization.md +749 -0
- package/docs/reference/management-api/schema/project.md +607 -0
- package/docs/reference/management-api/schema/report.md +243 -0
- package/docs/reference/management-api/schema/saved-view.md +288 -0
- package/docs/reference/management-api/schema/shopify.md +795 -0
- package/docs/reference/management-api/schema/step.md +273 -0
- package/docs/reference/management-api/schema/tenant-branding.md +185 -0
- package/docs/reference/management-api/schema/workbench.md +246 -0
- package/docs/reference/management-api/schema/workflow-run.md +263 -0
- package/docs/reference/management-api/schema/workflow.md +1110 -0
- package/docs/reference/management-api/schema/workspace-version.md +823 -0
- package/docs/reference/management-api/schema/workspace.md +917 -0
- package/docs/reference/pickedql/data-sources.md +174 -0
- package/docs/reference/pickedql/dimensions.md +103 -0
- package/docs/reference/pickedql/filtering.md +64 -0
- package/docs/reference/pickedql/index.md +18 -0
- package/docs/reference/pickedql/schema.md +172 -0
- package/docs/reference/pickedql/virtual-functions.md +248 -0
- package/docs/reference/sdk/actions.md +154 -0
- package/docs/reference/sdk/analytics-events.md +453 -0
- package/docs/reference/sdk/conditions.md +147 -0
- package/docs/reference/sdk/content-security-policy.md +21 -0
- package/docs/reference/sdk/content.md +253 -0
- package/docs/reference/sdk/experiences.md +51 -0
- package/docs/reference/sdk/features.md +256 -0
- package/docs/reference/sdk/fields.md +255 -0
- package/docs/reference/sdk/index.md +68 -0
- package/docs/reference/sdk/plugins/create-experience.md +123 -0
- package/docs/reference/sdk/plugins/dynamic-experiences.md +74 -0
- package/docs/reference/sdk/plugins/fingerprintjs.md +39 -0
- package/docs/reference/sdk/plugins/hotjar.md +60 -0
- package/docs/reference/sdk/plugins/index.md +33 -0
- package/docs/reference/sdk/plugins/sentry.md +51 -0
- package/docs/reference/sdk/plugins/shopify.md +109 -0
- package/docs/reference/sdk/plugins/window-object.md +25 -0
- package/docs/reference/sdk/predicates.md +43 -0
- package/docs/reference/sdk/react.md +61 -0
- package/docs/reference/sdk/ssr/index.md +33 -0
- package/docs/reference/sdk/ssr/rendering-and-hydration.md +103 -0
- package/docs/reference/sdk/ssr/serialize.md +80 -0
- package/docs/reference/sdk/ssr/slots-and-placements.md +113 -0
- package/docs/reference/sdk/steps.md +86 -0
- package/docs/reference/sdk/svelte.md +74 -0
- package/docs/reference/sdk/type-generation.md +265 -0
- package/docs/reference/tools/admin-api-client.md +89 -0
- package/docs/reference/tools/chrome-extension.md +16 -0
- package/docs/reference/tools/cli.md +319 -0
- package/docs/reference/tools/delivery-api-client.md +60 -0
- package/docs/reference/tools/image-optimisation-service.md +104 -0
- package/docs/reference/tools/mcp-run.md +121 -0
- package/docs/reference/tools/mcp.md +391 -0
- package/docs/reference/tools/vite-plugin.md +163 -0
- package/docs/tutorials/first-api-call.md +253 -0
- package/docs/tutorials/first-experience-in-the-dashboard.mdx +160 -0
- package/docs/tutorials/first-experience.mdx +254 -0
- package/docs/tutorials/first-server-rendered-page.mdx +186 -0
- package/package.json +8 -7
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: reference
|
|
3
|
+
layout: docs
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Svelte
|
|
7
|
+
|
|
8
|
+
`@picked/svelte` lets the Picked client render Svelte components, and gives functions and
|
|
9
|
+
components to read the client from Svelte.
|
|
10
|
+
|
|
11
|
+
| Peer dependency | Version |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `svelte` | `^5.55.7` |
|
|
14
|
+
| `@picked/client` | The version of your Picked SDK |
|
|
15
|
+
| `effector` | `^23.4.4` |
|
|
16
|
+
|
|
17
|
+
## Entry points
|
|
18
|
+
|
|
19
|
+
| Import | Exports |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| `@picked/svelte` | `adaptSvelteComponent`, `isValidAdaptedComponent`, `setPickedContext`, `ExperienceSlot`, `HtmlRender`, `LazyImage` |
|
|
22
|
+
| `@picked/svelte/plugins/framework` | `svelteFrameworkPlugin` |
|
|
23
|
+
| `@picked/svelte/plugins/devtools` | `svelteDevtoolsPlugin` |
|
|
24
|
+
| `@picked/svelte/hooks` | `getPicked`, `getExperience`, `getStep`, `getStepContent`, `getStepLayoutContent`, `setStepContext`, `getFeature`, `getFeatureResult`, `getFeatureEnabled`, `getPredicate`, `getPredicateResult`, `getAction`, `getActionResult`, `getContent`, `getReference`, `getReferences`, `createQuery`, `createSessionStorageStore`, `createLocalStorageStore`, `useUnit` |
|
|
25
|
+
| `@picked/svelte/router` | `StepRouter`, `Step` |
|
|
26
|
+
| `@picked/svelte/form` | `getForm` |
|
|
27
|
+
| `@picked/svelte/server` | `renderer`, which renders a Svelte component to HTML on the server |
|
|
28
|
+
|
|
29
|
+
## Framework plugin
|
|
30
|
+
|
|
31
|
+
`svelteFrameworkPlugin` registers Svelte as a framework of the client. The client then
|
|
32
|
+
renders each Svelte component in a shadow root.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { createClient } from 'picked'
|
|
36
|
+
import { svelteFrameworkPlugin } from '@picked/svelte/plugins/framework'
|
|
37
|
+
|
|
38
|
+
const client = createClient({
|
|
39
|
+
projectId: 'your-project-id',
|
|
40
|
+
plugins: [svelteFrameworkPlugin({ components: {} })],
|
|
41
|
+
})
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
| Option | Type | Default | Description |
|
|
45
|
+
| --- | --- | --- | --- |
|
|
46
|
+
| `components` | `{ experience?: { component, style? } }` | required | `experience` renders each experience that has no component of its own. |
|
|
47
|
+
| `stylesheets` | `string[]` | none | The URLs of stylesheets to add to each shadow root. |
|
|
48
|
+
| `css` | `string[]` | none | CSS text to add to each shadow root. |
|
|
49
|
+
|
|
50
|
+
## Devtools plugin
|
|
51
|
+
|
|
52
|
+
`svelteDevtoolsPlugin` connects the client to the Picked Chrome extension.
|
|
53
|
+
|
|
54
|
+
| Option | Type | Default | Description |
|
|
55
|
+
| --- | --- | --- | --- |
|
|
56
|
+
| `enabled` | `boolean` | `false` | When `true`, the devtools open on page load. When `false`, the Chrome extension opens them. |
|
|
57
|
+
| `customTools` | `CustomTool[]` | `[]` | Your own tools, which show in the Custom Tools tab. |
|
|
58
|
+
|
|
59
|
+
When a preview token is there, the devtools launcher shows, even if `enabled` is `false`.
|
|
60
|
+
See [How to debug with the Chrome extension](/how-to/debug-with-the-chrome-extension).
|
|
61
|
+
|
|
62
|
+
## Components
|
|
63
|
+
|
|
64
|
+
`adaptSvelteComponent(component)` makes a Svelte component that the client can render. It
|
|
65
|
+
takes a component, a dynamic import, or a lazy loader. See
|
|
66
|
+
[How to register a component](/how-to/register-a-component).
|
|
67
|
+
|
|
68
|
+
## Related
|
|
69
|
+
|
|
70
|
+
- [How to install the SDK](/how-to/install-the-sdk)
|
|
71
|
+
- [Steps](/reference/sdk/steps)
|
|
72
|
+
- [Features](/reference/sdk/features)
|
|
73
|
+
- [Content](/reference/sdk/content)
|
|
74
|
+
- [Rendering and hydration](/reference/sdk/ssr/rendering-and-hydration)
|
|
@@ -0,0 +1,265 @@
|
|
|
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
|
+
// Reference: `https://docs.picked.app/reference/sdk/type-generation`
|
|
123
|
+
|
|
124
|
+
export type WelcomePage = { /* ... */ }
|
|
125
|
+
export type FieldValues = { /* ... */ }
|
|
126
|
+
export type FeatureKey =
|
|
127
|
+
| 'default'
|
|
128
|
+
| 'hero'
|
|
129
|
+
| 'winter-sale'
|
|
130
|
+
|
|
131
|
+
declare module '@picked/client' {
|
|
132
|
+
interface PickedSchemaRegistry {
|
|
133
|
+
contentModels: {
|
|
134
|
+
'welcome-page': WelcomePage
|
|
135
|
+
}
|
|
136
|
+
stepContentModels: {
|
|
137
|
+
'intro': 'welcome-page'
|
|
138
|
+
}
|
|
139
|
+
featureValues: {
|
|
140
|
+
'hero':
|
|
141
|
+
| false
|
|
142
|
+
| 'hero-a'
|
|
143
|
+
| 'hero-b'
|
|
144
|
+
}
|
|
145
|
+
fieldValues: FieldValues
|
|
146
|
+
featureKeys: FeatureKey
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Commit this file to the version control system, or regenerate it in CI after you publish a workspace change.
|
|
152
|
+
|
|
153
|
+
### Feature flag values
|
|
154
|
+
|
|
155
|
+
A Text feature flag declares the values that it can serve, so `useFeatureResult` narrows
|
|
156
|
+
the bucket to those values:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const result = useFeatureResult('hero')
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The `bucket` property then has the type `false | 'hero-a' | 'hero-b'`.
|
|
163
|
+
|
|
164
|
+
`featureValues` holds the Text feature flags alone. A Boolean feature flag, and a feature
|
|
165
|
+
flag that your application defines, both keep the general `boolean | string` type. The
|
|
166
|
+
`FeatureValueFor<'hero'>` type gives the same union on its own.
|
|
167
|
+
|
|
168
|
+
### Assets
|
|
169
|
+
|
|
170
|
+
An `asset` field is a union. An asset that the API finds has a `url`, and an asset that
|
|
171
|
+
it does not find has no `url`.
|
|
172
|
+
[Field values](/reference/delivery-api/workspace-schema#field-values) gives the two shapes.
|
|
173
|
+
The `in` operator narrows the union:
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
const image = page.hero_image
|
|
177
|
+
|
|
178
|
+
return 'url' in image ? <img src={image.url} width={image.width ?? undefined} alt="" /> : null
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Content blocks
|
|
182
|
+
|
|
183
|
+
Each block type has a `contentBlockKey` property whose type is the key of the block. A
|
|
184
|
+
`switch` on that property gives the `data` type of each block:
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
for (const section of page.sections ?? []) {
|
|
188
|
+
switch (section.contentBlockKey) {
|
|
189
|
+
case 'faq':
|
|
190
|
+
renderFaq(section.data.items)
|
|
191
|
+
break
|
|
192
|
+
case 'hero':
|
|
193
|
+
renderHero(section.data.headline)
|
|
194
|
+
break
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### The model of a record
|
|
200
|
+
|
|
201
|
+
`isContentOfModel(record, key)` from `@picked/client` returns `true` when the
|
|
202
|
+
`contentModelKey` of the record is `key`. In that branch, `record.data` has the generated
|
|
203
|
+
type of the model. `ContentRecordOf<'landing-page'>` gives the same record type, and
|
|
204
|
+
`ContentModelKeys` holds the keys of the models in the workspace.
|
|
205
|
+
|
|
206
|
+
In this example, one component renders the layouts of two models:
|
|
207
|
+
|
|
208
|
+
```tsx
|
|
209
|
+
import { isContentOfModel } from '@picked/client'
|
|
210
|
+
import { useStepLayoutContent } from '@picked/react/hooks'
|
|
211
|
+
|
|
212
|
+
export function Page() {
|
|
213
|
+
const record = useStepLayoutContent()
|
|
214
|
+
|
|
215
|
+
if (record && isContentOfModel(record, 'landing-page')) {
|
|
216
|
+
return <LandingPage content={record.data} />
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (record && isContentOfModel(record, 'standard-page')) {
|
|
220
|
+
return <StandardPage content={record.data} />
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return null
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
The check reads `contentModelKey` only. It does not validate `data` against the model.
|
|
228
|
+
|
|
229
|
+
## Keys the application defines
|
|
230
|
+
|
|
231
|
+
An application can define a feature, an action, a field, a step, or an experience of its
|
|
232
|
+
own. It does this through `createClient` options or through a `register` method. The
|
|
233
|
+
workspace has no record of such a key, so the generated types have none either.
|
|
234
|
+
|
|
235
|
+
A hook still accepts one. Each key type holds the keys of the workspace and any other
|
|
236
|
+
string. Your editor shows the workspace keys, and no local key is an error:
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
useFeature('winter-sale') // from the workspace, and suggested
|
|
240
|
+
useFeature('summer-sales-experiment') // from createClient, and accepted
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Each key type has a `Known` form that holds the workspace keys alone —
|
|
244
|
+
`KnownFeatureKeys`, `KnownActionKeys`, `KnownFieldKeys`, `KnownStepKeys`, and
|
|
245
|
+
`KnownExperienceKeys`. Use one where you want the workspace set and nothing else.
|
|
246
|
+
|
|
247
|
+
## Actions that start a workflow
|
|
248
|
+
|
|
249
|
+
`WorkflowActionKeys` holds the keys of the actions that start a workflow in the workspace. For one
|
|
250
|
+
of these keys, the types of `useAction` and `getAction` give `run`, `status`, `response` and
|
|
251
|
+
`error`. For every other key, the types give the action as a function. Without generated types,
|
|
252
|
+
and with a schema that has no such actions, `WorkflowActionKeys` is `never`. See
|
|
253
|
+
[Actions](/reference/sdk/actions).
|
|
254
|
+
|
|
255
|
+
## Cache
|
|
256
|
+
|
|
257
|
+
Type generation writes its artefacts under `.picked/`: the schema JSON and a manifest. The first run adds this directory to `.gitignore` for you.
|
|
258
|
+
|
|
259
|
+
## Related
|
|
260
|
+
|
|
261
|
+
- [CLI](/reference/tools/cli) — commands, authentication, and environment variables.
|
|
262
|
+
- [How to switch workspaces](/how-to/switch-workspaces) — read a draft workspace on your machine.
|
|
263
|
+
- [Vite plugin](/reference/tools/vite-plugin) — the build-time prefetch and the dev launcher.
|
|
264
|
+
- [Workspace schema](/reference/delivery-api/workspace-schema) — the schema endpoint.
|
|
265
|
+
- [Delivery API](/reference/delivery-api) — the published surface and the preview surface.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: reference
|
|
3
|
+
layout: docs
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Management API client
|
|
7
|
+
|
|
8
|
+
`@picked/admin-api-client` is a typed GraphQL client for the Management API. It gets the
|
|
9
|
+
type of each result and its variables from the API schema.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createAdminApiClient, graphql } from '@picked/admin-api-client'
|
|
13
|
+
|
|
14
|
+
const MeQuery = graphql(`
|
|
15
|
+
query Me {
|
|
16
|
+
user {
|
|
17
|
+
id
|
|
18
|
+
email
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
`)
|
|
22
|
+
|
|
23
|
+
const client = createAdminApiClient({
|
|
24
|
+
apiUrl: 'https://api.picked.app',
|
|
25
|
+
apiKey: process.env.PICKED_API_KEY,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const data = await client.request(MeQuery, {})
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Client options
|
|
32
|
+
|
|
33
|
+
`createAdminApiClient(options)` returns a client. The client sends each request to
|
|
34
|
+
`<apiUrl>/api/graphql`.
|
|
35
|
+
|
|
36
|
+
| Option | Type | Default | Description |
|
|
37
|
+
| --- | --- | --- | --- |
|
|
38
|
+
| `apiUrl` | `string` | required | The origin of the API, for example `https://api.picked.app`. |
|
|
39
|
+
| `token` | `string \| (() => string \| Promise<string>)` | none | A bearer token. A function gives a new token for each request. |
|
|
40
|
+
| `apiKey` | `string` | none | An API key. The client sends it in the `X-API-Key` header. |
|
|
41
|
+
|
|
42
|
+
See [Authentication](/reference/management-api/authentication) for the tokens and keys
|
|
43
|
+
that the API accepts.
|
|
44
|
+
|
|
45
|
+
## Requests
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
client.request(document, variables, options?): Promise<Result>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
| Parameter | Type | Description |
|
|
52
|
+
| --- | --- | --- |
|
|
53
|
+
| `document` | `TadaDocumentNode` | A document that `graphql` makes. |
|
|
54
|
+
| `variables` | `object` | The variables of the document. Use `{}` for a document without variables. |
|
|
55
|
+
| `options.timeoutMs` | `number` | The time limit of the request in milliseconds. The default is `30000`. |
|
|
56
|
+
|
|
57
|
+
The client does not check the shape of the response at runtime.
|
|
58
|
+
|
|
59
|
+
## Errors
|
|
60
|
+
|
|
61
|
+
| Case | Error |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| The API returns GraphQL errors | `AdminApiResponseError`. Its `codes` holds the `extensions.code` of each error. |
|
|
64
|
+
| A network failure, a timeout, or an HTTP error without GraphQL errors | `Error` |
|
|
65
|
+
|
|
66
|
+
See [Errors](/reference/management-api/error-handling) for each error code.
|
|
67
|
+
|
|
68
|
+
## Workspace documents
|
|
69
|
+
|
|
70
|
+
The package also gives the documents that move a workspace from one project to a
|
|
71
|
+
different project:
|
|
72
|
+
|
|
73
|
+
| Document | Operation |
|
|
74
|
+
| --- | --- |
|
|
75
|
+
| `WorkspaceExportDocument` | Reads the full contents of a workspace. |
|
|
76
|
+
| `ProjectLiveVersionDocument` | Reads the live version of a project. |
|
|
77
|
+
| `WorkspaceImportDocument` | Makes a workspace from those contents. |
|
|
78
|
+
| `AssetUploadInitDocument` | Gives a URL that receives the file of an asset. |
|
|
79
|
+
| `AssetCommitDocument` | Records an asset after its file is at that URL. |
|
|
80
|
+
| `AssetDeleteDocument` | Deletes an asset. |
|
|
81
|
+
| `WorkspacePublishDocument` | Publishes a workspace. |
|
|
82
|
+
|
|
83
|
+
The `picked workspace export` and `picked workspace import` commands use these documents.
|
|
84
|
+
See [CLI](/reference/tools/cli).
|
|
85
|
+
|
|
86
|
+
## Related
|
|
87
|
+
|
|
88
|
+
- [Authentication](/reference/management-api/authentication)
|
|
89
|
+
- [About the two APIs](/explanation/the-two-apis)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: reference
|
|
3
|
+
layout: docs
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Chrome Extension
|
|
7
|
+
|
|
8
|
+
The extension for the Picked Developer Tools adds a Picked panel to Chrome DevTools.
|
|
9
|
+
Use the panel to check and debug your Picked integration on any page that runs the
|
|
10
|
+
SDK.
|
|
11
|
+
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
## Related
|
|
15
|
+
|
|
16
|
+
- [How to debug with the Chrome extension](/how-to/debug-with-the-chrome-extension)
|