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
@@ -0,0 +1,307 @@
1
+ ---
2
+ type: how-to
3
+ layout: docs
4
+ ---
5
+
6
+ # How to connect an external service with OAuth
7
+
8
+ This guide shows you how to connect one installation of your app to an account at a
9
+ different service. It uses the authorization code flow of OAuth. A person clicks a button on the
10
+ page of your app. The service opens in a new window, and the person gives access. Your
11
+ server keeps the tokens of the service in labels of the installation.
12
+
13
+ `@picked/app-kit` does the OAuth steps that are the same for each service. Your app gives two
14
+ functions: `authorize` builds the authorization URL of the service, and `complete` exchanges
15
+ the code for tokens.
16
+
17
+ You need these items:
18
+
19
+ - An app with a server that uses `@picked/app-kit`, and an `app-home` page.
20
+ [How to add a page to the dashboard](/how-to/apps/add-a-page-to-the-dashboard) shows the
21
+ page.
22
+ - An OAuth client at the service: a client ID and a client secret.
23
+
24
+ The examples use a service at `crm.example.com`. Use the addresses and the scopes that your
25
+ service gives.
26
+
27
+ ## 1. Register the callback address
28
+
29
+ At the service, register this callback address for your OAuth client:
30
+
31
+ ```text
32
+ <APP_PUBLIC_URL>/oauth/callback
33
+ ```
34
+
35
+ `APP_PUBLIC_URL` is the origin of your app, for example `https://crm-app.example.com`.
36
+ `readAppEnvironment` returns it as `publicUrl`. Refer to
37
+ [App environment variables](/reference/apps/environment) for its value on each host.
38
+
39
+ The callback must have the same host as the page of your app. The new window starts on the
40
+ origin of the page, and sets a cookie for that host only. The callback reads that cookie.
41
+
42
+ If you work on your computer, use one host name for the page and the callback. For example,
43
+ the dashboard shows the page from `http://localhost:4103`. Then the callback address is
44
+ `http://localhost:4103/oauth/callback`, not `http://127.0.0.1:4103/oauth/callback`. On an
45
+ `http:` address of `localhost`, `127.0.0.1` or `[::1]`, the cookie has the name
46
+ `picked-oauth-<port>`. Two apps on different ports do not share it.
47
+
48
+ Keep the client ID and the client secret in the environment of your server. In this guide,
49
+ they are `CRM_CLIENT_ID` and `CRM_CLIENT_SECRET`. If each customer has an OAuth client of
50
+ their own, keep the client in labels of the installation in place of the environment. Refer
51
+ to [How to store data for an installation](/how-to/apps/store-data-for-an-installation).
52
+
53
+ ## 2. Add a button that opens the authorization window
54
+
55
+ On the page, call `authorizeInPopup` from a `click` handler. Give it the session token from
56
+ `connect`. To send a value to your server, such as a region that the person chose, give it
57
+ as `params`.
58
+
59
+ ```html [src/home.html]
60
+ <!doctype html>
61
+ <html lang="en">
62
+ <head>
63
+ <meta charset="utf-8" />
64
+ </head>
65
+ <body>
66
+ <select id="region">
67
+ <option value="us">United States</option>
68
+ <option value="eu">Europe</option>
69
+ </select>
70
+ <button id="connect" type="button">Connect CRM</button>
71
+ <p id="status"></p>
72
+ <script type="module">
73
+ import { authorizeInPopup, autoResize, connect } from '/app-kit/frame.js'
74
+
75
+ let context = await connect()
76
+ autoResize()
77
+
78
+ document.getElementById('connect').addEventListener('click', async () => {
79
+ const result = await authorizeInPopup({
80
+ sessionToken: context.sessionToken,
81
+ params: { region: document.getElementById('region').value },
82
+ })
83
+ document.getElementById('status').textContent = result.message
84
+ context = await connect()
85
+ })
86
+ </script>
87
+ </body>
88
+ </html>
89
+ ```
90
+
91
+ `authorizeInPopup` opens a new window at `/oauth/start` on the origin of the page. When that
92
+ window is ready, `authorizeInPopup` sends the session token and `params` to that window only.
93
+ The session token does not go in an address.
94
+
95
+ Do not put an `await` before `authorizeInPopup` in the handler. The browser can stop a new
96
+ window that does not come directly from a click.
97
+
98
+ A session token expires 10 minutes after Picked makes it. With an expired session token, the
99
+ result is `Sign in again`. After each result, the handler calls `connect()` again. The
100
+ dashboard then sends a new session token for the next click.
101
+
102
+ `connect()` works only in the `iframe` of the dashboard, so the page must open in Picked.
103
+
104
+ Some services separate the new window from your page. The window then stays open and
105
+ shows the result. `authorizeInPopup` returns when the person comes back to your page. Read
106
+ the connection from your server again after `authorizeInPopup` returns, and show it. The
107
+ results of `authorizeInPopup` are in
108
+ [`authorizeInPopup`](/reference/apps/app-kit#authorizeinpopup).
109
+
110
+ ## 3. Return the authorization URL
111
+
112
+ On your server, call `startAuthorization` for `/oauth/start`. Give it an `authorize` function
113
+ that returns the authorization URL of the service. Put the value of `state(connection)` in its
114
+ `state` parameter.
115
+
116
+ ```ts [src/server.ts]
117
+ import { OAUTH_START_PATH, finishAuthorization, startAuthorization } from '@picked/app-kit/oauth'
118
+ import type { OAuthCallback } from '@picked/app-kit/oauth'
119
+ import {
120
+ createAppHandler,
121
+ installationClientFor,
122
+ json,
123
+ page,
124
+ readAppEnvironment,
125
+ } from '@picked/app-kit/server'
126
+ import { frameScript, serve } from '@picked/app-kit/node'
127
+
128
+ const port = process.env.APP_PORT ?? '4103'
129
+ const { privateKey, pickedKeys, publicUrl, frameAncestors } = readAppEnvironment(process.env, port)
130
+ const clientId = process.env.CRM_CLIENT_ID ?? ''
131
+ const clientSecret = process.env.CRM_CLIENT_SECRET ?? ''
132
+ const redirectUri = `${publicUrl}/oauth/callback`
133
+ const hosts: Record<string, string> = { us: 'crm.example.com', eu: 'eu.crm.example.com' }
134
+
135
+ function start(request: Request): Promise<Response> {
136
+ return startAuthorization(request, {
137
+ privateKey,
138
+ pickedKeys,
139
+ async authorize({ params, state }) {
140
+ const region =
141
+ typeof params === 'object' && params !== null && 'region' in params ? params.region : 'us'
142
+ if (typeof region !== 'string' || !(region in hosts)) {
143
+ return json({ error: { message: 'Choose a region' } }, 422)
144
+ }
145
+
146
+ const url = new URL(`https://${hosts[region]}/oauth/authorize`)
147
+ url.searchParams.set('response_type', 'code')
148
+ url.searchParams.set('client_id', clientId)
149
+ url.searchParams.set('redirect_uri', redirectUri)
150
+ url.searchParams.set('scope', 'contacts.read contacts.write')
151
+ url.searchParams.set('state', await state(region))
152
+ return url.toString()
153
+ },
154
+ })
155
+ }
156
+ ```
157
+
158
+ `startAuthorization` verifies the session token before it calls `authorize`. `authorize` gets
159
+ the session, the session token, the `params` from the page, and the `state` function.
160
+
161
+ `state(connection)` returns a `state` that holds the installation, the session token and the
162
+ value of a cookie. `connection` is a value that you choose. Use it when your app connects to
163
+ more than one service, or to more than one region of one service. The callback reads it back.
164
+
165
+ To refuse, return a `Response` with the body `{ "error": { "message": "<text>" } }`. The
166
+ page gets that text as the result, and the browser does not go to the service.
167
+
168
+ ## 4. Handle the callback
169
+
170
+ The service sends the browser to `/oauth/callback` with `code` and `state`. Call
171
+ `finishAuthorization` for this path. Give it a `complete` function that exchanges the code
172
+ for tokens.
173
+
174
+ `finishAuthorization` calls `complete` only when the state is correct and the browser has the
175
+ cookie from step 3. Otherwise, the window shows
176
+ `This connection link has expired or was opened in another browser; start again`.
177
+
178
+ Keep the tokens in a secret label of the installation. To write the label, make an
179
+ installation client with the session token from the state:
180
+
181
+ ```ts [src/server.ts]
182
+ async function complete({ state, url }: OAuthCallback): Promise<{ ok: boolean; message: string }> {
183
+ const code = url.searchParams.get('code')
184
+ if (code === null) return { ok: false, message: url.searchParams.get('error') ?? 'No code' }
185
+
186
+ const response = await fetch(`https://${hosts[state.connection]}/oauth/token`, {
187
+ method: 'POST',
188
+ headers: { 'content-type': 'application/x-www-form-urlencoded' },
189
+ body: new URLSearchParams({
190
+ grant_type: 'authorization_code',
191
+ code,
192
+ redirect_uri: redirectUri,
193
+ client_id: clientId,
194
+ client_secret: clientSecret,
195
+ }),
196
+ })
197
+ if (!response.ok) return { ok: false, message: `The CRM answered ${response.status}` }
198
+ const grant: unknown = await response.json()
199
+
200
+ const client = installationClientFor(state, { privateKey, sessionToken: state.sessionToken })
201
+ await client.labels.set([
202
+ {
203
+ namespace: 'crm',
204
+ key: 'connection',
205
+ type: 'json',
206
+ value: JSON.stringify({ region: state.connection, grant }),
207
+ secret: true,
208
+ },
209
+ ])
210
+ return { ok: true, message: 'Connected to the CRM' }
211
+ }
212
+ ```
213
+
214
+ The window sends the `ok` and `message` that `complete` returns to your page, and then
215
+ closes. `authorizeInPopup` returns them.
216
+
217
+ The callback request does not come from Picked, and it has no `Authorization` header. The
218
+ session token in the state is the only way to get a token for the installation, and it
219
+ expires as step 2 shows. If your app has `offlineAccess`, the client can get a token without
220
+ it.
221
+
222
+ ## 5. Route the requests
223
+
224
+ Send the two paths to the functions, in the `fallback` of `createAppHandler`. Send each
225
+ method of `/oauth/start` to `start`: the window loads `GET /oauth/start`, then sends
226
+ `POST /oauth/start`.
227
+
228
+ ```ts [src/server.ts]
229
+ const handler = createAppHandler({
230
+ pickedKeys,
231
+ async fallback(request) {
232
+ const { pathname } = new URL(request.url)
233
+ if (pathname === '/') return page(homeHtml, { frameAncestors })
234
+ if (pathname === '/app-kit/frame.js') return frameScript()
235
+ if (pathname === OAUTH_START_PATH) return start(request)
236
+ if (pathname === '/oauth/callback')
237
+ return finishAuthorization(request, { privateKey, complete })
238
+ return json({ error: 'not_found' }, 404)
239
+ },
240
+ })
241
+
242
+ serve(handler, Number(port))
243
+ ```
244
+
245
+ `homeHtml` is the page from step 2. `OAUTH_START_PATH` is `/oauth/start`. `authorizeInPopup`
246
+ always opens this path.
247
+
248
+ ## 6. Revoke the grant when a person removes the app
249
+
250
+ When a person removes the app from a project, Picked sends `installation.deleted` before it deletes the
251
+ labels. Add `onUninstall` to the options of `createAppHandler` from step 5. Read the secret
252
+ label, and revoke the grant at the service:
253
+
254
+ ```ts [src/server.ts]
255
+ const handler = createAppHandler({
256
+ pickedKeys,
257
+ async onUninstall(event) {
258
+ const client = installationClientFor(event, { privateKey })
259
+ const stored = await client.labels.get('crm', 'connection')
260
+ if (stored === undefined) return
261
+ const { region, grant } = JSON.parse(stored.value)
262
+ await fetch(`https://${hosts[region]}/oauth/revoke`, {
263
+ method: 'POST',
264
+ headers: { 'content-type': 'application/x-www-form-urlencoded' },
265
+ body: new URLSearchParams({ token: grant.refresh_token, client_id: clientId }),
266
+ })
267
+ },
268
+ async fallback(request) {
269
+ const { pathname } = new URL(request.url)
270
+ if (pathname === '/') return page(homeHtml, { frameAncestors })
271
+ if (pathname === '/app-kit/frame.js') return frameScript()
272
+ if (pathname === OAUTH_START_PATH) return start(request)
273
+ if (pathname === '/oauth/callback')
274
+ return finishAuthorization(request, { privateKey, complete })
275
+ return json({ error: 'not_found' }, 404)
276
+ },
277
+ })
278
+ ```
279
+
280
+ If your server answers `installation.deleted` with an error, or does not answer, Picked
281
+ still deletes the installation and its labels.
282
+
283
+ To let a person stop the connection and keep the app, add a route that does the same. Then
284
+ remove the label with `client.labels.delete([{ namespace: 'crm', key: 'connection' }])`.
285
+
286
+ ## 7. Use the connection
287
+
288
+ In a tool call or an event, read the label with the installation client of the request.
289
+ Then call the service with its access token:
290
+
291
+ ```ts
292
+ const stored = await installationClientFor(call, { privateKey }).labels.get('crm', 'connection')
293
+ if (stored === undefined) throw new Error('Connect the CRM on the app page in this project first')
294
+ ```
295
+
296
+ When the access token of the service expires, get a new one with its refresh token. Then
297
+ set the label again.
298
+
299
+ ## Related
300
+
301
+ - [`@picked/app-kit`](/reference/apps/app-kit#pickedapp-kitoauth) — `startAuthorization`,
302
+ `finishAuthorization`, the cookie and the state, and
303
+ [`authorizeInPopup`](/reference/apps/app-kit#authorizeinpopup).
304
+ - [About app authentication](/explanation/app-authentication#oauth-with-another-service) —
305
+ why the state carries the session token, and why a cookie binds the flow to one browser.
306
+ - [How to store data for an installation](/how-to/apps/store-data-for-an-installation) —
307
+ secret labels.
@@ -0,0 +1,162 @@
1
+ ---
2
+ type: how-to
3
+ layout: docs
4
+ ---
5
+
6
+ # How to create an app in the dashboard
7
+
8
+ This guide shows you how to create an app in the dashboard. The dashboard deploys the
9
+ manifest for you. Use it for an app that shows pages from a different site in the dashboard,
10
+ or for an app whose server you deploy yourself.
11
+
12
+ You must have the scope `organization_apps/create` in the organization. To change the app
13
+ later, you must have `organization_apps/update`.
14
+
15
+ The handle names the app in the organization. If an app of the organization has the same
16
+ handle, **Create app** deploys a new version of that app.
17
+
18
+ ## 1. Open the New app page
19
+
20
+ 1. In the organization switcher, choose **Apps**.
21
+ 2. Choose **New app** at the top of the page.
22
+
23
+ ## 2. Fill in the manifest
24
+
25
+ Use one of the two methods that follow. You can change between them at any time. Each
26
+ method starts with the values of the other.
27
+
28
+ ### With the form
29
+
30
+ 1. In **Details**, enter a **Name**, such as `Acme CRM`. The form fills in the **Handle**
31
+ from the name, for example `acme-crm`. To use a different handle, enter it in the **Handle** field.
32
+ 2. Enter a **Description**.
33
+ 3. For each page that the dashboard shows, choose **Add slot** in **Slots**. Then do these
34
+ steps:
35
+ 1. In **Where it shows**, choose the place for the page. Refer to
36
+ [Slot locations](/reference/dashboard/apps#slot-locations).
37
+ 2. In **Page URL**, enter the `https` address of the page.
38
+ 3. Optionally, enter a **Heading** and a **Height in pixels**.
39
+ 4. If the app has a server, enter its base URL in **Base URL** in the **Server** card.
40
+ **Requests Picked sends** shows the URLs that Picked sends requests to. Then choose the
41
+ **Events** that the server gets. Enter the full **MCP server URL** if the app has an MCP
42
+ server. Choose **Works on its own** if necessary.
43
+ 5. For each workflow tool, choose **Add workflow tool** in **Workflow tools**. Enter the
44
+ **Tool name**, the **Tool label** and the **Effect**. Then add the arguments with
45
+ **Add argument**, and the output fields with **Add output field**.
46
+ 6. In **Access**, choose the scopes that the app asks for.
47
+
48
+ To remove a slot, a workflow tool, an argument or an output field, choose **Remove** on it.
49
+
50
+ The dashboard shows each page in an `iframe`. The site of the page must let the dashboard
51
+ show it in an `iframe`. Refer to
52
+ [`frame-ancestors`](/reference/apps/environment#frame-ancestors).
53
+
54
+ ### With JSON
55
+
56
+ 1. Choose **Edit as JSON** at the top of the page.
57
+ 2. In **Manifest (JSON)**, enter the manifest as JSON.
58
+
59
+ This manifest makes an app with a page in each project, and asks to read leads:
60
+
61
+ ```json
62
+ {
63
+ "handle": "acme-crm",
64
+ "name": "Acme CRM",
65
+ "description": "Shows the Acme CRM record of each lead.",
66
+ "scopes": ["organization_leads/read"],
67
+ "slots": [
68
+ {
69
+ "location": "app-home",
70
+ "url": "https://crm.acme.example/picked",
71
+ "title": "Acme CRM",
72
+ "height": 600
73
+ }
74
+ ]
75
+ }
76
+ ```
77
+
78
+ The fields are the same as the fields of the `app` section of `picked.config.ts`. Refer to
79
+ [App manifest](/reference/apps/manifest).
80
+
81
+ To go back to the form, choose **Edit in the form**.
82
+
83
+ ## 3. Create the app
84
+
85
+ Choose **Create app**. The page of the new app opens. The newest version is **Version 1**.
86
+
87
+ If the manifest has errors, the dashboard creates nothing. It shows each error below the
88
+ field that has the error, and all errors below `The app could not be deployed`. If the text
89
+ in **Manifest (JSON)** is not JSON, **Create app** and **Edit in the form** are not
90
+ available.
91
+
92
+ ## 4. Add a public key
93
+
94
+ Do this step only if the server of the app calls Picked. An app with only a page needs no
95
+ key.
96
+
97
+ 1. On the page of the app, in **Public keys**, choose **Add key**.
98
+ 2. In the window **`Add a public key`**, choose **`Generate a key pair`**.
99
+ 3. Choose **`Copy PICKED_APP_PRIVATE_KEY`**.
100
+ 4. Set the private key as `PICKED_APP_PRIVATE_KEY` on the server of the app.
101
+ 5. Choose **Done**.
102
+
103
+ The dashboard shows the private key one time only. After **Done**, you cannot see it again. To register a key that you made with
104
+ `picked app keys generate`, refer to
105
+ [How to rotate an app key](/how-to/apps/rotate-an-app-key#in-the-dashboard).
106
+
107
+ ## Deploy a new version
108
+
109
+ 1. In the organization switcher, choose **Apps**.
110
+ 2. Choose the app in the list.
111
+ 3. Below **New version**, choose **Edit the manifest**.
112
+ 4. Change the manifest in **Manifest (JSON)**.
113
+ 5. Choose `Deploy version <number>`. The number is the number of the next version.
114
+
115
+ The new version shows at the top of **Versions**. Each project that has the app shows
116
+ **New version available**. A person in the project upgrades the installation. Refer to
117
+ [Upgrade an installation](/how-to/apps/upgrade-or-uninstall-an-app).
118
+
119
+ If the manifest is the same as the newest version, the dashboard writes no version. It
120
+ shows `The manifest matches version 2, so nothing was deployed.`, with the number of
121
+ that version.
122
+
123
+ When you deploy the app with the CLI, the page does not show **Edit the manifest**. It shows
124
+ this message:
125
+
126
+ ```
127
+ This app is deployed with the Picked CLI. Change the app section of picked.config.ts and run picked app deploy.
128
+ ```
129
+
130
+ Refer to [How to deploy an app](/how-to/apps/deploy-an-app).
131
+
132
+ ## Delete the app
133
+
134
+ You must have the scope `organization_apps/delete`.
135
+
136
+ 1. On the page of the app, choose **Delete app**.
137
+ 2. Read the warning in the window **Delete app**.
138
+ 3. In the window, choose **Delete app**.
139
+
140
+ Picked removes the app from each project that has it. You cannot undo this. The server of
141
+ the app does not get an `installation.deleted` event.
142
+
143
+ ## API and MCP
144
+
145
+ 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).
146
+
147
+ | Task | GraphQL | MCP tool | Run |
148
+ | --- | --- | --- | --- |
149
+ | Create the app | [`appDeploy`](/reference/management-api/schema/app#appdeploy) | None | None |
150
+ | Add a public key | [`appPublicKeyAdd`](/reference/management-api/schema/app#apppublickeyadd) | None | None |
151
+ | Deploy a new version | [`appDeploy`](/reference/management-api/schema/app#appdeploy) | None | None |
152
+ | Delete the app | [`appDelete`](/reference/management-api/schema/app#appdelete) | None | None |
153
+
154
+ The dashboard sends `appDeploy` with `source: DASHBOARD`. `appDelete` needs a user
155
+ session. An API key cannot delete an app.
156
+
157
+ ## Related
158
+
159
+ - [App manifest](/reference/apps/manifest) — each field, and the validation messages.
160
+ - [Apps](/reference/dashboard/apps) — the apps pages of the dashboard.
161
+ - [How to install an app](/how-to/apps/install-an-app) — put the app on a project.
162
+ - [About apps](/explanation/apps) — apps, versions and installations.
@@ -0,0 +1,201 @@
1
+ ---
2
+ type: how-to
3
+ layout: docs
4
+ ---
5
+
6
+ # How to deploy an app
7
+
8
+ This guide shows you how to deploy a release version of an app. Each project that installs
9
+ the app gets the newest release version.
10
+
11
+ Before you start, you need an app directory with a `picked.config.ts` file and a server that
12
+ uses `@picked/app-kit`. The `app` section of `picked.config.ts` is the manifest. [Build and install your first app](/tutorials/first-app)
13
+ makes both.
14
+
15
+ ## 1. Deploy the server
16
+
17
+ Deploy the server code before you deploy the manifest. Put it at the `endpoint` that the
18
+ manifest names.
19
+
20
+ Picked sends a request to the endpoint when a person installs or upgrades the app. If the
21
+ server does not accept the request, Picked does not do the change and shows an error. A new
22
+ workflow tool fails until the server has the code for it.
23
+
24
+ To put the server on Vercel, refer to
25
+ [How to host an app on Vercel](/how-to/apps/host-an-app-on-vercel).
26
+
27
+ The production dashboard sends requests only to a public `https` endpoint. Refer to
28
+ [Delivery](/reference/apps/protocol#delivery).
29
+
30
+ ## 2. Set the private key of the app
31
+
32
+ The CLI registers the public key of `PICKED_APP_PRIVATE_KEY` with the app. The server uses the
33
+ same private key to call Picked. The CLI does not send the private key.
34
+
35
+ Set the variable in the shell that runs the CLI:
36
+
37
+ ```bash
38
+ export PICKED_APP_PRIVATE_KEY='MC4CAQAwBQYDK2VwBCIEI…'
39
+ ```
40
+
41
+ If the app has no key yet, make one with `picked app keys generate`. Refer to
42
+ [How to rotate an app key](/how-to/apps/rotate-an-app-key#1-make-a-new-key).
43
+
44
+ If the app holds the key already, the CLI keeps it. If the app holds two different
45
+ keys, the CLI stops with
46
+ `An app holds at most 2 public keys; remove one before adding another`.
47
+
48
+ The other key variables and messages of the CLI are in
49
+ [CLI variables](/reference/apps/environment#cli-variables).
50
+
51
+ ## 3. Sign in the CLI
52
+
53
+ Sign in with your account:
54
+
55
+ ```bash
56
+ npx picked login
57
+ ```
58
+
59
+ You must have these scopes in the organization:
60
+
61
+ | Deploy | Scope |
62
+ | ------------------------------------ | -------------------------- |
63
+ | The first deploy of a handle | `organization_apps/create` |
64
+ | Each later deploy of the same handle | `organization_apps/update` |
65
+
66
+ To deploy from CI, use an API key in place of `picked login`. Refer to
67
+ [Deploy from CI](#deploy-from-ci).
68
+
69
+ ## 4. Deploy the manifest
70
+
71
+ In the app directory, deploy the manifest. Put the slug of your organization in place of
72
+ `acme`:
73
+
74
+ ```bash
75
+ npx picked app deploy --org acme
76
+ ```
77
+
78
+ ```
79
+ Deployed Lead Insights (lead-insights) version 1 [app_…]
80
+ ```
81
+
82
+ The command does these things:
83
+
84
+ - It reads the `app` section of `picked.config.ts`, `picked.config.js` or
85
+ `picked.config.json`, in that order. Refer to
86
+ [The `app` section of `picked.config`](/reference/apps/manifest#the-app-section-of-pickedconfig).
87
+ - It checks the manifest. If the manifest has errors, it shows each one below
88
+ ``picked.config `app` is not a valid app manifest:`` and deploys nothing.
89
+ - It registers the public key of `PICKED_APP_PRIVATE_KEY`.
90
+ - It deploys the manifest as the next release version.
91
+
92
+ `--org` takes the slug or the ID of the organization. You can leave it out when your
93
+ account is in one organization only. If your account is in more organizations, the
94
+ command stops with `Name the organisation with --org:` and a list of the slugs.
95
+
96
+ The first deploy of a handle makes the app. The value in `[` `]` is the app ID. Each
97
+ Picked environment gives the app a different app ID. The dashboard also shows the app ID
98
+ on the page of the app, under **App ID**.
99
+
100
+ `picked.config.ts` is code. The CLI runs it when it reads the manifest, so the manifest can
101
+ read `process.env`. For example, it can read the endpoint from a variable:
102
+
103
+ ```ts
104
+ import { defineConfig } from '@picked/config/define'
105
+
106
+ const endpoint = process.env.APP_PUBLIC_URL ?? 'http://localhost:4103'
107
+
108
+ export default defineConfig({
109
+ app: {
110
+ handle: 'lead-insights',
111
+ name: 'Lead Insights',
112
+ endpoint,
113
+ slots: [{ location: 'app-home', url: `${endpoint}/`, title: 'Recent leads' }],
114
+ },
115
+ })
116
+ ```
117
+
118
+ ### When nothing changed
119
+
120
+ If the manifest is the same as the newest release version, the command writes no version:
121
+
122
+ ```
123
+ Lead Insights (lead-insights) is unchanged: the manifest matches version 1 [app_…]
124
+ ```
125
+
126
+ The order of the keys in the manifest has no effect on this comparison. So you can run
127
+ the command on each build.
128
+
129
+ ### An app that you made in the dashboard
130
+
131
+ The CLI can deploy an app that you made on the **New app** page. After the first CLI
132
+ deploy, the app has the badge **Deployed with the CLI**. From then on, you cannot change the
133
+ manifest in the dashboard. A dashboard deploy fails with
134
+ `<name> is deployed with the Picked CLI; deploy changes with picked app deploy`.
135
+
136
+ ## 5. Upgrade the installations
137
+
138
+ Picked does not move an installation to the new version. Each project that has the app
139
+ shows **New version available** next to it. A person in the project chooses **Upgrade**
140
+ and accepts the access of the new version. Refer to
141
+ [How to upgrade or uninstall an app](/how-to/apps/upgrade-or-uninstall-an-app#upgrade-an-app).
142
+
143
+ A release version has no effect on an installation that uses a dev version. That
144
+ installation upgrades only to a dev version.
145
+
146
+ ## Deploy from CI
147
+
148
+ When `PICKED_API_KEY` is set, the CLI sends the API key and needs no `picked login`
149
+ session.
150
+
151
+ 1. Make an API key of the organization. Set its **Project** to **All projects**. Refer to
152
+ [Create a key](/how-to/create-and-revoke-an-api-key#create-a-key).
153
+ 2. In **Permissions**, below **Apps**, choose **`Create and install apps`** and
154
+ **`Deploy app versions and upgrade installations`**.
155
+ 3. Keep the API key and the private key of the app in the secret store of your CI.
156
+ 4. Find the ID of the organization. **Project Settings** shows it as **Organization ID**.
157
+ 5. Run the CLI after the step that deploys the server.
158
+
159
+ With an API key, `--org` must be the ID of the organization. An API key cannot read the
160
+ list of the organizations. A slug, or no `--org`, gives this error:
161
+
162
+ ```
163
+ Not signed in as a user, or no organizations are visible to this account. An API key has no organization list.
164
+ ```
165
+
166
+ This GitHub Actions step deploys the manifest:
167
+
168
+ ```yaml
169
+ - name: Deploy the app manifest
170
+ env:
171
+ PICKED_API_KEY: ${{ secrets.PICKED_API_KEY }}
172
+ PICKED_API_URL: https://api.picked.app
173
+ PICKED_APP_PRIVATE_KEY: ${{ secrets.PICKED_APP_PRIVATE_KEY }}
174
+ APP_PUBLIC_URL: https://lead-insights.example.com
175
+ run: npx picked app deploy --org 3f6c2a1e-8b4d-4c2a-9e7f-5d1b0a9c8e72
176
+ ```
177
+
178
+ `PICKED_API_URL` sets the Picked environment. Each Picked environment keeps a different
179
+ copy of the app. Refer to
180
+ [Values for each Picked environment](/reference/apps/environment#values-for-each-picked-environment).
181
+
182
+ ## API and MCP
183
+
184
+ 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).
185
+
186
+ | Task | GraphQL | MCP tool | Run |
187
+ | --- | --- | --- | --- |
188
+ | Deploy a release version | [`appDeploy`](/reference/management-api/schema/app#appdeploy) | None | None |
189
+
190
+ The CLI sends `appDeploy` with `source: CLI`, `channel: RELEASE` and the public key in
191
+ `publicKey`.
192
+
193
+ ## Related
194
+
195
+ - [App manifest](/reference/apps/manifest) — the fields and the validation messages.
196
+ - [App environment variables](/reference/apps/environment#cli-variables) — the variables
197
+ that the CLI reads.
198
+ - [Apps](/reference/dashboard/apps) — the apps pages of the dashboard.
199
+ - [How to work on an app from your machine](/how-to/apps/develop-an-app-locally) — deploy
200
+ a dev version.
201
+ - [About apps](/explanation/apps) — release versions, dev versions and installations.