picked 0.0.111-next.3 → 0.0.111

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 (75) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/docs/explanation/app-authentication.md +178 -0
  3. package/docs/explanation/apps.md +169 -0
  4. package/docs/explanation/conditions-and-the-logic-engine.md +12 -2
  5. package/docs/explanation/feature-flag-allocation.md +5 -3
  6. package/docs/how-to/apps/add-a-page-to-the-dashboard.md +257 -0
  7. package/docs/how-to/apps/add-a-workflow-tool.md +199 -0
  8. package/docs/how-to/apps/add-an-mcp-server-to-an-app.md +210 -0
  9. package/docs/how-to/apps/connect-a-third-party-service-with-oauth.md +307 -0
  10. package/docs/how-to/apps/create-an-app-in-the-dashboard.md +162 -0
  11. package/docs/how-to/apps/deploy-an-app.md +201 -0
  12. package/docs/how-to/apps/develop-an-app-locally.md +152 -0
  13. package/docs/how-to/apps/host-an-app-on-vercel.md +226 -0
  14. package/docs/how-to/apps/install-an-app.md +116 -0
  15. package/docs/how-to/apps/link-to-an-installation-from-your-site.md +134 -0
  16. package/docs/how-to/apps/read-project-data-from-an-app.md +225 -0
  17. package/docs/how-to/apps/rotate-an-app-key.md +130 -0
  18. package/docs/how-to/apps/run-code-when-a-workspace-publishes.md +148 -0
  19. package/docs/how-to/apps/store-data-for-an-installation.md +230 -0
  20. package/docs/how-to/apps/test-an-app.md +359 -0
  21. package/docs/how-to/apps/upgrade-or-uninstall-an-app.md +97 -0
  22. package/docs/how-to/apps/use-an-app-tool-in-a-workflow.md +112 -0
  23. package/docs/index.md +6 -3
  24. package/docs/reference/apps/app-kit.md +811 -0
  25. package/docs/reference/apps/environment.md +116 -0
  26. package/docs/reference/apps/manifest.md +311 -0
  27. package/docs/reference/apps/protocol.md +497 -0
  28. package/docs/reference/dashboard/apps.md +504 -0
  29. package/docs/reference/dashboard/external-apis.md +5 -0
  30. package/docs/reference/dashboard/features.mdx +5 -5
  31. package/docs/reference/dashboard/labels.md +25 -8
  32. package/docs/reference/dashboard/lead-search.md +6 -6
  33. package/docs/reference/dashboard/reports.mdx +13 -5
  34. package/docs/reference/dashboard/workflow-tools.md +14 -0
  35. package/docs/reference/glossary.md +153 -140
  36. package/docs/reference/management-api/authentication.md +36 -27
  37. package/docs/reference/management-api/authorization-and-scopes.md +73 -21
  38. package/docs/reference/management-api/schema/api-key.md +10 -10
  39. package/docs/reference/management-api/schema/app.md +726 -0
  40. package/docs/reference/management-api/schema/auth.md +7 -7
  41. package/docs/reference/management-api/schema/common.md +54 -35
  42. package/docs/reference/management-api/schema/feature.md +1 -1
  43. package/docs/reference/management-api/schema/feedback.md +1 -1
  44. package/docs/reference/management-api/schema/index.md +35 -20
  45. package/docs/reference/management-api/schema/label.md +31 -8
  46. package/docs/reference/management-api/schema/organization.md +66 -66
  47. package/docs/reference/management-api/schema/project.md +5 -5
  48. package/docs/reference/management-api/schema/report.md +1 -1
  49. package/docs/reference/management-api/schema/shopify.md +19 -19
  50. package/docs/reference/management-api/schema/workflow.md +6 -1
  51. package/docs/reference/management-api/schema/workspace.md +2 -2
  52. package/docs/reference/sdk/analytics-events.md +42 -36
  53. package/docs/reference/sdk/conditions.md +3 -3
  54. package/docs/reference/sdk/fields.md +5 -4
  55. package/docs/reference/sdk/index.md +4 -4
  56. package/docs/reference/sdk/plugins/create-experience.md +11 -9
  57. package/docs/reference/sdk/plugins/hotjar.md +2 -2
  58. package/docs/reference/sdk/plugins/sentry.md +2 -2
  59. package/docs/reference/sdk/plugins/shopify.md +2 -2
  60. package/docs/reference/sdk/predicates.md +5 -5
  61. package/docs/reference/sdk/type-generation.md +24 -19
  62. package/docs/reference/tools/admin-api-client.md +15 -0
  63. package/docs/reference/tools/cli.md +192 -41
  64. package/docs/reference/tools/mcp.md +30 -9
  65. package/docs/tutorials/first-app.md +308 -0
  66. package/package.json +4 -4
  67. package/docs/explanation/how-pickedql-works.md +0 -76
  68. package/docs/how-to/analytics/index.md +0 -324
  69. package/docs/reference/management-api/schema/analytics.md +0 -75
  70. package/docs/reference/pickedql/data-sources.md +0 -174
  71. package/docs/reference/pickedql/dimensions.md +0 -103
  72. package/docs/reference/pickedql/filtering.md +0 -64
  73. package/docs/reference/pickedql/index.md +0 -18
  74. package/docs/reference/pickedql/schema.md +0 -172
  75. package/docs/reference/pickedql/virtual-functions.md +0 -248
@@ -27,20 +27,23 @@ package.
27
27
 
28
28
  ## Commands
29
29
 
30
- | Command | Description |
31
- | --- | --- |
32
- | `picked login` | Sign in with your browser (OAuth) to the API origin of the current directory. Stores a session under `~/.picked/auth/`. |
33
- | `picked logout` | Clear the stored session for the current directory's API origin. |
34
- | `picked whoami` | Print the identity signed in to the API origin of the current directory. |
35
- | `picked status` | Print the resolved selection and the committed `picked.config` default. |
36
- | `picked workspace list` | List each org, project, and workspace that you can read. Alias `ls`. `--json` gives machine output. |
37
- | `picked workspace use` | Set the active project or workspace. Alias `picked use`. Interactive, or `--project` and `--workspace`. |
38
- | `picked workspace export` | Write a workspace, or the published version of a project, to a bundle directory. |
39
- | `picked workspace import` | Create a new draft workspace in a project from a bundle directory. `--publish` also publishes it. |
40
- | `picked generate types` | Read the workspace schema and write `picked-env.d.ts`. `--check` verifies and writes nothing. |
41
- | `picked pull` | Write `picked.snapshot.json`, which a build with `data: 'snapshot'` reads. `--check` verifies and writes nothing. |
42
- | `picked docs list` | List the documentation pages. Words after `list` filter the list. `--type` and `--json` are available. |
43
- | `picked docs read` | Print one documentation page as Markdown. |
30
+ | Command | Description |
31
+ | -------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
32
+ | `picked login` | Sign in with your browser (OAuth) to the API origin of the current directory. Stores a session under `~/.picked/auth/`. |
33
+ | `picked logout` | Clear the stored session for the current directory's API origin. |
34
+ | `picked whoami` | Print the identity signed in to the API origin of the current directory. |
35
+ | `picked status` | Print the resolved selection and the committed `picked.config` default. |
36
+ | `picked workspace list` | List each org, project, and workspace that you can read. Alias `ls`. `--json` gives machine output. |
37
+ | `picked workspace use` | Set the active project or workspace. Alias `picked use`. Interactive, or `--project` and `--workspace`. |
38
+ | `picked workspace export` | Write a workspace, or the published version of a project, to a bundle directory. |
39
+ | `picked workspace import` | Create a new draft workspace in a project from a bundle directory. `--publish` also publishes it. |
40
+ | `picked generate types` | Read the workspace schema and write `picked-env.d.ts`. `--check` verifies and writes nothing. |
41
+ | `picked pull` | Write `picked.snapshot.json`, which a build with `data: 'snapshot'` reads. `--check` verifies and writes nothing. |
42
+ | `picked docs list` | List the documentation pages. Words after `list` filter the list. `--type` and `--json` are available. |
43
+ | `picked docs read` | Print one documentation page as Markdown. |
44
+ | `picked app keys generate` | Print a new private key and its public key for an [app](/explanation/apps). |
45
+ | `picked app deploy` | Deploy the `app` section of `picked.config` as a release version of the app. |
46
+ | `picked app dev` | Deploy the `app` section of `picked.config` as a dev version, with a different endpoint. |
44
47
 
45
48
  ### `picked generate types`
46
49
 
@@ -97,10 +100,10 @@ picked docs read /how-to/install-the-sdk
97
100
 
98
101
  `picked docs list` prints one page on each line: the path, a tab, and the title.
99
102
 
100
- | Option | Description |
101
- | --- | --- |
103
+ | Option | Description |
104
+ | --------------- | --------------------------------------------------------------------------- |
102
105
  | `--type <type>` | Keeps one content type: `tutorial`, `how-to`, `reference` or `explanation`. |
103
- | `--json` | Gives the path, title, type, description and file of each page. |
106
+ | `--json` | Gives the path, title, type, description and file of each page. |
104
107
 
105
108
  `picked docs read` accepts a page path, a `docs.picked.app` URL, or a file path below
106
109
  `node_modules/picked/docs`. The command `picked docs <path>` does the same thing. The first
@@ -163,12 +166,12 @@ picked workspace export --project proj_a1b2 --workspace ws_id --out ./bundle
163
166
  Exported workspace "Snapshot of Default Storefront" with 12 assets to /app/bundle
164
167
  ```
165
168
 
166
- | Flag | Description |
167
- | --- | --- |
168
- | `--project <id>` | The project that holds the workspace. Required. |
169
- | `--live` | Write the version that the project serves now. The bundle does not include draft changes that you made after you published that version. |
170
- | `--workspace <id>` | Write this workspace, with its draft changes. The command stops with status 1 when you use `--live` and `--workspace` together. |
171
- | `--out <dir>` | The bundle directory. It must be in the current directory, and be empty or not exist. Required. |
169
+ | Flag | Description |
170
+ | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
171
+ | `--project <id>` | The project that holds the workspace. Required. |
172
+ | `--live` | Write the version that the project serves now. The bundle does not include draft changes that you made after you published that version. |
173
+ | `--workspace <id>` | Write this workspace, with its draft changes. The command stops with status 1 when you use `--live` and `--workspace` together. |
174
+ | `--out <dir>` | The bundle directory. It must be in the current directory, and be empty or not exist. Required. |
172
175
 
173
176
  The command stops with status 1 when:
174
177
 
@@ -197,10 +200,10 @@ it also needs the `organization_projects/read` scope.
197
200
 
198
201
  #### Bundle directory
199
202
 
200
- | Path | Contents |
201
- | --- | --- |
202
- | `bundle.json` | The workspace. `formatVersion` is `1`. `assets` lists each asset version with its `fileName`, `mimeType`, `sizeBytes`, and `sha256` hash. |
203
- | `assets/<sha256>` | The bytes of one asset. The file name is the `sha256` hash of the bytes, in lowercase. |
203
+ | Path | Contents |
204
+ | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
205
+ | `bundle.json` | The workspace. `formatVersion` is `1`. `assets` lists each asset version with its `fileName`, `mimeType`, `sizeBytes`, and `sha256` hash. |
206
+ | `assets/<sha256>` | The bytes of one asset. The file name is the `sha256` hash of the bytes, in lowercase. |
204
207
 
205
208
  The command writes the bundle into a temporary directory next to `--out`, and writes
206
209
  `bundle.json` last. When the bundle is complete, the command moves it to `--out`. When the
@@ -226,12 +229,12 @@ Imported workspace "Copy of storefront" as ws_new into project proj_c3d4 (assets
226
229
  Published workspace ws_new.
227
230
  ```
228
231
 
229
- | Flag | Description |
230
- | --- | --- |
232
+ | Flag | Description |
233
+ | ---------------- | ---------------------------------------------------------------------------------------------------------- |
231
234
  | `--project <id>` | The project to import into. It can be in a different organization or a different API deployment. Required. |
232
- | `--in <dir>` | The bundle directory that `picked workspace export` wrote. It must be in the current directory. Required. |
233
- | `--name <name>` | The name of the new workspace. The default is the workspace name in the bundle. |
234
- | `--publish` | Publish the new workspace after the command creates it. |
235
+ | `--in <dir>` | The bundle directory that `picked workspace export` wrote. It must be in the current directory. Required. |
236
+ | `--name <name>` | The name of the new workspace. The default is the workspace name in the bundle. |
237
+ | `--publish` | Publish the new workspace after the command creates it. |
235
238
 
236
239
  The command sends the `sha256` hash of each asset to the API before it uploads the asset.
237
240
  When the project already has an asset with the same bytes, the new workspace uses that
@@ -280,6 +283,144 @@ The credential needs the `organization_projects/read`, `organization_projects/up
280
283
  `organization_workspace/update` scopes on the project. For a bundle with workflows, it also
281
284
  needs the scopes of their tools, as described above.
282
285
 
286
+ ### `picked app keys generate`
287
+
288
+ Prints a new `Ed25519` private key and its public key for an app. The command does not call the API, and it does
289
+ not keep the key. It prints the private key one time only.
290
+
291
+ ```bash
292
+ picked app keys generate
293
+ ```
294
+
295
+ ```
296
+ A new app key pair. Keep the private key secret; it is printed once:
297
+
298
+ PICKED_APP_PRIVATE_KEY=MC4CAQAwBQYDK2VwBCIEI…
299
+
300
+ Public key: 3fJ0b…
301
+ Key id: Qm9yZ2…
302
+
303
+ Set PICKED_APP_PRIVATE_KEY on the app server and where you run `picked app deploy`,
304
+ which registers the public key with the app.
305
+ ```
306
+
307
+ The private key is the `base64` of its `PKCS#8 DER`, on one line. The
308
+ public key is the `base64url` of its 32 bytes. See
309
+ [How to rotate an app key](/how-to/apps/rotate-an-app-key).
310
+
311
+ ### `picked app deploy`
312
+
313
+ Reads the `app` section of `picked.config`, checks it, and deploys it as the next release
314
+ version of the app. The first deploy of a `handle` in an organization creates the app. See
315
+ [App configuration](#app-configuration) for the config, and
316
+ [App manifest](/reference/apps/manifest) for the fields.
317
+
318
+ ```bash
319
+ picked app deploy --org acme
320
+ ```
321
+
322
+ ```
323
+ Deployed Lead score (lead-score) version 3 [app_k3v9x2m1q8zt]
324
+ ```
325
+
326
+ When the manifest is the same as the last release version, the command adds no version:
327
+
328
+ ```
329
+ Lead score (lead-score) is unchanged: the manifest matches version 3 [app_k3v9x2m1q8zt]
330
+ ```
331
+
332
+ The value in `[…]` is the app ID.
333
+
334
+ | Flag | Description |
335
+ | -------------------- | ------------------------------------------------------------------------------------------------ |
336
+ | `--org <id or slug>` | The organization of the app. It is necessary when your account is in more than one organization. |
337
+
338
+ When `PICKED_APP_PRIVATE_KEY` or `PICKED_APP_PUBLIC_KEY` is set, the command also registers
339
+ the public key with the app. See [Environment variables](#environment-variables).
340
+
341
+ The command stops with status 1 when:
342
+
343
+ - No `picked.config` file is in the current directory. The message names the files it
344
+ looked for.
345
+ - The `picked.config` file has no `app` section. The message is
346
+ ``picked.config in <dir> has no `app` section. `picked app deploy` and `picked app dev` need one.``
347
+ - The manifest is not correct. The message has one line for each problem.
348
+ - Your account is in more than one organization, and `--org` is not set. The message lists
349
+ the slug of each organization.
350
+ - No organization with that slug is visible to your account.
351
+ - `PICKED_APP_PRIVATE_KEY` is not an `Ed25519` private key in `PKCS#8`.
352
+ - The API rejects the manifest or the request.
353
+
354
+ The credential needs the `organization_apps/update` scope in the organization. When the
355
+ command makes the app, the credential needs `organization_apps/create`. See
356
+ [How to deploy an app](/how-to/apps/deploy-an-app).
357
+
358
+ ### `picked app dev`
359
+
360
+ Deploys the manifest as the next dev version of the app, with the endpoint that `--endpoint`
361
+ gives. Only the projects of the organization of the app can install a dev version. See
362
+ [How to work on an app from your machine](/how-to/apps/develop-an-app-locally).
363
+
364
+ ```bash
365
+ picked app dev --endpoint https://my-app.tunnel.example --org acme
366
+ ```
367
+
368
+ ```
369
+ Deployed Lead score (lead-score) dev version 4 [app_k3v9x2m1q8zt]
370
+ ```
371
+
372
+ | Flag | Description |
373
+ | -------------------- | -------------------------------------------------------------------------------- |
374
+ | `--endpoint <url>` | The address of your app server, for example a tunnel to your computer. Required. |
375
+ | `--org <id or slug>` | The same as for `picked app deploy`. |
376
+
377
+ The command replaces the `endpoint` of the manifest with `--endpoint`. A slot URL that
378
+ starts with the endpoint of the `app` section moves to the new endpoint. The command reads
379
+ the same environment variables, and stops for the same reasons, as `picked app deploy`.
380
+ Without `--endpoint`, it stops with status 1 before it reads the manifest.
381
+
382
+ ### App configuration
383
+
384
+ The `picked.config` file of an app has an `app` section. The `app` section is the manifest.
385
+ A `picked.config` file can have a `projectId`, an `app` section, or both. It must have one of
386
+ them. This is a `picked.config.ts` file:
387
+
388
+ ```ts
389
+ import { defineConfig } from '@picked/config/define'
390
+
391
+ export default defineConfig({
392
+ app: {
393
+ handle: 'lead-score',
394
+ name: 'Lead score',
395
+ endpoint: 'https://lead-score.example.com',
396
+ },
397
+ })
398
+ ```
399
+
400
+ | Key | Description |
401
+ | -------- | ----------------------------------------------------------------------------------------------------------- |
402
+ | `app` | The manifest. See [App manifest](/reference/apps/manifest) for the fields. |
403
+ | `apiUrl` | The Picked API origin that the `app` commands use. `PICKED_API_URL` replaces it. The default is production. |
404
+
405
+ A config with no `projectId` and no `app` section does not load. The CLI then stops with
406
+ status 1 and gives the reason. See
407
+ [The `app` section of `picked.config`](/reference/apps/manifest#the-app-section-of-pickedconfig)
408
+ for each message.
409
+
410
+ A config can have the two keys. Then the `app` commands use the `app` section. The project
411
+ commands use `projectId`.
412
+
413
+ `picked status` prints the app and the project.
414
+
415
+ When a config has an `app` section and no `projectId`, the project commands do these things:
416
+
417
+ - `picked status` prints the handle, the name and the endpoint of the app.
418
+ - `picked generate types` and `picked pull` stop with status 1, with this message:
419
+
420
+ ```
421
+ picked.config in <dir> names no project. Add `projectId` beside its `app` section.
422
+ ```
423
+
283
424
  ## Authentication
284
425
 
285
426
  `picked login` signs in through the browser. It uses an authorization-code flow with PKCE
@@ -290,8 +431,8 @@ The CLI holds one auth config file for each API origin, outside each repository.
290
431
  command reads and writes only the origin that the current directory resolves to, and never
291
432
  a session for another API.
292
433
 
293
- | File | Contents |
294
- | --- | --- |
434
+ | File | Contents |
435
+ | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
295
436
  | `~/.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. |
296
437
 
297
438
  An API deployment with no OAuth client registration rejects `picked login`, and has no
@@ -312,13 +453,22 @@ An API key does not identify a user. When `PICKED_API_KEY` is set, `picked login
312
453
 
313
454
  ## Environment variables
314
455
 
315
- | Variable | Effect |
316
- | --- | --- |
317
- | `PICKED_API_URL` | The API origin that the CLI reads. Supersedes `picked.config` `apiUrl` and the `https://api.picked.app` default. |
318
- | `PICKED_API_KEY` | An API key. When set, the CLI sends it as `X-API-Key` in place of the stored session. |
319
- | `PICKED_PROJECT_ID` | Supersedes the resolved project id, above the active selection and the committed configuration. |
320
- | `PICKED_PREVIEW_TOKEN` | Supersedes the preview token. Applies only when the resolved source is `preview`. |
321
- | `PICKED_DATA` | Supersedes the `data` field of `picked.config`: `bundle`, `api` or `snapshot`. |
456
+ | Variable | Effect |
457
+ | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
458
+ | `PICKED_API_URL` | The API origin that the CLI reads. Supersedes `picked.config` `apiUrl` and the `https://api.picked.app` default. |
459
+ | `PICKED_API_KEY` | An API key. When set, the CLI sends it as `X-API-Key` in place of the stored session. |
460
+ | `PICKED_PROJECT_ID` | Supersedes the resolved project id, above the active selection and the committed configuration. |
461
+ | `PICKED_PREVIEW_TOKEN` | Supersedes the preview token. Applies only when the resolved source is `preview`. |
462
+ | `PICKED_DATA` | Supersedes the `data` field of `picked.config`: `bundle`, `api` or `snapshot`. |
463
+ | `PICKED_APP_PRIVATE_KEY` | The private key of an app. `picked app deploy` and `picked app dev` register its public key with the app. They do not send the private key. |
464
+ | `PICKED_APP_PUBLIC_KEY` | A public key, as the `base64url` of its 32 bytes. `picked app deploy` and `picked app dev` register it when `PICKED_APP_PRIVATE_KEY` is not set. |
465
+
466
+ When neither app key variable is set, `picked app deploy` and `picked app dev` deploy the
467
+ manifest with no key, and print this line:
468
+
469
+ ```
470
+ Set PICKED_APP_PRIVATE_KEY, from `picked app keys generate`, to register the key the app authenticates with.
471
+ ```
322
472
 
323
473
  ### How the selection resolves
324
474
 
@@ -342,3 +492,4 @@ layer supersedes the layer before it:
342
492
  - [Type generation](/reference/sdk/type-generation) — `picked.config.ts` and the generated types.
343
493
  - [Vite plugin](/reference/tools/vite-plugin) — reads the same selection in development and in a build.
344
494
  - [Preview, cache, and crawlers](/reference/delivery-api/preview-caching-crawling) — how a preview token behaves.
495
+ - [How to deploy an app](/how-to/apps/deploy-an-app) — the `picked app` commands in use.
@@ -110,7 +110,12 @@ You cannot delete or publish a workspace with these tools. Do these in the dashb
110
110
 
111
111
  #### `get_schema_info`
112
112
 
113
- Reads the rules for an entity type, and the format of a flow graph. Call it before the first change to that type.
113
+ Reads the rules for one topic, for example an entity type or the format of a flow graph. The
114
+ topics are `experience`, `step`, `field`, `condition`, `action`, `feature`, `flow_graph`,
115
+ `json_logic`, `field_types`, `content_model`, `analytics_query`, `analytics_sql`, and `all`.
116
+ Before the first change to each type, call it with the topic for that type. For example,
117
+ use `flow_graph` before `update_experience_flow`. Before you write an analytics query, use
118
+ `analytics_query` or `analytics_sql`.
114
119
 
115
120
  #### `list_picked_docs`
116
121
 
@@ -448,10 +453,23 @@ queries by `project_id`. You must have the reports read permission on the organi
448
453
 
449
454
  #### `list_analytics_reports`
450
455
 
451
- Lists the analytics reports of a project: the Leads and Sessions dashboards, and the
452
- reports that you added to the project. Each report has its ID and the parameters that
453
- limit it to the project, for example `project_id`. To read the data, use
454
- `run_analytics_question` with the ID, and set all these parameters.
456
+ Lists the analytics reports of a project. The list starts with six reports:
457
+ `Leads: Acquisition`, `Leads: Journeys`, `Leads: Conversion`, `Sessions: Acquisition`,
458
+ `Sessions: Journeys`, and `Sessions: Conversion`. Then it has the other reports of the
459
+ project.
460
+
461
+ Each report has its ID and the parameters that limit its data. The six reports above set
462
+ `project_id` to the ID of the project. The other reports have only the parameters that a
463
+ user set for them with `lockedParameters` in `reportCreate` or `reportUpdate`. A report can
464
+ have no parameters.
465
+
466
+ To read a question, give its ID to `run_analytics_question` as `question_id`. A dashboard
467
+ runs one card at a time. Give its ID as `dashboard_id`, and get the `dashcard_id` and the
468
+ `question_id` of each card from `get_analytics_content`. In `parameters`, set a value for
469
+ each of these parameters.
470
+
471
+ This tool also accepts the leads read permission. With only that permission, the list has the
472
+ Leads and Sessions reports, but not the other reports of the project.
455
473
 
456
474
  #### `search_analytics`
457
475
 
@@ -478,14 +496,17 @@ the parameters and cards of a dashboard.
478
496
 
479
497
  #### `query_analytics`
480
498
 
481
- Runs a structured query and gives the rows, 200 rows on each page. When there are more
482
- rows, the result has a `continuation_token`. Send only this token to get the next page.
483
- Read `get_schema_info` with the topic `analytics_query` for the query format.
499
+ Runs a structured query and gives the rows: 200 rows on each page, and a maximum of 2,000
500
+ rows. When there are more rows, the result has a `continuation_token`. Send only this
501
+ token to get the next page. Read `get_schema_info` with the topic `analytics_query` for
502
+ the query format.
484
503
 
485
504
  #### `run_analytics_sql`
486
505
 
487
506
  Runs SQL on a database and gives the rows. Use it only when `query_analytics` cannot
488
- do the query. Your analytics user must have permission to write SQL on that database.
507
+ do the query. Write the SQL for ClickHouse. Before you write SQL, read
508
+ `get_schema_info` with the topic `analytics_sql`. Your analytics user must have permission
509
+ to write SQL on that database.
489
510
 
490
511
  #### `run_analytics_question`
491
512
 
@@ -0,0 +1,308 @@
1
+ ---
2
+ type: tutorial
3
+ layout: docs
4
+ ---
5
+
6
+ # Build and install your first app
7
+
8
+ In this tutorial we build a small Picked app, install it on a project, and run its workflow
9
+ tool. The app is named Lead Score. It gives a lead a score from its email address and its
10
+ company.
11
+
12
+ At the end you have an app server on your machine. The dashboard shows its page, and a
13
+ workflow test run gets a score from it.
14
+
15
+ ## Before you start
16
+
17
+ - A Picked organization in which you are an Owner.
18
+ - A project in that organization, with a workflow.
19
+ - Node 24 or later.
20
+ - A tool that forwards a port on your machine to a public `https` address. Picked sends
21
+ requests only to public `https` addresses.
22
+
23
+ ## 1. Make the app directory
24
+
25
+ Make a directory for the app. Install `@picked/app-kit`, `@picked/config`, `@picked/cli` and
26
+ `tsx` in it:
27
+
28
+ ```bash
29
+ mkdir lead-score
30
+ cd lead-score
31
+ npm init -y
32
+ npm pkg set type=module
33
+ npm install @picked/app-kit @picked/config
34
+ npm install --save-dev @picked/cli tsx
35
+ ```
36
+
37
+ The directory now holds a `package.json` file and a `node_modules` directory.
38
+
39
+ ## 2. Write the manifest
40
+
41
+ The manifest tells Picked what the app adds to a project. The manifest is the `app` section
42
+ of the `picked.config.ts` file. Make the file `picked.config.ts` in the `lead-score`
43
+ directory:
44
+
45
+ ```ts
46
+ import { defineConfig } from '@picked/config/define'
47
+
48
+ const endpoint = 'http://localhost:4103'
49
+
50
+ export default defineConfig({
51
+ app: {
52
+ handle: 'lead-score',
53
+ name: 'Lead Score',
54
+ description: 'Gives a lead a score from its email address and its company.',
55
+ endpoint,
56
+ slots: [{ location: 'app-home', url: `${endpoint}/`, title: 'Lead Score', height: 200 }],
57
+ workflowTools: [
58
+ {
59
+ name: 'score_lead',
60
+ label: 'Score lead',
61
+ description: 'Gives a lead a score from 0 to 100, and names its tier.',
62
+ effect: 'read',
63
+ arguments: {
64
+ email: { label: 'Email', type: 'string', required: true },
65
+ company: { label: 'Company', type: 'string' },
66
+ },
67
+ output: {
68
+ score: { label: 'Score', type: 'number' },
69
+ tier: { label: 'Tier', type: 'string', description: 'hot, warm or cold' },
70
+ },
71
+ },
72
+ ],
73
+ },
74
+ })
75
+ ```
76
+
77
+ This manifest declares three things:
78
+
79
+ - `endpoint` is the address of the app server. Picked sends its requests below this
80
+ address.
81
+ - The `app-home` slot is a page that the dashboard shows in the project.
82
+ - `score_lead` is a workflow tool. Its `effect` is `read`, so a workflow test run runs it.
83
+
84
+ The `endpoint` is a local address for now. In step 7 the CLI changes it to your public
85
+ address.
86
+
87
+ ## 3. Write the server
88
+
89
+ Make the file `src/server.ts`:
90
+
91
+ ```ts
92
+ import { createAppHandler, json, page, readAppEnvironment } from '@picked/app-kit/server'
93
+ import { frameScript, serve } from '@picked/app-kit/node'
94
+
95
+ const port = '4103'
96
+ const { pickedKeys, frameAncestors } = readAppEnvironment(process.env, port)
97
+
98
+ const freeMail = new Set(['gmail.com', 'outlook.com', 'hotmail.com', 'yahoo.com', 'icloud.com'])
99
+
100
+ function scoreLead(email: string, company: string): { score: number; tier: string } {
101
+ const domain = email.split('@')[1]?.toLowerCase() ?? ''
102
+ let score = 20
103
+ if (domain !== '' && !freeMail.has(domain)) score += 40
104
+ if (company.trim() !== '') score += 20
105
+ const tier = score >= 70 ? 'hot' : score >= 40 ? 'warm' : 'cold'
106
+ return { score, tier }
107
+ }
108
+
109
+ const homePage = `<!doctype html>
110
+ <html lang="en">
111
+ <head><meta charset="utf-8" /></head>
112
+ <body style="font: 14px system-ui, sans-serif">
113
+ <p id="status">Connecting to Picked…</p>
114
+ <script type="module">
115
+ import { connect, autoResize } from '/app-kit/frame.js'
116
+ const context = await connect()
117
+ document.getElementById('status').textContent =
118
+ 'Lead Score version ' + context.appVersion + ' is installed in ' + context.organizationSlug + '.'
119
+ autoResize()
120
+ </script>
121
+ </body>
122
+ </html>`
123
+
124
+ const handler = createAppHandler({
125
+ pickedKeys,
126
+ onInstall: (event) => {
127
+ console.log(`Installed on project ${event.projectId}`)
128
+ },
129
+ tools: {
130
+ score_lead(call) {
131
+ const email = typeof call.arguments.email === 'string' ? call.arguments.email : ''
132
+ const company = typeof call.arguments.company === 'string' ? call.arguments.company : ''
133
+ return Promise.resolve(scoreLead(email, company))
134
+ },
135
+ },
136
+ fallback(request) {
137
+ const { pathname } = new URL(request.url)
138
+ if (pathname === '/') return page(homePage, { frameAncestors })
139
+ if (pathname === '/app-kit/frame.js') return frameScript()
140
+ return json({ error: 'not_found' }, 404)
141
+ },
142
+ })
143
+
144
+ serve(handler, Number(port))
145
+ ```
146
+
147
+ The server has three parts:
148
+
149
+ - `createAppHandler` checks that Picked signed each request. Then it sends the request to
150
+ `onInstall` or to the `score_lead` tool.
151
+ - `fallback` serves the page, and the script `/app-kit/frame.js` that the page imports.
152
+ - The page calls `connect` to get its context from the dashboard. Then it calls
153
+ `autoResize`, which keeps the height of the page in the dashboard equal to its content.
154
+
155
+ ## 4. Make the keys of the app
156
+
157
+ The app server and the CLI need the private key of the app. Make a private key and its
158
+ public key:
159
+
160
+ ```bash
161
+ npx picked app keys generate
162
+ ```
163
+
164
+ ```
165
+ A new app key pair. Keep the private key secret; it is printed once:
166
+
167
+ PICKED_APP_PRIVATE_KEY=MC4CAQAwBQYDK2VwBCIEI…
168
+
169
+ Public key: 3fJ0b…
170
+ Key id: Qm9yZ2…
171
+
172
+ Set PICKED_APP_PRIVATE_KEY on the app server and where you run `picked app deploy`,
173
+ which registers the public key with the app.
174
+ ```
175
+
176
+ Copy the `PICKED_APP_PRIVATE_KEY=…` line to a safe place. The CLI shows it one time
177
+ only.
178
+
179
+ ## 5. Make the port public
180
+
181
+ Open a second shell. Forward port `4103` to a public `https` address with your tool.
182
+
183
+ The tool shows a public `https` address, such as `https://lead-score.tunnel.example`.
184
+ Copy that address. In the next steps, put it where you see
185
+ `https://lead-score.tunnel.example`.
186
+
187
+ ## 6. Start the server
188
+
189
+ Go back to the first shell. Set the four values that the server reads:
190
+
191
+ ```bash
192
+ export PICKED_APP_PRIVATE_KEY='MC4CAQAwBQYDK2VwBCIEI…'
193
+ export PICKED_API_URL=https://api.picked.app
194
+ export APP_PUBLIC_URL=https://lead-score.tunnel.example
195
+ export PICKED_DASHBOARD_ORIGINS=https://dashboard.picked.app,https://*.picked.app,https://dashboard.convincely.com
196
+ ```
197
+
198
+ Use the line from step 4 for `PICKED_APP_PRIVATE_KEY`. Then start the server:
199
+
200
+ ```bash
201
+ npx tsx src/server.ts
202
+ ```
203
+
204
+ ```
205
+ Listening on http://localhost:4103
206
+ ```
207
+
208
+ Keep this shell open. The server writes one line for each request that it gets.
209
+
210
+ ## 7. Deploy a dev version
211
+
212
+ Open one more shell in the `lead-score` directory. Set the private key, and sign in the CLI:
213
+
214
+ ```bash
215
+ export PICKED_APP_PRIVATE_KEY='MC4CAQAwBQYDK2VwBCIEI…'
216
+ npx picked login
217
+ ```
218
+
219
+ ```
220
+ Logged in as you@example.com (https://api.picked.app)
221
+ ```
222
+
223
+ Deploy the manifest as a dev version that uses your public address. Put the slug of your
224
+ organization in place of `acme`:
225
+
226
+ ```bash
227
+ npx picked app dev --endpoint https://lead-score.tunnel.example --org acme
228
+ ```
229
+
230
+ ```
231
+ Deployed Lead Score (lead-score) dev version 1 [app_…]
232
+ ```
233
+
234
+ The first deploy makes the app in your organization. The CLI also registers the public key
235
+ of the app. The `endpoint` and the slot address now start with your public address.
236
+
237
+ ## 8. Install the app
238
+
239
+ 1. In the dashboard, open your project.
240
+ 2. In the project switcher, choose **Apps**.
241
+ 3. Choose the tab **Available**.
242
+ 4. Find **Lead Score**. It has the badge **Dev**.
243
+ 5. Choose **Install**.
244
+
245
+ The window **Install Lead Score?** opens. It shows "This app asks for no access to your
246
+ data." because the manifest declares no `scopes`. Choose **Install**.
247
+
248
+ Lead Score moves to the tab **Installed**. Below its name, the line shows
249
+ `Version 1 · 1 slot · Workflow tools: app.lead-score.score_lead`. The app asks for no
250
+ scopes, so it has no access line. The server shell shows the installation:
251
+
252
+ ```
253
+ Installed on project 7d1c…
254
+ POST /lifecycle 200
255
+ ```
256
+
257
+ ## 9. Open the page
258
+
259
+ On the line of Lead Score, choose **Open**.
260
+
261
+ The dashboard opens the page of the app in the project. The page shows:
262
+
263
+ ```
264
+ Lead Score version 1 is installed in acme.
265
+ ```
266
+
267
+ The server shell shows `GET / 200` and `GET /app-kit/frame.js 200`.
268
+
269
+ ## 10. Run the tool in a workflow
270
+
271
+ 1. Open your workflow.
272
+ 2. Choose **Add node**.
273
+ 3. Choose **Add tool**.
274
+ 4. Choose **Lead Score: Score lead**.
275
+ 5. Set `email` to `ada@acme.com`.
276
+ 6. Set `company` to `Acme`.
277
+ 7. Open the **Test** tab.
278
+ 8. Enter the trigger input that the form asks for.
279
+ 9. Choose **Run test**.
280
+
281
+ The result shows the tool node with the status **Succeeded**. Its **Output** is:
282
+
283
+ ```json
284
+ { "score": 80, "tier": "hot" }
285
+ ```
286
+
287
+ The server shell shows `POST /tools/score_lead 200`.
288
+
289
+ ## What you built
290
+
291
+ You built an app with a page and a workflow tool. You deployed it from your machine as a
292
+ dev version, and installed it on a project. The dashboard shows its page, and a workflow
293
+ gets a score from your server.
294
+
295
+ The app server keeps no data. Picked signs each request that it sends. The server
296
+ makes sure that a public key of Picked signed it.
297
+
298
+ ## Where to go next
299
+
300
+ - [About apps](/explanation/apps) — what an app is, and how versions and installations
301
+ work.
302
+ - [How to work on an app from your machine](/how-to/apps/develop-an-app-locally) — change
303
+ the app and send the change to your installation.
304
+ - [How to test an app](/how-to/apps/test-an-app) — test the handler without a Picked API.
305
+ - [How to deploy an app](/how-to/apps/deploy-an-app) — deploy a release version from a
306
+ public server.
307
+ - [App manifest](/reference/apps/manifest) — every field of the `app` section.
308
+ - [`@picked/app-kit`](/reference/apps/app-kit) — every function of the package.