picked 0.0.111-next.2 → 0.0.111-next.4

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 (78) 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/tenant-branding.md +16 -0
  51. package/docs/reference/management-api/schema/workflow.md +6 -1
  52. package/docs/reference/management-api/schema/workspace.md +2 -2
  53. package/docs/reference/sdk/analytics-events.md +42 -36
  54. package/docs/reference/sdk/conditions.md +3 -3
  55. package/docs/reference/sdk/fields.md +5 -4
  56. package/docs/reference/sdk/index.md +4 -4
  57. package/docs/reference/sdk/plugins/create-experience.md +11 -9
  58. package/docs/reference/sdk/plugins/hotjar.md +2 -2
  59. package/docs/reference/sdk/plugins/sentry.md +2 -2
  60. package/docs/reference/sdk/plugins/shopify.md +2 -2
  61. package/docs/reference/sdk/predicates.md +5 -5
  62. package/docs/reference/sdk/ssr/index.md +4 -3
  63. package/docs/reference/sdk/ssr/rendering-and-hydration.md +30 -0
  64. package/docs/reference/sdk/type-generation.md +24 -19
  65. package/docs/reference/tools/admin-api-client.md +15 -0
  66. package/docs/reference/tools/cli.md +192 -41
  67. package/docs/reference/tools/mcp.md +30 -9
  68. package/docs/tutorials/first-app.md +308 -0
  69. package/package.json +4 -4
  70. package/docs/explanation/how-pickedql-works.md +0 -76
  71. package/docs/how-to/analytics/index.md +0 -324
  72. package/docs/reference/management-api/schema/analytics.md +0 -75
  73. package/docs/reference/pickedql/data-sources.md +0 -174
  74. package/docs/reference/pickedql/dimensions.md +0 -103
  75. package/docs/reference/pickedql/filtering.md +0 -64
  76. package/docs/reference/pickedql/index.md +0 -18
  77. package/docs/reference/pickedql/schema.md +0 -172
  78. package/docs/reference/pickedql/virtual-functions.md +0 -248
@@ -0,0 +1,152 @@
1
+ ---
2
+ type: how-to
3
+ layout: docs
4
+ ---
5
+
6
+ # How to work on an app from your machine
7
+
8
+ This guide shows you how to connect Picked to an app server that runs on your machine. You
9
+ can then change the app and try each change in a project.
10
+
11
+ You need an app directory with a `picked.config.ts` file whose `app` section is the
12
+ manifest, and a server that uses `@picked/app-kit`. You also need the private key of the app, and a CLI that is signed in. [Build and install your first app](/tutorials/first-app) makes
13
+ all of these.
14
+
15
+ ## 1. Start the server
16
+
17
+ Set the variables that the server reads, for the Picked environment that you use. The
18
+ values for each environment are in [App environment variables](/reference/apps/environment).
19
+
20
+ ```bash
21
+ export PICKED_APP_PRIVATE_KEY='MC4CAQAwBQYDK2VwBCIEI…'
22
+ export PICKED_API_URL=https://api.picked.app
23
+ export APP_PUBLIC_URL=https://my-app.tunnel.example
24
+ export PICKED_DASHBOARD_ORIGINS=https://dashboard.picked.app,https://*.picked.app,https://dashboard.convincely.com
25
+ ```
26
+
27
+ Start the server. Keep it open while you work.
28
+
29
+ ## 2. Make the port public
30
+
31
+ Forward the port of your server to a public `https` address with a forward tool of your
32
+ choice. Copy the address that the tool gives.
33
+
34
+ Picked sends requests only to a public host. The address must use `https` and the default
35
+ port. An address on `localhost` or on a private network works only with a Picked API on
36
+ your machine. Refer to
37
+ [Work with a Picked API on your machine](#work-with-a-picked-api-on-your-machine).
38
+
39
+ ## 3. Deploy a dev version
40
+
41
+ In the app directory, deploy the manifest to the dev versions of the app. Give the public
42
+ address as the endpoint:
43
+
44
+ ```bash
45
+ npx picked app dev --endpoint https://my-app.tunnel.example --org acme
46
+ ```
47
+
48
+ ```
49
+ Deployed My App (my-app) dev version 3 [app_…]
50
+ ```
51
+
52
+ The command does these things:
53
+
54
+ - It reads the `app` section of `picked.config.ts`, `picked.config.js` or
55
+ `picked.config.json`, in that order.
56
+ - It replaces the `endpoint` of the manifest with the value of `--endpoint`.
57
+ - It moves each slot whose `url` starts with the `endpoint` in the `app` section to the new
58
+ endpoint. A slot on a different address keeps its `url`.
59
+ - It registers the public key of `PICKED_APP_PRIVATE_KEY` with the app.
60
+
61
+ `--endpoint` is necessary. `--org` takes the slug or the ID of the organization. You can
62
+ leave it out when your account is in one organization only.
63
+
64
+ If the manifest has errors, the command shows each one below
65
+ ``picked.config `app` is not a valid app manifest:`` and deploys nothing.
66
+
67
+ When you deploy a handle for the first time, Picked makes the app. For this, you must have
68
+ the scope `organization_apps/create`. Each later deploy needs `organization_apps/update`.
69
+
70
+ ## 4. Install the dev version
71
+
72
+ Install the app on a project of the organization that owns the app. Refer to
73
+ [How to install an app](/how-to/apps/install-an-app).
74
+
75
+ Only projects of the organization that owns the app can install a dev version. A new
76
+ installation uses the newest dev version only while the app has no release version. When
77
+ the app has a release version, a new installation uses the newest release version.
78
+
79
+ The installation shows the badge **Dev** while it uses a dev version.
80
+
81
+ Picked sends the installation to your server before it completes the installation. If your server
82
+ does not answer with a `2xx` status, Picked removes the installation and shows
83
+ `<name> did not accept the installation`. When your server answered, the message ends with
84
+ `(it answered <status>)`.
85
+
86
+ ## 5. Send a change to the project
87
+
88
+ What you do depends on what you changed:
89
+
90
+ - **Server code only.** Restart the server. Picked does not keep your code, so you do not
91
+ deploy.
92
+ - **The manifest.** Run `picked app dev` again. Then upgrade the installation.
93
+ - **The public address.** Run `picked app dev` again with the new `--endpoint`. Then
94
+ upgrade the installation. Until you upgrade, Picked sends requests to the old address.
95
+
96
+ If the manifest is the same as the newest dev version, the command writes no version:
97
+
98
+ ```
99
+ My App (my-app) is unchanged: the manifest matches dev version 3 [app_…]
100
+ ```
101
+
102
+ After a new dev version, the installation shows **New version available**. To upgrade it,
103
+ refer to [How to upgrade or uninstall an app](/how-to/apps/upgrade-or-uninstall-an-app).
104
+
105
+ An installation that uses a dev version upgrades only to the newest dev version. An
106
+ installation that uses a release version upgrades only to the newest release version.
107
+
108
+ If your server does not accept the upgrade, Picked puts the installation back on its
109
+ previous version and shows `<name> did not accept the upgrade`.
110
+
111
+ ## Work with a Picked API on your machine
112
+
113
+ If the Picked API and the dashboard run on your machine, set their ports in place of the
114
+ two addresses. Remove `PICKED_API_URL` and `PICKED_DASHBOARD_ORIGINS` from the shell of the
115
+ server, because the server reads them before the ports:
116
+
117
+ ```bash
118
+ unset PICKED_API_URL PICKED_DASHBOARD_ORIGINS
119
+ export PICKED_APP_PRIVATE_KEY='MC4CAQAwBQYDK2VwBCIEI…'
120
+ export API_PORT=3001
121
+ export DASHBOARD_PORT=5173
122
+ ```
123
+
124
+ The server then reads the public keys of Picked from `http://localhost:$API_PORT`. It lets
125
+ these two origins show its pages: `http://localhost:$DASHBOARD_PORT` and `http://127.0.0.1:$DASHBOARD_PORT`.
126
+
127
+ The CLI does not read `API_PORT`. Set `PICKED_API_URL` in the shell that runs the CLI, and
128
+ sign in again:
129
+
130
+ ```bash
131
+ export PICKED_API_URL=http://localhost:3001
132
+ npx picked login
133
+ ```
134
+
135
+ A Picked API outside production sends requests to `localhost` on any port. You need no
136
+ forward tool, and the endpoint can be the local address of your server:
137
+
138
+ ```bash
139
+ npx picked app dev --endpoint http://localhost:4103
140
+ ```
141
+
142
+ ## Related
143
+
144
+ - [CLI](/reference/tools/cli#picked-app-dev) — every flag of `picked app dev`.
145
+ - [App environment variables](/reference/apps/environment) — every variable that the server
146
+ reads.
147
+ - [How to install an app](/how-to/apps/install-an-app) — the consent window and the scopes
148
+ that you must hold.
149
+ - [How to upgrade or uninstall an app](/how-to/apps/upgrade-or-uninstall-an-app) — move an
150
+ installation to a new version.
151
+ - [How to deploy an app](/how-to/apps/deploy-an-app) — deploy a release version.
152
+ - [About apps](/explanation/apps) — versions, dev versions and installations.
@@ -0,0 +1,226 @@
1
+ ---
2
+ type: how-to
3
+ layout: docs
4
+ ---
5
+
6
+ # How to host an app on Vercel
7
+
8
+ This guide shows you how to serve the server of an app from one Vercel Function. Picked
9
+ sends each request to the function, and Vercel serves the static files.
10
+
11
+ Before you start, you need an app directory with `picked.config.ts` and a handler from
12
+ `createAppHandler`. The `app` section of `picked.config.ts` is the manifest. You also need a Vercel project for the directory, and the Vercel CLI.
13
+ [Build and install your first app](/tutorials/first-app) makes the app.
14
+
15
+ When you finish, the directory has these files:
16
+
17
+ ```text
18
+ my-app/
19
+ ├── api/
20
+ │ └── index.ts the Vercel Function
21
+ ├── public/ static files; the build writes app-kit/frame.js here
22
+ ├── src/
23
+ │ ├── app.ts the handler
24
+ │ └── server.ts the server on your machine
25
+ ├── package.json
26
+ ├── picked.config.ts
27
+ └── vercel.json
28
+ ```
29
+
30
+ ## 1. Put the handler in its own module
31
+
32
+ Make the handler in `src/app.ts`. The function on Vercel and the server on your machine
33
+ both use it.
34
+
35
+ ```ts
36
+ import { createAppHandler, json, page, readAppEnvironment } from '@picked/app-kit/server'
37
+ import config from '../picked.config.js'
38
+
39
+ const homePage = `<!doctype html>
40
+ <html>
41
+ <body>
42
+ <p id="project">Connecting to Picked…</p>
43
+ <script type="module">
44
+ import { autoResize, connect } from '/app-kit/frame.js'
45
+ const context = await connect()
46
+ document.getElementById('project').textContent = 'Project ' + context.projectId
47
+ autoResize()
48
+ </script>
49
+ </body>
50
+ </html>`
51
+
52
+ // Builds the handler of the app.
53
+ export function createHandler(
54
+ env: Record<string, string | undefined>,
55
+ options: { frameScript?: () => Promise<Response> } = {},
56
+ ): (request: Request) => Promise<Response> {
57
+ const { pickedKeys, frameAncestors } = readAppEnvironment(env, env.APP_PORT ?? '4103')
58
+ return createAppHandler({
59
+ pickedKeys,
60
+ manifest: config.app,
61
+ async fallback(request) {
62
+ const { pathname } = new URL(request.url)
63
+ if (pathname === '/') return page(homePage, { frameAncestors })
64
+ if (pathname === '/app-kit/frame.js' && options.frameScript !== undefined) {
65
+ return options.frameScript()
66
+ }
67
+ return json({ error: 'not_found' }, 404)
68
+ },
69
+ })
70
+ }
71
+ ```
72
+
73
+ `picked.config.ts` imports `defineConfig` from `@picked/config/define`, which reads no files,
74
+ so the function includes the manifest and nothing more of `@picked/config`.
75
+
76
+ Write each relative import with the extension `.js`, also for a `.ts` file. Vercel runs
77
+ the function as a native JavaScript module. A relative path without the extension fails. Set
78
+ `"type": "module"` in `package.json`.
79
+
80
+ ## 2. Add the function
81
+
82
+ Make `api/index.ts`. Vercel serves each file in `api/` as a function.
83
+
84
+ ```ts
85
+ import { withRewrittenPath } from '@picked/app-kit/server'
86
+ import { createHandler } from '../src/app.js'
87
+
88
+ export default {
89
+ fetch: withRewrittenPath(createHandler(process.env)),
90
+ }
91
+ ```
92
+
93
+ Keep `src/server.ts` for your machine. It serves the same handler. It also serves
94
+ `/app-kit/frame.js` from the package:
95
+
96
+ ```ts
97
+ import { frameScript, serve } from '@picked/app-kit/node'
98
+ import { createHandler } from './app.js'
99
+
100
+ serve(createHandler(process.env, { frameScript }), Number(process.env.APP_PORT ?? '4103'))
101
+ ```
102
+
103
+ ## 3. Send each path to the function
104
+
105
+ Make `vercel.json`:
106
+
107
+ ```json
108
+ {
109
+ "$schema": "https://openapi.vercel.sh/vercel.json",
110
+ "framework": null,
111
+ "buildCommand": "npm run build",
112
+ "outputDirectory": "public",
113
+ "rewrites": [{ "source": "/:path*", "destination": "/api?__path=/:path*" }]
114
+ }
115
+ ```
116
+
117
+ The rewrite sends each path to the function, with the path in `__path`.
118
+ `withRewrittenPath` puts the path back in the URL of the request. So the handler gets
119
+ `/lifecycle`, `/tools/<name>` and the other paths of the
120
+ [App protocol](/reference/apps/protocol).
121
+
122
+ Vercel serves a file in `public/` before it applies the rewrite.
123
+
124
+ ## 4. Copy the script of the page at build time
125
+
126
+ The pages of the app import `/app-kit/frame.js`. The command `app-kit-copy-frame`
127
+ from `@picked/app-kit` copies the script to a directory. Add it as the `build` script of
128
+ `package.json`:
129
+
130
+ ```json
131
+ {
132
+ "type": "module",
133
+ "scripts": {
134
+ "build": "app-kit-copy-frame public",
135
+ "start": "tsx src/server.ts"
136
+ }
137
+ }
138
+ ```
139
+
140
+ Run the build one time to make sure that it works:
141
+
142
+ ```bash
143
+ npm run build
144
+ ```
145
+
146
+ ```
147
+ Copied the app-kit frame script to /home/you/my-app/public/app-kit/frame.js
148
+ ```
149
+
150
+ Do not commit `public/app-kit/frame.js`. Each build writes it again from the installed
151
+ version of `@picked/app-kit`.
152
+
153
+ ## 5. Set the environment variables
154
+
155
+ Set these variables on the Vercel project, for the `production` environment:
156
+
157
+ - `PICKED_APP_PRIVATE_KEY`
158
+ - `PICKED_API_URL`
159
+ - `PICKED_DASHBOARD_ORIGINS`
160
+
161
+ ```bash
162
+ vercel env add PICKED_APP_PRIVATE_KEY production
163
+ vercel env add PICKED_API_URL production
164
+ vercel env add PICKED_DASHBOARD_ORIGINS production
165
+ ```
166
+
167
+ The values for each Picked environment are in
168
+ [App environment variables](/reference/apps/environment#values-for-each-picked-environment).
169
+
170
+ You do not have to set `APP_PUBLIC_URL`. On Vercel, the server uses the production domain
171
+ of the project in production, and the branch URL in a preview. Set it if the app has a
172
+ different domain. Refer to
173
+ [Values when a variable is not set](/reference/apps/environment#values-when-a-variable-is-not-set).
174
+
175
+ ## 6. Deploy the server
176
+
177
+ ```bash
178
+ vercel deploy --prod
179
+ ```
180
+
181
+ Make sure that the function answers. The handler serves the manifest at `/manifest.json`:
182
+
183
+ ```bash
184
+ curl https://my-app.vercel.app/manifest.json
185
+ ```
186
+
187
+ ```json
188
+ {"handle":"my-app","name":"My App", …}
189
+ ```
190
+
191
+ A request that Picked did not sign gets `401`:
192
+
193
+ ```bash
194
+ curl -i -X POST https://my-app.vercel.app/lifecycle
195
+ ```
196
+
197
+ ```
198
+ HTTP/2 401
199
+ {"error":"invalid_signature"}
200
+ ```
201
+
202
+ ## 7. Deploy the manifest
203
+
204
+ Set the `endpoint` of the manifest to the production domain of the project. Then deploy
205
+ the manifest. This command reads the endpoint from `APP_PUBLIC_URL`, as the manifest in
206
+ [How to deploy an app](/how-to/apps/deploy-an-app#4-deploy-the-manifest) does:
207
+
208
+ ```bash
209
+ APP_PUBLIC_URL=https://my-app.vercel.app npx picked app deploy --org acme
210
+ ```
211
+
212
+ ```
213
+ Deployed My App (my-app) version 1 [app_…]
214
+ ```
215
+
216
+ ## Related
217
+
218
+ - [`withRewrittenPath`](/reference/apps/app-kit#withrewrittenpath) and
219
+ [`app-kit-copy-frame`](/reference/apps/app-kit#app-kit-copy-frame) — the parts of
220
+ `@picked/app-kit` that this guide uses.
221
+ - [App environment variables](/reference/apps/environment) — each variable, and its value
222
+ on Vercel.
223
+ - [How to deploy an app](/how-to/apps/deploy-an-app) — release versions, CI and the app
224
+ ID.
225
+ - [How to work on an app from your machine](/how-to/apps/develop-an-app-locally) — run
226
+ `src/server.ts` against a project.
@@ -0,0 +1,116 @@
1
+ ---
2
+ type: how-to
3
+ layout: docs
4
+ ---
5
+
6
+ # How to install an app
7
+
8
+ This guide shows you how to install an app on a project. Before you start, the app must
9
+ show on the tab **Available** of the apps page of the project. An app of your organization shows
10
+ there after you deploy it. An app of a different organization shows there only when it is
11
+ public, with the badge **Published by Picked**.
12
+
13
+ You must have these scopes in the project:
14
+
15
+ - `organization_apps/create`, to install the app.
16
+ - Each scope that the app asks for. You cannot give an app access that you do not have.
17
+
18
+ ## 1. Open the apps of the project
19
+
20
+ 1. Open the project.
21
+ 2. In the project switcher, choose **Apps**.
22
+
23
+ The page has two tabs: **Installed** and **Available**. The page opens on **Installed**.
24
+
25
+ ## 2. Find the app
26
+
27
+ 1. Choose the tab **Available**.
28
+ 2. Find the app.
29
+ 3. Read the line below its description.
30
+
31
+ `Access: <scopes>` names the data that the app can read or change. When the app asks for no
32
+ scopes, the app has no line below its description.
33
+
34
+ ## 3. Install the app
35
+
36
+ 1. Choose **Install** next to the app.
37
+ 2. Read the access in the window `Install <name>?`.
38
+ 3. Choose **Install**.
39
+
40
+ The window shows each scope that the app asks for. Some apps can also work when you are not
41
+ in the dashboard, for example to copy data at fixed times. The window then tells you that the
42
+ app works on its own. You accept all of the access, or you do not install the app.
43
+
44
+ The app moves to the tab **Installed**. Picked tells the app about the installation before
45
+ the installation is complete.
46
+
47
+ ## 4. Open the app
48
+
49
+ 1. Choose the tab **Installed**.
50
+ 2. If the app has its own page, choose **Open** next to the app.
51
+
52
+ The page of the app opens in the project. The top of the page has the button **`Uninstall`**,
53
+ and **Upgrade** when a newer version is available. Refer to
54
+ [How to upgrade or uninstall an app](/how-to/apps/upgrade-or-uninstall-an-app).
55
+
56
+ The line below the name of the installed app shows the other things that the app adds:
57
+
58
+ - `Workflow tools: <names>` shows the tools that your workflows can use. See
59
+ [How to use an app tool in a workflow](/how-to/apps/use-an-app-tool-in-a-workflow).
60
+ - `MCP server for the assistant` tells you that the AI agent of the dashboard can use the
61
+ tools of the app.
62
+
63
+ An app can also add a card to the window that publishes a workspace.
64
+
65
+ ## Install an app of your organization from its page
66
+
67
+ You can also install an app of your organization from the page of the app:
68
+
69
+ 1. In the organization switcher, choose **Apps**.
70
+ 2. Choose the app.
71
+ 3. At the top of the page, choose **Install**.
72
+ 4. In the window `Install <name> in a project`, choose the project. A project that has the app
73
+ already shows the badge **Installed**, and you cannot choose it.
74
+ 5. Read the access in the window `Install <name>?`.
75
+ 6. Choose **Install**.
76
+
77
+ The dashboard opens the app in the project. When the app has an `app-home` slot, it opens the
78
+ page of the app in the project. Otherwise, it opens the apps page of the project.
79
+
80
+ ## If Picked cannot install the app
81
+
82
+ The error shows in a banner at the top of the page. Picked does not install the app.
83
+
84
+ | Error | Do this |
85
+ | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
86
+ | `Cannot grant scopes you do not hold: <scopes>` | Ask an owner of the organization to give you the scopes, or to install the app. |
87
+ | `<name> did not accept the installation (it answered <status>)` | The app refused the installation. Contact the maker of the app. |
88
+ | `<name> did not accept the installation` | Picked cannot get to the app. Try again later. If the error occurs again, contact the maker of the app. |
89
+ | `<name> is already installed on this project` | Find the app on the tab **Installed**. A project has one installation of each app. |
90
+
91
+ ## API and MCP
92
+
93
+ You can also do this task with the [Management API](/reference/management-api/schema), the [MCP server](/reference/tools/mcp), or code that you send to [`picked_run`](/reference/tools/mcp-run).
94
+
95
+ | Task | GraphQL | MCP tool | Run |
96
+ | --- | --- | --- | --- |
97
+ | Find the app | [`installableApps`](/reference/management-api/schema/app#installableapps) | None | None |
98
+ | Install the app | [`appInstall`](/reference/management-api/schema/app#appinstall) | None | None |
99
+
100
+ `appInstall` needs the session of a user. An API key cannot install an app. Set
101
+ `acceptedScopes` to the `scopes` in the `manifest` of the `version` that `installableApps`
102
+ gives. Set `acceptedOfflineAccess` to the `offlineAccess` of that manifest. Picked refuses
103
+ other values.
104
+
105
+ `installableApps` is a connection that gives the apps in name order. Use `first` and `after`
106
+ to read the apps one page at a time. A page has a maximum of 200 apps. Refer to
107
+ [Pagination](/reference/management-api/pagination).
108
+
109
+ ## Related
110
+
111
+ - [Apps](/reference/dashboard/apps) — each part of the apps pages, and each error.
112
+ - [How to upgrade or uninstall an app](/how-to/apps/upgrade-or-uninstall-an-app) — move to a
113
+ new version, or remove the app.
114
+ - [Authorization and scopes](/reference/management-api/authorization-and-scopes#organization-apps)
115
+ — the scopes of apps.
116
+ - [About apps](/explanation/apps) — apps, versions and installations.
@@ -0,0 +1,134 @@
1
+ ---
2
+ type: how-to
3
+ layout: docs
4
+ ---
5
+
6
+ # How to link to an installation from your site
7
+
8
+ This guide shows you how to send a person from your own site to the installation of your
9
+ app in the Picked dashboard. A different service can also send the person. The link names a value that only
10
+ one installation holds, such as the ID of an account at your service. The dashboard finds
11
+ the installation and opens its page.
12
+
13
+ You need an app with a server that uses `@picked/app-kit`, and the private key of the app.
14
+ [Build and install your first app](/tutorials/first-app) makes these. The installation must
15
+ show a page at the `app-home` location. Refer to
16
+ [How to add a page to the dashboard](/how-to/apps/add-a-page-to-the-dashboard).
17
+
18
+ ## 1. Keep the external ID in a label
19
+
20
+ When an installation connects to an account at your service, set a label that holds the ID
21
+ of the account. The label must not be secret. A secret label never matches a link.
22
+
23
+ Set the label with the installation client of the request that makes the connection. An
24
+ example is the callback in [How to connect an external service with OAuth](/how-to/apps/connect-a-third-party-service-with-oauth#4-handle-the-callback):
25
+
26
+ ```ts
27
+ await client.labels.set([{ namespace: 'crm', key: 'account_id', type: 'text', value: 'acct_4821' }])
28
+ ```
29
+
30
+ The namespace and the key of the label each have 1 to 64 characters: lowercase letters,
31
+ digits, `_` or `-`. A label that is expired does not match.
32
+ [How to store data for an installation](/how-to/apps/store-data-for-an-installation) shows
33
+ the other ways to write labels.
34
+
35
+ ## 2. Get the app ID
36
+
37
+ Each Picked environment gives your app a different app ID, for example `app_k3v9x2m1q8zt`.
38
+ Get the ID for each environment that you deploy to, in one of these ways:
39
+
40
+ - **From the CLI.** `picked app deploy` prints it at the end of a line:
41
+ `Deployed My App (my-app) version 3 [app_k3v9x2m1q8zt]`. When the manifest has no
42
+ changes, the line is `My App (my-app) is unchanged: the manifest matches version 3 [app_k3v9x2m1q8zt]`.
43
+ - **From the dashboard.** In the organization, open **Apps**, then open the app. **App ID**
44
+ shows the ID. Click **Copy the app ID** to copy it.
45
+
46
+ Keep the ID in the configuration of your server for that environment. In this guide, it is
47
+ the environment variable `PICKED_APP_ID`, which your server reads.
48
+
49
+ ## 3. Build the link
50
+
51
+ Call `installationLinkUrl` with the origin of the dashboard, the app ID, and the label:
52
+
53
+ ```ts
54
+ import { installationLinkUrl } from '@picked/app-kit/server'
55
+
56
+ const url = installationLinkUrl({
57
+ dashboardOrigin: 'https://dashboard.picked.app',
58
+ appId: process.env.PICKED_APP_ID ?? '',
59
+ namespace: 'crm',
60
+ key: 'account_id',
61
+ value: 'acct_4821',
62
+ })
63
+ ```
64
+
65
+ The result is
66
+ `https://dashboard.picked.app/apps/app_k3v9x2m1q8zt/open?label=crm.account_id&value=acct_4821`.
67
+
68
+ The link has this shape:
69
+
70
+ ```text
71
+ <dashboard origin>/apps/<app ID>/open?label=<namespace>.<key>&value=<value>
72
+ ```
73
+
74
+ `installationLinkUrl` encodes the value. It throws `TypeError` in two conditions:
75
+
76
+ - The app ID, the namespace or the key has a format that Picked does not accept.
77
+ - `dashboardOrigin` is not a URL.
78
+
79
+ ## 4. Send the person to the link
80
+
81
+ Put the link on your site, or redirect to it. For example, the Vercel app answers the
82
+ Configuration URL of its Vercel integration. Vercel opens that URL with a
83
+ `configurationId`. The app redirects to the installation that holds that ID in its
84
+ `vercel.configuration_id` label. This code is a short form of it:
85
+
86
+ ```ts [src/server.ts]
87
+ import { installationLinkUrl, json } from '@picked/app-kit/server'
88
+
89
+ async function configure(request: Request): Promise<Response> {
90
+ const configurationId = new URL(request.url).searchParams.get('configurationId') ?? ''
91
+ if (!/^icfg_\w{1,64}$/.test(configurationId)) return json({ error: 'not_found' }, 404)
92
+
93
+ const location = installationLinkUrl({
94
+ dashboardOrigin: 'https://dashboard.picked.app',
95
+ appId: process.env.PICKED_APP_ID ?? '',
96
+ namespace: 'vercel',
97
+ key: 'configuration_id',
98
+ value: configurationId,
99
+ })
100
+ return new Response(null, { status: 302, headers: { location, 'cache-control': 'no-store' } })
101
+ }
102
+ ```
103
+
104
+ ## 5. Know what the person sees
105
+
106
+ The dashboard looks for the installations of the app that hold the label with that value.
107
+ It keeps only the installations in projects where the person has `organization_apps/read`.
108
+ Then it shows one of these results:
109
+
110
+ | Matches | Result |
111
+ | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
112
+ | One | The dashboard opens the page of the installation, at `/<organization>/<project>/apps/<installation slug>`. |
113
+ | More than one | The page **Choose where to open &lt;app name&gt;** shows a list of the projects, as `<organization> / <project>`. The person chooses one. |
114
+ | None | The page **No installation of this app that you can open matches this link**, with the link **Go to the dashboard**. |
115
+
116
+ For one link, Picked reads 200 installations at most. When more projects match than
117
+ the list shows, the page shows this message: "More projects match this link than this list shows. Open the
118
+ project from the dashboard to find the rest."
119
+
120
+ The person sees no match in these conditions:
121
+
122
+ - The label is secret, is expired, or holds a different value.
123
+ - The app is installed only on projects that the person cannot open.
124
+ - The app ID is for a different Picked environment.
125
+ - The link has no `label` or no `value`.
126
+
127
+ ## Related
128
+
129
+ - [`@picked/app-kit`](/reference/apps/app-kit#installationlinkurl) — the parameters and
130
+ errors of `installationLinkUrl`.
131
+ - [How to store data for an installation](/how-to/apps/store-data-for-an-installation) —
132
+ write the label.
133
+ - [How to deploy an app](/how-to/apps/deploy-an-app) — get the app ID from
134
+ `picked app deploy`.