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,497 @@
1
+ ---
2
+ type: reference
3
+ layout: docs
4
+ ---
5
+
6
+ # App protocol
7
+
8
+ The app protocol is the set of requests between Picked and the server of an app. It also
9
+ includes the messages between the dashboard and a page of an app.
10
+ [`@picked/app-kit`](/reference/apps/app-kit) implements it. This page is for a server that
11
+ does not use `@picked/app-kit`, or for a reader who needs the exact rules.
12
+
13
+ [About app authentication](/explanation/app-authentication) tells why the protocol has this
14
+ design.
15
+
16
+ ## Requests from Picked
17
+
18
+ Picked sends lifecycle events, app events and workflow tool calls to a path below the
19
+ `endpoint` of the manifest that the installation uses. Picked sends MCP requests to the
20
+ `mcp.url` of the manifest. An app with no `endpoint` and no `mcp` gets no requests.
21
+
22
+ | Request | Method and URL | When Picked sends it |
23
+ | ------------------ | -------------------------------------- | ----------------------------------------------------------------------------------------- |
24
+ | Lifecycle event | `POST <endpoint>/lifecycle` | After a person installs or upgrades the app on a project, and before a person removes it. |
25
+ | App event | `POST <endpoint>/events` | After an event that the manifest lists in `events`. |
26
+ | Workflow tool call | `POST <endpoint>/tools/<name>` | When a workflow node runs the tool `<name>` of the manifest. |
27
+ | MCP request | `POST`, `GET` or `DELETE` `<mcp.url>` | When the AI agent in the dashboard uses the MCP server of the app. |
28
+
29
+ ## Headers
30
+
31
+ | Header | On | Value |
32
+ | ------------------------ | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
33
+ | `picked-signature` | All requests | `t=<unix seconds>,kid=<key id>,v1=<signature>`. See [The `picked-signature` header](#the-picked-signature-header). |
34
+ | `picked-installation-id` | All requests | The ID of the installation, for example `appi_…`. |
35
+ | `picked-context` | MCP requests | The `base64url` of the JSON of an [`InstallationRef`](#the-installationref-fields). |
36
+ | `content-type` | Lifecycle events, app events, tool calls | `application/json`. |
37
+ | `accept` | Lifecycle events, app events, tool calls | `application/json`. |
38
+ | `idempotency-key` | App events, tool calls | The same value on each resend of one request. |
39
+ | `user-agent` | Lifecycle events, app events, tool calls | `Picked/1.0 (+https://picked.app)`. |
40
+ | `user-agent` | MCP requests | `PickedMcpProxy/1.0 (+https://picked.app)`. |
41
+
42
+ An MCP request also carries the `content-type`, `accept`, `mcp-protocol-version` and
43
+ `mcp-session-id` headers of the AI agent, when it sends them. Picked does not forward the
44
+ `Authorization`, `Cookie` or `Origin` headers of the person.
45
+
46
+ ## The `picked-signature` header
47
+
48
+ Picked signs each request with its `Ed25519` private key. The `picked-signature` header has
49
+ three parts. A `,` separates each part from the next:
50
+
51
+ | Part | Value |
52
+ | ----- | ----------------------------------------------------------------- |
53
+ | `t` | The time at which Picked signed, in `unix` seconds. |
54
+ | `kid` | The ID of the Picked key that signed. |
55
+ | `v1` | The `base64url` of the `Ed25519` signed value of the signed text. |
56
+
57
+ The signed text is `<t>.<body>`, with the body exactly as Picked sent it. For an MCP request,
58
+ the body part is `<picked-context>\n<body>`: the value of the `picked-context` header, a line
59
+ feed, and the body. A `GET` or `DELETE` MCP request has an empty body.
60
+
61
+ A request is from Picked when all of these are true:
62
+
63
+ - A public key of Picked has the ID `kid`.
64
+ - That key verifies `v1` over the signed text.
65
+ - `t` is not more than 300 seconds before or after the current time.
66
+
67
+ This `Node.js` example verifies a request without `@picked/app-kit`. For an MCP request,
68
+ put `` `${pickedContext}\n${body}` `` in `signedText`.
69
+
70
+ ```js
71
+ import { createPublicKey, verify } from 'node:crypto'
72
+
73
+ const PICKED_API_URL = process.env.PICKED_API_URL ?? 'https://api.picked.app'
74
+
75
+ let keys = new Map()
76
+
77
+ async function loadKeys() {
78
+ const response = await fetch(`${PICKED_API_URL}/.well-known/picked-app-keys.json`)
79
+ const { keys: jwks } = await response.json()
80
+ keys = new Map(jwks.map((jwk) => [jwk.kid, createPublicKey({ key: jwk, format: 'jwk' })]))
81
+ }
82
+
83
+ export async function verifyPickedSignature(header, signedText) {
84
+ if (header === null) return false
85
+ const parts = Object.fromEntries(header.split(',').map((part) => part.trim().split('=')))
86
+ const timestamp = Number(parts.t)
87
+ if (!Number.isFinite(timestamp) || Math.abs(Date.now() / 1000 - timestamp) > 300) return false
88
+ if (!keys.has(parts.kid)) await loadKeys()
89
+ const key = keys.get(parts.kid)
90
+ if (key === undefined || parts.v1 === undefined) return false
91
+ return verify(
92
+ null,
93
+ Buffer.from(`${parts.t}.${signedText}`),
94
+ key,
95
+ Buffer.from(parts.v1, 'base64url'),
96
+ )
97
+ }
98
+ ```
99
+
100
+ `@picked/app-kit` loads the keys again for an unknown `kid` at most one time each minute.
101
+
102
+ ## Public keys of Picked
103
+
104
+ Picked publishes its public keys as a JSON Web Key Set at
105
+ `<Picked API>/.well-known/picked-app-keys.json`, for example
106
+ `https://api.picked.app/.well-known/picked-app-keys.json`. The response has
107
+ `cache-control: public, max-age=300`.
108
+
109
+ ```json
110
+ {
111
+ "keys": [
112
+ {
113
+ "kty": "OKP",
114
+ "crv": "Ed25519",
115
+ "alg": "EdDSA",
116
+ "use": "sig",
117
+ "kid": "HQ5n5zqPQ-Dy39Ix",
118
+ "x": "mjKkpr8T2m_9DePfc7SHBxKxSsNEe2JgHscMMxccNy0"
119
+ }
120
+ ]
121
+ }
122
+ ```
123
+
124
+ | Field | Value |
125
+ | ----- | ------------------------------------------------------------------------------------------------------------ |
126
+ | `kid` | The key ID: the first 16 characters of the `base64url` of the SHA-256 of the 32 raw bytes of the public key. |
127
+ | `x` | The `base64url` of the 32 raw bytes of the public key. |
128
+
129
+ The set holds the current key of Picked first. After Picked replaces its key, the set can
130
+ also hold old keys.
131
+
132
+ ## The `InstallationRef` fields
133
+
134
+ Each request body from Picked contains these fields. They identify the installation, and the
135
+ Picked API that the app calls back.
136
+
137
+ | Field | Type | Description |
138
+ | ---------------- | -------- | ----------------------------------------------------------------------------------------- |
139
+ | `installationId` | `string` | The ID of the installation, for example `appi_…`. |
140
+ | `organizationId` | `string` | The ID of the organization of the project. |
141
+ | `projectId` | `string` | The ID of the project that the app is installed on. |
142
+ | `apiUrl` | `string` | The origin of the Picked API that sent the request, for example `https://api.picked.app`. |
143
+ | `token` | `string` | A new installation token. See [Installation tokens](#installation-tokens). |
144
+ | `tokenExpiresAt` | `string` | The time at which `token` expires, as ISO 8601. One hour after Picked made the token. |
145
+
146
+ `token` and `tokenExpiresAt` are in each request body from Picked. A session token does not
147
+ contain them. See [Session tokens](#session-tokens).
148
+
149
+ ## Lifecycle events
150
+
151
+ Picked sends lifecycle events to `POST <endpoint>/lifecycle`. The `type` field gives the
152
+ event. Each body also contains the [`InstallationRef`](#the-installationref-fields) fields.
153
+
154
+ | `type` | Other fields | When |
155
+ | ----------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
156
+ | `installation.created` | `scopes`: the scopes of the installation, as `string[]`. | After Picked adds a new installation. |
157
+ | `installation.upgraded` | `version`: the new version number, as `number`. `scopes`: the new scopes, as `string[]`. | After Picked moves the installation to a new version. |
158
+ | `installation.deleted` | None. | Before Picked removes the installation, its tokens and its labels. |
159
+
160
+ ```json
161
+ {
162
+ "type": "installation.created",
163
+ "installationId": "appi_8gk2mz4q7xw1",
164
+ "organizationId": "6f1c2b9e-4d3a-4e8b-9a7c-2d5e8f1a3b4c",
165
+ "projectId": "proj_7d2h9k4m",
166
+ "apiUrl": "https://api.picked.app",
167
+ "scopes": ["organization_leads/read"],
168
+ "token": "…",
169
+ "tokenExpiresAt": "2026-10-30T11:00:00.000Z"
170
+ }
171
+ ```
172
+
173
+ The answer of the app:
174
+
175
+ | Event | A `2xx` answer | Other answers, or no answer |
176
+ | ----------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
177
+ | `installation.created` | Picked keeps the installation. | Picked removes the installation. The installation fails with `<name> did not accept the installation (it answered <status>)`. |
178
+ | `installation.upgraded` | Picked keeps the upgrade. | Picked moves the installation back to its old version and its old scopes. The upgrade fails with `<name> did not accept the upgrade (it answered <status>)`. |
179
+ | `installation.deleted` | Picked removes the installation. | Picked removes the installation. |
180
+
181
+ When Picked gets no answer, the message does not have the `(it answered <status>)` part.
182
+
183
+ During `installation.deleted`, the labels of the installation still exist, and `token` can
184
+ read them.
185
+
186
+ ## App events
187
+
188
+ Picked sends app events to `POST <endpoint>/events`. It sends an event only to an
189
+ installation whose manifest lists it in `events`. The only event is `workspace.published`.
190
+
191
+ | Field | Type | Description |
192
+ | -------------------- | -------- | -------------------------------------------------------------- |
193
+ | `type` | `string` | `workspace.published`. |
194
+ | `eventId` | `string` | The ID of the event. It is the same on each resend. |
195
+ | `workspaceId` | `string` | The workspace that was published. |
196
+ | `workspaceVersionId` | `string` | The version that Picked wrote when it published the workspace. |
197
+ | `occurredAt` | `string` | The time at which the workspace was published, as ISO 8601. |
198
+
199
+ The body also contains the [`InstallationRef`](#the-installationref-fields) fields. The
200
+ `idempotency-key` header is `<eventId>:<installationId>`.
201
+
202
+ Picked does not show the answer of the app to a person. The workspace is published also
203
+ when the delivery fails.
204
+
205
+ ## Workflow tool calls
206
+
207
+ Picked sends a tool call to `POST <endpoint>/tools/<name>`, where `<name>` is the `name` of the
208
+ tool in the manifest.
209
+
210
+ | Field | Type | Description |
211
+ | ---------------- | --------- | -------------------------------------------------------------------------------------------------------- |
212
+ | `type` | `string` | `workflow_tool.call`. |
213
+ | `tool` | `string` | The name of the tool, as the manifest declares it. |
214
+ | `arguments` | `object` | The arguments of the node, after Picked resolves them. |
215
+ | `idempotencyKey` | `string` | `<runId>:<nodeId>`. The same key is the same call. Picked also sends it as the `idempotency-key` header. |
216
+ | `run.runId` | `string` | The ID of the workflow run. |
217
+ | `run.nodeId` | `string` | The ID of the node that calls the tool. |
218
+ | `run.test` | `boolean` | `true` in a test run. |
219
+
220
+ The body also contains the [`InstallationRef`](#the-installationref-fields) fields.
221
+
222
+ ```json
223
+ {
224
+ "type": "workflow_tool.call",
225
+ "tool": "score_lead",
226
+ "arguments": { "email": "ada@example.com", "company": "Analytical Engines" },
227
+ "idempotencyKey": "wkrun_5t8q2n:n3",
228
+ "run": { "runId": "wkrun_5t8q2n", "nodeId": "n3", "test": false },
229
+ "installationId": "appi_8gk2mz4q7xw1",
230
+ "organizationId": "6f1c2b9e-4d3a-4e8b-9a7c-2d5e8f1a3b4c",
231
+ "projectId": "proj_7d2h9k4m",
232
+ "apiUrl": "https://api.picked.app",
233
+ "token": "…",
234
+ "tokenExpiresAt": "2026-10-30T11:00:00.000Z"
235
+ }
236
+ ```
237
+
238
+ The app answers with a JSON `ToolResult`:
239
+
240
+ ```ts
241
+ type ToolResult =
242
+ { output: Record<string, unknown> } | { error: { message: string; retryable?: boolean } }
243
+ ```
244
+
245
+ | Answer | Result in the run |
246
+ | ---------------------------------------------------- | -------------------------------------------------------------------------------------- |
247
+ | `2xx` with an `output` object | The node records `output`. |
248
+ | `5xx` | The node fails with `the app answered <status>`. The failure has `retryable: true`. |
249
+ | Any other status, or a `2xx` with no `output` object | The node fails with `the app answered <status>`. The failure has `retryable: false`. |
250
+ | No answer | The node fails with `the app could not be reached`. The failure has `retryable: true`. |
251
+
252
+ Picked uses the status to set `retryable`. When a tool throws an error, `@picked/app-kit`
253
+ answers with status `422` and `{ "error": { "message": "…" } }`. It answers an unknown tool
254
+ with status `404`.
255
+
256
+ ## MCP requests
257
+
258
+ The AI agent in the dashboard calls `<Picked API>/mcp-proxy/app/<installation ID>`. Picked
259
+ then sends the request to `mcp.url`. Picked first checks that the person holds
260
+ `organization_apps/read` on the project.
261
+
262
+ Picked adds three headers to each MCP request: `picked-context`, `picked-installation-id` and
263
+ `picked-signature`. The body is the `JSON-RPC` body of the AI agent, without changes. That
264
+ body does not identify the installation. `picked-context` identifies it. Picked signs
265
+ `picked-context` together with the body.
266
+
267
+ | Limit | Value |
268
+ | -------------- | ---------- |
269
+ | Time to answer | 60 seconds |
270
+ | Request body | 1 MiB |
271
+ | Answer body | 4 MiB |
272
+
273
+ Picked forwards the `content-type`, `cache-control` and `mcp-session-id` headers of the
274
+ answer to the AI agent.
275
+
276
+ ## Delivery
277
+
278
+ These rules apply to lifecycle events, app events and tool calls.
279
+
280
+ | Rule | Value |
281
+ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
282
+ | Time to answer | 15 seconds for the full request, resends included. |
283
+ | Resends | Only for a request with an `idempotency-key` header: app events and tool calls. Picked sends such a request three times at most, after a `408`, a `429`, a `5xx` or no answer. |
284
+ | Redirects | Picked does not go to a new address that a `3xx` answer gives. A `3xx` answer is not a `2xx` answer. |
285
+ | Answer body | Picked reads 256 KiB of the answer at most. |
286
+
287
+ The `endpoint` must be a URL that the [manifest](/reference/apps/manifest#endpoint) permits.
288
+ Before each request, Picked also checks the address:
289
+
290
+ | Picked environment | Allowed addresses |
291
+ | ------------------ | ------------------------------------------------------------------------------------ |
292
+ | Production | A host that resolves to public `IP` addresses only, on port 443, port 80 or no port. |
293
+ | Local | The same, and also a loopback host on any port. |
294
+
295
+ So an app that you install from the production dashboard must have a public HTTPS
296
+ endpoint. An `http://localhost` endpoint works only with a Picked API that runs on your
297
+ computer.
298
+
299
+ ## Installation tokens
300
+
301
+ An installation token is a credential for the GraphQL API at `<apiUrl>/api/graphql`. Send it
302
+ in the `X-API-Key` header:
303
+
304
+ ```http
305
+ POST /api/graphql HTTP/1.1
306
+ Host: api.picked.app
307
+ Content-Type: application/json
308
+ X-API-Key: <token>
309
+ ```
310
+
311
+ | Property | Value |
312
+ | ------------ | ------------------------------------------------------------------------------------ |
313
+ | Life | One hour after Picked makes it. |
314
+ | Scopes | The `grantedScopes` of the installation. |
315
+ | Labels | Reads and writes the labels of the installation, with no scope. Reads secret values. |
316
+ | Installation | Reads `appInstallation` for its own installation, with no scope. |
317
+
318
+ The app gets a token in two ways:
319
+
320
+ - In the `token` field of each request from Picked.
321
+ - From `appInstallationTokenCreate`, with a
322
+ [`picked-app-assertion` token](#the-picked-app-assertion-token).
323
+
324
+ ### The `appInstallationTokenCreate` mutation
325
+
326
+ ```graphql
327
+ mutation AppInstallationToken($input: AppInstallationTokenCreateInput!) {
328
+ appInstallationTokenCreate(input: $input) {
329
+ token
330
+ expiresAt
331
+ }
332
+ }
333
+ ```
334
+
335
+ Send it to `<apiUrl>/api/graphql` with a `picked-app-assertion` token in the
336
+ `picked-app-assertion` header. The operation accepts no other credential.
337
+
338
+ | Input field | Type | Description |
339
+ | ---------------- | -------- | ------------------------------------------------------------------------------------------------------------ |
340
+ | `installationId` | `ID!` | The installation. It must be the `sub` of the `picked-app-assertion` token. |
341
+ | `sessionToken` | `String` | The session token of the person that the app answers. Required when the installation has no `offlineAccess`. |
342
+
343
+ | Result field | Type | Description |
344
+ | ------------ | ----------- | ------------------------------------- |
345
+ | `token` | `String!` | The installation token. |
346
+ | `expiresAt` | `DateTime!` | One hour after Picked made the token. |
347
+
348
+ | Error message | Cause |
349
+ | -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
350
+ | `Authentication required` | The request has no `picked-app-assertion` header. The error code is `UNAUTHENTICATED`. |
351
+ | `Authentication failed: The app assertion does not verify` | No installation has the ID in `sub`. Or no key of the app of that installation signed the token. Or the token has incorrect fields, is expired, or Picked accepted it before. The error code is `UNAUTHENTICATED`. |
352
+ | `The app assertion names another installation` | `installationId` is not the `sub` of the token. |
353
+ | `The installation has no offline access; use the token Picked sends with each request` | The installation has no `offlineAccess`, and `sessionToken` is absent, not valid, or for another installation. |
354
+
355
+ ## The `picked-app-assertion` token
356
+
357
+ The `picked-app-assertion` token is an `EdDSA` `JWT`. The app signs it with its own `Ed25519`
358
+ private key.
359
+
360
+ Header:
361
+
362
+ | Field | Value |
363
+ | ----- | ------------------------------------ |
364
+ | `alg` | `EdDSA` |
365
+ | `typ` | `JWT` |
366
+ | `kid` | The ID of the public key of the app. |
367
+
368
+ Fields:
369
+
370
+ | Field | Type | Value |
371
+ | ----- | -------- | ---------------------------------------------------------------------------- |
372
+ | `sub` | `string` | The ID of the installation that the app acts for. |
373
+ | `aud` | `string` | The `apiUrl` of the Picked API that gets the token. |
374
+ | `iat` | `number` | The time at which the app made the token, in `unix` seconds. |
375
+ | `exp` | `number` | The time of expiry, in `unix` seconds. `@picked/app-kit` sets `iat` plus 60. |
376
+ | `jti` | `string` | A unique ID. Picked accepts each `jti` one time only. |
377
+
378
+ Picked refuses the token when `exp` is more than 300 seconds after `iat`. It also refuses the
379
+ token after `exp`.
380
+
381
+ This `Node.js` example makes a token without `@picked/app-kit`:
382
+
383
+ ```js
384
+ import { createHash, createPrivateKey, createPublicKey, randomUUID, sign } from 'node:crypto'
385
+
386
+ const privateKey = createPrivateKey(process.env.PICKED_APP_PRIVATE_KEY.replaceAll('\\n', '\n'))
387
+ const publicKey = createPublicKey(privateKey).export({ format: 'jwk' }).x
388
+ const kid = createHash('sha256')
389
+ .update(Buffer.from(publicKey, 'base64url'))
390
+ .digest('base64url')
391
+ .slice(0, 16)
392
+
393
+ const encode = (value) => Buffer.from(JSON.stringify(value)).toString('base64url')
394
+
395
+ export function createAppAssertion(installationId, apiUrl) {
396
+ const now = Math.floor(Date.now() / 1000)
397
+ const header = encode({ alg: 'EdDSA', typ: 'JWT', kid })
398
+ const claims = encode({
399
+ sub: installationId,
400
+ aud: apiUrl,
401
+ iat: now,
402
+ exp: now + 60,
403
+ jti: randomUUID(),
404
+ })
405
+ const signature = sign(null, Buffer.from(`${header}.${claims}`), privateKey)
406
+ return `${header}.${claims}.${signature.toString('base64url')}`
407
+ }
408
+ ```
409
+
410
+ ## Public keys of an app
411
+
412
+ | Property | Value |
413
+ | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
414
+ | Private key format | The `base64` of the `PKCS#8 DER`, on one line. A `PKCS#8 PEM` also works, and can have `\n` in place of line breaks. |
415
+ | Public key format | The `base64url` of the 32 raw bytes of the `Ed25519` public key. |
416
+ | Key ID | The first 16 characters of the `base64url` of the SHA-256 of the 32 raw bytes. |
417
+ | Keys for each app | Two at most. When an app holds two keys, the next key fails with `An app holds at most 2 public keys; remove one before adding another`. |
418
+
419
+ `picked app keys generate` makes a private key and its public key. These register a public
420
+ key: `picked app deploy`, `picked app dev`, `appDeploy` with `publicKey`, and
421
+ `appPublicKeyAdd`. A key that the app holds already stays as it is. `appPublicKeyRemove`
422
+ removes a key. After that, each `picked-app-assertion` token from that key fails.
423
+
424
+ ## Session tokens
425
+
426
+ A session token is an `EdDSA` `JWT` that Picked signs with the same key as its requests. The
427
+ dashboard gets one with `appSessionTokenCreate`, and gives it to a page of the app in
428
+ [`picked:context`](#messages-between-the-page-and-the-dashboard).
429
+
430
+ | Field | Type | Value |
431
+ | ---------------- | -------- | ------------------------------------------------------------------------------- |
432
+ | `installationId` | `string` | The installation. |
433
+ | `organizationId` | `string` | The organization of the project. |
434
+ | `projectId` | `string` | The project. |
435
+ | `apiUrl` | `string` | The origin of the Picked API. |
436
+ | `userId` | `string` | The person in the dashboard. |
437
+ | `exp` | `number` | The time of expiry, in `unix` seconds. 600 seconds after Picked made the token. |
438
+
439
+ The header of the token is `{ "alg": "EdDSA", "typ": "JWT", "kid": "<key id>" }`. Verify the
440
+ token with the [public keys of Picked](#public-keys-of-picked), and refuse it after `exp`.
441
+
442
+ `appSessionTokenCreate` needs a signed-in person who holds `organization_apps/read` on the
443
+ project. An API key cannot get a session token.
444
+
445
+ The server functions of `@picked/app-kit` read the session token from an
446
+ `Authorization: Bearer <token>` header on a request from the page. This is a convention of
447
+ `@picked/app-kit`. Picked does not read that request.
448
+
449
+ ## Messages between the page and the dashboard
450
+
451
+ The dashboard shows each slot of the app in an `iframe`. The page and the dashboard send
452
+ these messages with `postMessage`:
453
+
454
+ | Message | From | Data |
455
+ | ---------------- | ------------- | ------------------------------------------------------- |
456
+ | `picked:ready` | The page | `{ "type": "picked:ready" }` |
457
+ | `picked:context` | The dashboard | `{ "type": "picked:context", "context": FrameContext }` |
458
+ | `picked:resize` | The page | `{ "type": "picked:resize", "height": number }` |
459
+
460
+ - The dashboard answers each `picked:ready` with `picked:context`, and a new session token.
461
+ - The dashboard sets the height of the `iframe` to `height` pixels, and 40 pixels at least.
462
+ When the page of an app has one `app-home` slot, its `iframe` fills the page, and the
463
+ dashboard ignores `height`.
464
+ - The dashboard accepts a message only from the `iframe` of the slot, and only from the origin
465
+ of the slot `url`. It sends `picked:context` only to that origin.
466
+
467
+ `FrameContext`:
468
+
469
+ | Field | Type | Description |
470
+ | ------------------ | -------- | ------------------------------------------------------------------------------------------------- |
471
+ | `installationId` | `string` | The installation. |
472
+ | `organizationId` | `string` | The organization of the project. |
473
+ | `organizationSlug` | `string` | The slug of the organization, as in dashboard URLs. |
474
+ | `projectId` | `string` | The project. |
475
+ | `location` | `string` | The slot location: `app-home`, `workspace-prepublish-actions` or `workspace-postpublish-actions`. |
476
+ | `appVersion` | `number` | The version that the installation uses. |
477
+ | `sessionToken` | `string` | A session token for the person and the installation. |
478
+ | `theme` | `string` | `light` or `dark`. |
479
+
480
+ The `iframe` has the `sandbox` value
481
+ `allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox`. The
482
+ dashboard does not show a slot whose URL has the same origin as the dashboard, or a URL that
483
+ does not parse.
484
+
485
+ The server of the app controls which pages can show its pages in an `iframe`, with the
486
+ `frame-ancestors` directive of its `Content-Security-Policy`. See
487
+ [`frame-ancestors`](/reference/apps/environment#frame-ancestors).
488
+
489
+ ## Related
490
+
491
+ - [About app authentication](/explanation/app-authentication) — why the protocol has this
492
+ design.
493
+ - [`@picked/app-kit`](/reference/apps/app-kit) — the functions that implement it.
494
+ - [App manifest](/reference/apps/manifest) — `endpoint`, `workflowTools`, `mcp`, `events` and
495
+ `slots`.
496
+ - [Authentication](/reference/management-api/authentication) — the other credentials of the
497
+ API.