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.
- package/dist/.tsbuildinfo +1 -1
- package/docs/explanation/app-authentication.md +178 -0
- package/docs/explanation/apps.md +169 -0
- package/docs/explanation/conditions-and-the-logic-engine.md +12 -2
- package/docs/explanation/feature-flag-allocation.md +5 -3
- package/docs/how-to/apps/add-a-page-to-the-dashboard.md +257 -0
- package/docs/how-to/apps/add-a-workflow-tool.md +199 -0
- package/docs/how-to/apps/add-an-mcp-server-to-an-app.md +210 -0
- package/docs/how-to/apps/connect-a-third-party-service-with-oauth.md +307 -0
- package/docs/how-to/apps/create-an-app-in-the-dashboard.md +162 -0
- package/docs/how-to/apps/deploy-an-app.md +201 -0
- package/docs/how-to/apps/develop-an-app-locally.md +152 -0
- package/docs/how-to/apps/host-an-app-on-vercel.md +226 -0
- package/docs/how-to/apps/install-an-app.md +116 -0
- package/docs/how-to/apps/link-to-an-installation-from-your-site.md +134 -0
- package/docs/how-to/apps/read-project-data-from-an-app.md +225 -0
- package/docs/how-to/apps/rotate-an-app-key.md +130 -0
- package/docs/how-to/apps/run-code-when-a-workspace-publishes.md +148 -0
- package/docs/how-to/apps/store-data-for-an-installation.md +230 -0
- package/docs/how-to/apps/test-an-app.md +359 -0
- package/docs/how-to/apps/upgrade-or-uninstall-an-app.md +97 -0
- package/docs/how-to/apps/use-an-app-tool-in-a-workflow.md +112 -0
- package/docs/index.md +6 -3
- package/docs/reference/apps/app-kit.md +811 -0
- package/docs/reference/apps/environment.md +116 -0
- package/docs/reference/apps/manifest.md +311 -0
- package/docs/reference/apps/protocol.md +497 -0
- package/docs/reference/dashboard/apps.md +504 -0
- package/docs/reference/dashboard/external-apis.md +5 -0
- package/docs/reference/dashboard/features.mdx +5 -5
- package/docs/reference/dashboard/labels.md +25 -8
- package/docs/reference/dashboard/lead-search.md +6 -6
- package/docs/reference/dashboard/reports.mdx +13 -5
- package/docs/reference/dashboard/workflow-tools.md +14 -0
- package/docs/reference/glossary.md +153 -140
- package/docs/reference/management-api/authentication.md +36 -27
- package/docs/reference/management-api/authorization-and-scopes.md +73 -21
- package/docs/reference/management-api/schema/api-key.md +10 -10
- package/docs/reference/management-api/schema/app.md +726 -0
- package/docs/reference/management-api/schema/auth.md +7 -7
- package/docs/reference/management-api/schema/common.md +54 -35
- package/docs/reference/management-api/schema/feature.md +1 -1
- package/docs/reference/management-api/schema/feedback.md +1 -1
- package/docs/reference/management-api/schema/index.md +35 -20
- package/docs/reference/management-api/schema/label.md +31 -8
- package/docs/reference/management-api/schema/organization.md +66 -66
- package/docs/reference/management-api/schema/project.md +5 -5
- package/docs/reference/management-api/schema/report.md +1 -1
- package/docs/reference/management-api/schema/shopify.md +19 -19
- package/docs/reference/management-api/schema/tenant-branding.md +16 -0
- package/docs/reference/management-api/schema/workflow.md +6 -1
- package/docs/reference/management-api/schema/workspace.md +2 -2
- package/docs/reference/sdk/analytics-events.md +42 -36
- package/docs/reference/sdk/conditions.md +3 -3
- package/docs/reference/sdk/fields.md +5 -4
- package/docs/reference/sdk/index.md +4 -4
- package/docs/reference/sdk/plugins/create-experience.md +11 -9
- package/docs/reference/sdk/plugins/hotjar.md +2 -2
- package/docs/reference/sdk/plugins/sentry.md +2 -2
- package/docs/reference/sdk/plugins/shopify.md +2 -2
- package/docs/reference/sdk/predicates.md +5 -5
- package/docs/reference/sdk/ssr/index.md +4 -3
- package/docs/reference/sdk/ssr/rendering-and-hydration.md +30 -0
- package/docs/reference/sdk/type-generation.md +24 -19
- package/docs/reference/tools/admin-api-client.md +15 -0
- package/docs/reference/tools/cli.md +192 -41
- package/docs/reference/tools/mcp.md +30 -9
- package/docs/tutorials/first-app.md +308 -0
- package/package.json +4 -4
- package/docs/explanation/how-pickedql-works.md +0 -76
- package/docs/how-to/analytics/index.md +0 -324
- package/docs/reference/management-api/schema/analytics.md +0 -75
- package/docs/reference/pickedql/data-sources.md +0 -174
- package/docs/reference/pickedql/dimensions.md +0 -103
- package/docs/reference/pickedql/filtering.md +0 -64
- package/docs/reference/pickedql/index.md +0 -18
- package/docs/reference/pickedql/schema.md +0 -172
- package/docs/reference/pickedql/virtual-functions.md +0 -248
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: explanation
|
|
3
|
+
layout: docs
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# About app authentication
|
|
7
|
+
|
|
8
|
+
Picked sends requests to the server of an app, and the app sends requests to Picked. Each
|
|
9
|
+
side must know that a request comes from the other side. This page answers two questions.
|
|
10
|
+
How does each side identify the other? Why does the server of an app hold one private
|
|
11
|
+
key and no other data?
|
|
12
|
+
|
|
13
|
+
The exact headers, fields and time limits are in [App protocol](/reference/apps/protocol).
|
|
14
|
+
|
|
15
|
+
## Two private keys, and no shared secret
|
|
16
|
+
|
|
17
|
+
Picked and each app have their own `Ed25519` private key and public key. Each side keeps its private key, and
|
|
18
|
+
gives only its public key to the other side.
|
|
19
|
+
|
|
20
|
+
- **Picked signs each request that it sends to an app.** Picked publishes its public keys at
|
|
21
|
+
`/.well-known/picked-app-keys.json` on its API. The app gets them from there. It uses them
|
|
22
|
+
to verify that Picked signed each request.
|
|
23
|
+
- **The app signs its requests to Picked.** The app registers its public key with Picked.
|
|
24
|
+
`picked app deploy` registers it. A person can also add the key on the page of the app in
|
|
25
|
+
the dashboard. Picked uses that key to verify the requests of the app.
|
|
26
|
+
|
|
27
|
+
The result: Picked holds no secret of an app. If a person gets a copy of the data of Picked,
|
|
28
|
+
that copy contains no credential of an app. The app can verify that Picked signed a request,
|
|
29
|
+
but the app cannot sign as Picked. In the same way, Picked cannot sign as the app.
|
|
30
|
+
|
|
31
|
+
A shared secret is the alternative. Picked and the app then sign with the same value. That
|
|
32
|
+
design is less work. But each side can then sign as the other side. Picked must also keep a
|
|
33
|
+
secret for each app, and a copy of that store in the wrong hands would expose every app.
|
|
34
|
+
|
|
35
|
+
## The `picked-app-assertion` token
|
|
36
|
+
|
|
37
|
+
When the app calls Picked, it first makes a short token, and signs it with its private key.
|
|
38
|
+
The app sends this token in the `picked-app-assertion` header. The token identifies the
|
|
39
|
+
installation that the app acts for, and the Picked API that the token is for.
|
|
40
|
+
|
|
41
|
+
Picked accepts each `picked-app-assertion` token one time only, for that API only, and for
|
|
42
|
+
five minutes at most. Picked also uses the keys of the app of that installation to verify it.
|
|
43
|
+
So a copy of the token is of no use to another person. An app also cannot act for an
|
|
44
|
+
installation of a different app.
|
|
45
|
+
|
|
46
|
+
The `picked-app-assertion` token gives access to one operation only:
|
|
47
|
+
`appInstallationTokenCreate`. That operation gives the app an installation token. The app then
|
|
48
|
+
calls the API with that token, the same as other clients.
|
|
49
|
+
|
|
50
|
+
## Installation tokens
|
|
51
|
+
|
|
52
|
+
An installation token acts as the installation. It carries the scopes that the installation
|
|
53
|
+
got when a person accepted the app. It can also read and write the labels of the
|
|
54
|
+
installation. It expires one hour after Picked makes it.
|
|
55
|
+
|
|
56
|
+
Picked puts a new installation token in each request that it sends to an app. Examples are a
|
|
57
|
+
workflow tool call, an event, or a request from the AI agent. So an app that only answers
|
|
58
|
+
Picked does not have to make a token. The token in the request is enough.
|
|
59
|
+
|
|
60
|
+
This is the default, and it is deliberate. An app acts on a project while Picked asks it to
|
|
61
|
+
act, and for one hour after that at most. When the app does not get requests, it has no
|
|
62
|
+
access to the project.
|
|
63
|
+
|
|
64
|
+
## Session tokens
|
|
65
|
+
|
|
66
|
+
A page of an app in the dashboard comes from the server of the app. The page must tell its
|
|
67
|
+
server which person looks at it, and on which installation. For this, the dashboard gets a
|
|
68
|
+
session token from Picked, and gives it to the page. The page sends it to the server of the
|
|
69
|
+
app.
|
|
70
|
+
|
|
71
|
+
Picked signs the session token with its own key. The server of the app uses the public keys
|
|
72
|
+
of Picked to verify it. The app cannot make a session token. So a valid session token shows
|
|
73
|
+
that a person is in the dashboard on that installation now. A session token expires after ten
|
|
74
|
+
minutes.
|
|
75
|
+
|
|
76
|
+
## Access outside a request
|
|
77
|
+
|
|
78
|
+
Some apps must act when no person is in the dashboard and Picked sends no request. An example
|
|
79
|
+
is an app that copies data at fixed times. Such an app asks for `offlineAccess` in its
|
|
80
|
+
manifest. The person who installs it sees this in the consent window, below the scopes.
|
|
81
|
+
|
|
82
|
+
The difference shows in `appInstallationTokenCreate`:
|
|
83
|
+
|
|
84
|
+
- **With `offlineAccess`**, the app can get a token at any time.
|
|
85
|
+
- **Without `offlineAccess`**, the app must also send a session token for that installation.
|
|
86
|
+
|
|
87
|
+
Without `offlineAccess`, an app can get a token only while a person uses its page. The app
|
|
88
|
+
cannot go around this rule, because it cannot make a session token. The rule therefore holds
|
|
89
|
+
against the app itself, and not only against other persons.
|
|
90
|
+
|
|
91
|
+
## OAuth with another service
|
|
92
|
+
|
|
93
|
+
Many apps connect an installation to another service with OAuth. The person clicks a button
|
|
94
|
+
on the page of the app, and the service opens in a new window. Some time later, the service
|
|
95
|
+
sends the browser back to the callback address of the app. That callback is a new request. It
|
|
96
|
+
does not come from Picked, and it carries no session token.
|
|
97
|
+
|
|
98
|
+
Therefore the app must send its state through the service, and get it back on the callback.
|
|
99
|
+
The state contains the installation, and the session token of the person who started the
|
|
100
|
+
connection. The app encrypts the state with a key that it derives from its private key. The
|
|
101
|
+
service cannot read or change the state, and the app needs no second secret. On the
|
|
102
|
+
callback, the app opens the state. Then it gets an installation token with that session
|
|
103
|
+
token, and keeps the grant of the service in a label.
|
|
104
|
+
|
|
105
|
+
The session token never goes in an address. The page gives it to the new window with a
|
|
106
|
+
message, and the window sends it to the server of the app in a header. An address can go
|
|
107
|
+
into the history of the browser, into logs, or to a different site.
|
|
108
|
+
|
|
109
|
+
### Why a cookie binds the flow to one browser
|
|
110
|
+
|
|
111
|
+
A state that is correct is not enough. A person can start a connection, and then send the
|
|
112
|
+
address of the service to a different person. If the second person gives access, the callback
|
|
113
|
+
keeps the account of the second person in the installation of the first person. The same
|
|
114
|
+
problem occurs when a different person sends a callback address with their own code to a person
|
|
115
|
+
who is signed in.
|
|
116
|
+
|
|
117
|
+
So the start of the flow sets a cookie in the browser, and puts the same value in the state.
|
|
118
|
+
The callback completes only when the browser sends that cookie. A different browser does not
|
|
119
|
+
have it. The callback then deletes the cookie, so that the same callback cannot complete two
|
|
120
|
+
times.
|
|
121
|
+
|
|
122
|
+
The cookie has `HttpOnly`, so a script cannot read it, and `SameSite=Lax`, so the browser
|
|
123
|
+
sends it when the service sends the browser back. Its name starts with `__Host-`. The browser
|
|
124
|
+
then keeps it for the host of the app only, and only over `https:`.
|
|
125
|
+
[OAuth cookie](/reference/apps/app-kit#oauth-cookie) gives the name on a local `http:` address.
|
|
126
|
+
|
|
127
|
+
The cost is one flow at a time for each browser and app. A second start replaces the cookie,
|
|
128
|
+
and the first flow fails. The flow also fails when the callback is on a different host from
|
|
129
|
+
the start.
|
|
130
|
+
|
|
131
|
+
The state and the cookie expire after ten minutes. The session token in the state expires
|
|
132
|
+
ten minutes after Picked made it.
|
|
133
|
+
|
|
134
|
+
## Why the app holds no other data
|
|
135
|
+
|
|
136
|
+
The server of an app needs only its private key. Each request from Picked identifies the
|
|
137
|
+
installation and the address of the Picked API to call back. The data of each installation
|
|
138
|
+
stays in Picked, as labels. So the app can run as a function with no files and no database.
|
|
139
|
+
|
|
140
|
+
When the app marks a label as secret, Picked keeps the value in a secure store. Only the
|
|
141
|
+
installation can read the value back, with its own token. A person who reads the labels of
|
|
142
|
+
the installation sees an empty value. This choice is the responsibility of the author. A
|
|
143
|
+
refresh token in a label that is not secret is visible to each person who can read the
|
|
144
|
+
installation.
|
|
145
|
+
|
|
146
|
+
[About apps](/explanation/apps#why-an-app-keeps-its-data-in-picked) tells what happens to the
|
|
147
|
+
labels when a person removes the app.
|
|
148
|
+
|
|
149
|
+
## Two keys for each app
|
|
150
|
+
|
|
151
|
+
An app can hold two public keys at most. With two keys, an app can replace its key and
|
|
152
|
+
continue to work. The app registers the next public key first, and then holds two keys.
|
|
153
|
+
Picked accepts tokens that either key signed. The server of the app then moves to the next
|
|
154
|
+
private key.
|
|
155
|
+
|
|
156
|
+
Last, the app removes the old public key. See
|
|
157
|
+
[How to rotate an app key](/how-to/apps/rotate-an-app-key).
|
|
158
|
+
|
|
159
|
+
Picked can replace its own key in the same way. After it changes its private key, it can
|
|
160
|
+
continue to publish the old public key. Then a request that the old key signed still
|
|
161
|
+
verifies.
|
|
162
|
+
|
|
163
|
+
## The cost of this design
|
|
164
|
+
|
|
165
|
+
Each app must get the public keys of Picked, and keep them for a short time. The app gets the
|
|
166
|
+
keys again when a request names a key that it does not know. If an app cannot get to the
|
|
167
|
+
Picked API, it cannot verify a request that a new key signed.
|
|
168
|
+
|
|
169
|
+
The labels of an installation also have limits. See
|
|
170
|
+
[How to store data for an installation](/how-to/apps/store-data-for-an-installation).
|
|
171
|
+
|
|
172
|
+
## Related
|
|
173
|
+
|
|
174
|
+
- [App protocol](/reference/apps/protocol) — the headers, the fields and the time limits.
|
|
175
|
+
- [Connect another service with OAuth](/how-to/apps/connect-a-third-party-service-with-oauth)
|
|
176
|
+
— an OAuth flow in an app.
|
|
177
|
+
- [How to rotate an app key](/how-to/apps/rotate-an-app-key) — replace the key of an app.
|
|
178
|
+
- [About apps](/explanation/apps) — versions, installations and consent.
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: explanation
|
|
3
|
+
layout: docs
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# About apps
|
|
7
|
+
|
|
8
|
+
An app connects Picked to another service. It can add a page to the dashboard. It can also
|
|
9
|
+
add panels to the window that publishes a workspace. It can add workflow tools, and tools
|
|
10
|
+
for the AI agent in the dashboard.
|
|
11
|
+
|
|
12
|
+
This page answers two questions. What is an app? Why does
|
|
13
|
+
Picked install an app on each project at one fixed version?
|
|
14
|
+
|
|
15
|
+
## App, version and installation
|
|
16
|
+
|
|
17
|
+
Three things carry the name "app", and each one has a different owner.
|
|
18
|
+
|
|
19
|
+
- **The app** belongs to one organization. That organization builds the app, deploys it, and
|
|
20
|
+
holds its keys. A handle identifies the app in the organization, for example
|
|
21
|
+
`lead-insights`.
|
|
22
|
+
- **A version** is one manifest that the organization deployed. You cannot change a version.
|
|
23
|
+
When the organization deploys a different manifest, Picked adds the next version number.
|
|
24
|
+
When the manifest is the same as the newest version of that kind, Picked adds no version.
|
|
25
|
+
See [Release versions and dev versions](#release-versions-and-dev-versions).
|
|
26
|
+
- **An installation** is one app on one project, at one version. A project holds one
|
|
27
|
+
installation of an app at most. The installation has its own slug in the project, its own
|
|
28
|
+
scopes, and its own data.
|
|
29
|
+
|
|
30
|
+
Therefore, the organization that builds an app and the project that uses it can be different. The
|
|
31
|
+
members of a project decide what an app can do on that project. The author of the app
|
|
32
|
+
decides what the next version asks for.
|
|
33
|
+
|
|
34
|
+
## One manifest holds the whole app
|
|
35
|
+
|
|
36
|
+
The manifest declares every part of the app together. It holds the address of the server of
|
|
37
|
+
the app, and the pages of the app. It also holds the workflow tools, the MCP server, the
|
|
38
|
+
events that the app receives, and the scopes that the app asks for. See
|
|
39
|
+
[App manifest](/reference/apps/manifest) for each field.
|
|
40
|
+
|
|
41
|
+
These parts change together. A new workflow tool can need a new scope. A new page can need a
|
|
42
|
+
new tool on the server. When one version holds all of them, a person can check that
|
|
43
|
+
version, accept it, and upgrade to it as one item. When the parts are separate, a project
|
|
44
|
+
gets each change at a different time. Then nobody accepts the full set of access that the
|
|
45
|
+
app uses.
|
|
46
|
+
|
|
47
|
+
## Why an installation stays on its version
|
|
48
|
+
|
|
49
|
+
A new version does not change an installation. The installation stays on its version until a
|
|
50
|
+
person on that project upgrades it. The **Apps** page of the project then shows **New version
|
|
51
|
+
available**. **Upgrade** opens the same consent window that an installation opens.
|
|
52
|
+
|
|
53
|
+
This rule keeps the control of a project with the people on that project. A new version
|
|
54
|
+
cannot add a scope, a tool, or a new server address to a project if those people do not approve it.
|
|
55
|
+
|
|
56
|
+
The rule has a cost for the author of the app. Different projects can stay on different
|
|
57
|
+
versions for a long time. A project that never upgrades continues to call the endpoint of its
|
|
58
|
+
own version. Therefore, the server of an app must continue to serve each version that a project
|
|
59
|
+
still uses.
|
|
60
|
+
|
|
61
|
+
## Release versions and dev versions
|
|
62
|
+
|
|
63
|
+
Each version is a release version or a dev version. The API calls this the `channel` of the
|
|
64
|
+
version.
|
|
65
|
+
|
|
66
|
+
- **`RELEASE`** versions are for every project that can install the app.
|
|
67
|
+
`picked app deploy` writes a release version.
|
|
68
|
+
- **`DEV`** versions come from `picked app dev`. Only the projects of the organization that
|
|
69
|
+
owns the app can install a dev version. The dashboard shows **Dev** next to it.
|
|
70
|
+
|
|
71
|
+
A new installation uses the newest release version. Before the first release, the
|
|
72
|
+
organization that owns the app installs the newest dev version. An upgrade moves to the
|
|
73
|
+
newest version of the same kind. So a dev installation moves to the next dev version. A
|
|
74
|
+
release installation never gets a dev version.
|
|
75
|
+
|
|
76
|
+
With dev versions, an author can try a version on a real project before other projects can
|
|
77
|
+
get it. The installation, the consent and the upgrade are the same as for a release. See
|
|
78
|
+
[the guide for a local server](/how-to/apps/develop-an-app-locally).
|
|
79
|
+
|
|
80
|
+
## Consent
|
|
81
|
+
|
|
82
|
+
An app asks for scopes in its manifest, for example `organization_leads/read`. These are the
|
|
83
|
+
same scopes that an API key or a member role holds. See
|
|
84
|
+
[Authorization and scopes](/reference/management-api/authorization-and-scopes).
|
|
85
|
+
|
|
86
|
+
When a person installs or upgrades an app, the dashboard shows each scope that the version
|
|
87
|
+
asks for. For an upgrade, it also marks each new scope as **New**. It also shows each scope
|
|
88
|
+
that the version no longer asks for. The person accepts the full list, or does not continue.
|
|
89
|
+
A person cannot accept only a part of the list.
|
|
90
|
+
|
|
91
|
+
Three rules make this consent real:
|
|
92
|
+
|
|
93
|
+
- **The accepted list must be the list of the version.** The request carries the scopes that
|
|
94
|
+
the person accepted. If the version asks for a different list, the request fails. So a
|
|
95
|
+
version cannot get a scope that the person did not see.
|
|
96
|
+
- **You cannot grant a scope that you do not hold.** The person must hold each scope at that
|
|
97
|
+
project. If not, the request fails with `Cannot grant scopes you do not hold`. So an app
|
|
98
|
+
never gets more access than the person who accepted it.
|
|
99
|
+
- **Access outside a request is a separate grant.** An app that must work by itself, for
|
|
100
|
+
example to copy data at fixed times, asks for `offlineAccess`. The consent window then
|
|
101
|
+
tells the person, below the scopes. The person must accept it with the scopes. See
|
|
102
|
+
[Access outside a request](/explanation/app-authentication#access-outside-a-request).
|
|
103
|
+
|
|
104
|
+
The app must also accept. Picked tells the server of the app about each installation and each
|
|
105
|
+
upgrade. If the server refuses, or if Picked cannot get to it, Picked undoes the change. It
|
|
106
|
+
removes a new installation. It moves an upgraded installation back to its old version and
|
|
107
|
+
its old scopes. Therefore, a project never has an installation that its app does not know
|
|
108
|
+
about.
|
|
109
|
+
|
|
110
|
+
When the manifest has no `endpoint`, Picked sends no message, and the change stays.
|
|
111
|
+
|
|
112
|
+
## Private apps and public apps
|
|
113
|
+
|
|
114
|
+
An app is private to the organization that owns it. Only the projects of that organization
|
|
115
|
+
can install it.
|
|
116
|
+
|
|
117
|
+
A public app is available to every organization. Only Picked can make an app public. This
|
|
118
|
+
change needs the `apps/publish` scope, which only Picked holds. The app must also have a
|
|
119
|
+
release version. The **Apps** page of a project shows **Published by Picked** on a public app.
|
|
120
|
+
|
|
121
|
+
Each organization that installs a public app gets its own installation, with its own consent
|
|
122
|
+
and its own data. The author of the app does not get access to a project until a person on
|
|
123
|
+
that project installs the app.
|
|
124
|
+
|
|
125
|
+
## Apps, external APIs and MCP connections
|
|
126
|
+
|
|
127
|
+
A project can also connect to other services without an app.
|
|
128
|
+
|
|
129
|
+
- An [external API](/reference/dashboard/external-apis) is an origin that one project
|
|
130
|
+
registers for the **External API** workflow node. The project holds the origin and the
|
|
131
|
+
credential.
|
|
132
|
+
- An MCP connection is an MCP server that one project registers for the AI agent. The project
|
|
133
|
+
holds the URL and the credential.
|
|
134
|
+
|
|
135
|
+
Both belong to one project, and a person on that project configures each one. An app is
|
|
136
|
+
different. Its author makes workflow tools, pages and an MCP server as one version, and
|
|
137
|
+
many projects can install it. An app never adds an external API or an MCP connection to a
|
|
138
|
+
project. When you remove an app, its tools stop. The external APIs and the MCP connections of
|
|
139
|
+
the project do not change.
|
|
140
|
+
|
|
141
|
+
An external API is a good choice when one project calls one service with its own credential.
|
|
142
|
+
An app is a good choice when the same connection must work in many projects. An app is also
|
|
143
|
+
the choice when the connection needs a page in the dashboard.
|
|
144
|
+
|
|
145
|
+
## Why an app keeps its data in Picked
|
|
146
|
+
|
|
147
|
+
An app often must keep data for each installation. Examples are the token of another
|
|
148
|
+
service, or the list of projects to deploy. Picked keeps this data for the app, as
|
|
149
|
+
[labels](/reference/dashboard/labels) on the installation. Therefore, the server of the app needs
|
|
150
|
+
no database. It holds one private key. Each request from Picked identifies the installation
|
|
151
|
+
and the address of Picked to call back.
|
|
152
|
+
|
|
153
|
+
Labels also make removal complete. When a person removes an app, Picked tells the app first,
|
|
154
|
+
while the app can still read its labels. Therefore, an app that holds a grant at another service
|
|
155
|
+
can revoke it there. Then Picked removes the labels and the tokens of the installation. Picked
|
|
156
|
+
removes them also when the app does not answer.
|
|
157
|
+
|
|
158
|
+
An app can mark a label as secret. See
|
|
159
|
+
[Why the app holds no other data](/explanation/app-authentication#why-the-app-holds-no-other-data).
|
|
160
|
+
|
|
161
|
+
## Related
|
|
162
|
+
|
|
163
|
+
- [How to install an app](/how-to/apps/install-an-app) — install an app on a project.
|
|
164
|
+
- [How to upgrade or uninstall an app](/how-to/apps/upgrade-or-uninstall-an-app) — move to a new
|
|
165
|
+
version, or uninstall an app.
|
|
166
|
+
- [App manifest](/reference/apps/manifest) — every field of a manifest.
|
|
167
|
+
- [Apps](/reference/dashboard/apps) — the pages of the dashboard for apps.
|
|
168
|
+
- [About app authentication](/explanation/app-authentication) — how Picked and an app identify
|
|
169
|
+
each other.
|
|
@@ -45,7 +45,7 @@ the browser inside the published snapshot. A function cannot travel that way.
|
|
|
45
45
|
| --- | --- |
|
|
46
46
|
| **Responses** | The values your visitors send through the fields of the current experience. |
|
|
47
47
|
| **Actions** | The actions that ran during the flow. |
|
|
48
|
-
| **Feature flags** |
|
|
48
|
+
| **Feature flags** | The bucket of each feature flag for this visitor: `true`, `false`, or the value of one variant. |
|
|
49
49
|
| **Location** | The parts of the current URL: pathname, search parameters, hostname, and hash. |
|
|
50
50
|
|
|
51
51
|
Each one is state the SDK already holds, which is why a rule evaluates without a network
|
|
@@ -54,7 +54,7 @@ request.
|
|
|
54
54
|
## Predicates are the escape hatch
|
|
55
55
|
|
|
56
56
|
The four sources above cover what Picked knows. They do not cover what *your application*
|
|
57
|
-
knows: a cart total, an account level, or the profile of a signed-in
|
|
57
|
+
knows: a cart total, an account level, or the profile of a signed-in visitor.
|
|
58
58
|
|
|
59
59
|
A **predicate** gives you that. It is a function that you register on the client, and a
|
|
60
60
|
rule invokes it by name:
|
|
@@ -79,6 +79,16 @@ The client takes two gates, and they answer different questions:
|
|
|
79
79
|
| Precondition | Must Picked start at all? |
|
|
80
80
|
| Condition | Is this visitor eligible? |
|
|
81
81
|
|
|
82
|
+
The SDK keeps the last result of the condition as `isUser` in local storage. The analytics
|
|
83
|
+
events send that value as `is_user` in their `session` context. The condition runs after the
|
|
84
|
+
`app_load` event, and only when the precondition passes. Until it runs, `is_user` holds the
|
|
85
|
+
result from an earlier page, or it is absent.
|
|
86
|
+
|
|
87
|
+
When the result is false, the SDK starts no experience for that visitor. A
|
|
88
|
+
`launchExperienceByKey` or `launchExperienceById` call with `bypassCondition: true` skips
|
|
89
|
+
this gate. An `ExperienceSlot` component in React or Svelte does not read this result. It
|
|
90
|
+
shows an experience only when that experience targets the slot and its own condition passes.
|
|
91
|
+
|
|
82
92
|
A precondition runs at startup, and that has a result which catches people out. A
|
|
83
93
|
precondition that points at a feature flag reads the bucket of that flag, and a read is
|
|
84
94
|
what allocates the visitor. Every visitor is therefore allocated to that flag before
|
|
@@ -190,8 +190,9 @@ moment.
|
|
|
190
190
|
|
|
191
191
|
## What Picked reports for you
|
|
192
192
|
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
Most Picked analytics events carry a `feature_list` context, and a report of your own can
|
|
194
|
+
use it. See [Analytics events](/reference/sdk/analytics-events) for the events that carry
|
|
195
|
+
it. The context describes each feature flag that this visitor resolved: the
|
|
195
196
|
feature flag ID, the name, the version key, and the bucket. Only a resolved feature flag
|
|
196
197
|
appears there, so the context shows what the visitor was exposed to at the time when the
|
|
197
198
|
event fired.
|
|
@@ -207,7 +208,8 @@ bucket does not stay after you close the tab, and Picked can allocate a preview
|
|
|
207
208
|
differently from a production visitor. Treat a preview allocation as disposable.
|
|
208
209
|
|
|
209
210
|
A feature flag that you define in SDK code can ask for the same thing in production with
|
|
210
|
-
`storage: 'session'`. Use it for a short test that must not
|
|
211
|
+
`storage: 'session'`. Use it for a short test that must not stay after the visitor closes
|
|
212
|
+
the tab.
|
|
211
213
|
|
|
212
214
|
## Related
|
|
213
215
|
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: how-to
|
|
3
|
+
layout: docs
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# How to add a page to the dashboard
|
|
7
|
+
|
|
8
|
+
This guide shows you how to show a page of your app in the Picked dashboard. The page can
|
|
9
|
+
be a page of its own in the project, or a part of the publish modal of a workspace.
|
|
10
|
+
|
|
11
|
+
You need an app with a server that uses `@picked/app-kit`, and the private key of the app.
|
|
12
|
+
[Build and install your first app](/tutorials/first-app) makes these.
|
|
13
|
+
|
|
14
|
+
## 1. Declare a slot
|
|
15
|
+
|
|
16
|
+
Add a slot to `slots` in the manifest. The `location` of the slot tells the dashboard where
|
|
17
|
+
to show the page:
|
|
18
|
+
|
|
19
|
+
| `location` | Where the page shows |
|
|
20
|
+
| ------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
21
|
+
| `app-home` | A page of its own in the project, at `/<organization>/<project>/apps/<installation slug>`. |
|
|
22
|
+
| `workspace-prepublish-actions` | The publish modal, above the **Publish** button. |
|
|
23
|
+
| `workspace-postpublish-actions` | The publish modal, after Picked publishes the workspace. |
|
|
24
|
+
|
|
25
|
+
```ts [picked.config.ts]
|
|
26
|
+
import { defineConfig } from '@picked/config/define'
|
|
27
|
+
|
|
28
|
+
const endpoint = process.env.APP_PUBLIC_URL ?? 'http://localhost:4103'
|
|
29
|
+
|
|
30
|
+
export default defineConfig({
|
|
31
|
+
app: {
|
|
32
|
+
handle: 'my-app',
|
|
33
|
+
name: 'My App',
|
|
34
|
+
endpoint,
|
|
35
|
+
slots: [
|
|
36
|
+
{ location: 'app-home', url: `${endpoint}/`, title: 'Settings', height: 320 },
|
|
37
|
+
{
|
|
38
|
+
location: 'workspace-postpublish-actions',
|
|
39
|
+
url: `${endpoint}/publish`,
|
|
40
|
+
title: 'After publish',
|
|
41
|
+
height: 120,
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The `url` must be a URL that the [rule for the endpoint](/reference/apps/manifest#endpoint) permits.
|
|
49
|
+
The page must not have the origin of the dashboard. [Slots](/reference/apps/manifest#slots)
|
|
50
|
+
gives each field.
|
|
51
|
+
|
|
52
|
+
## 2. Serve the page
|
|
53
|
+
|
|
54
|
+
Serve the page with `page` from `@picked/app-kit/server`. `page` sets the
|
|
55
|
+
`content-security-policy` header to `frame-ancestors` with the origins that you give.
|
|
56
|
+
Therefore, only the dashboard can show the page in an `iframe`.
|
|
57
|
+
|
|
58
|
+
Give `page` the `frameAncestors` that `readAppEnvironment` returns. It reads them from
|
|
59
|
+
`PICKED_DASHBOARD_ORIGINS`. With no origins, `page` sends `frame-ancestors 'none'`, and the
|
|
60
|
+
dashboard cannot show the page.
|
|
61
|
+
|
|
62
|
+
```ts [src/server.ts]
|
|
63
|
+
import { readFile } from 'node:fs/promises'
|
|
64
|
+
import { createAppHandler, json, page, readAppEnvironment } from '@picked/app-kit/server'
|
|
65
|
+
import { frameScript, serve } from '@picked/app-kit/node'
|
|
66
|
+
|
|
67
|
+
const port = process.env.APP_PORT ?? '4103'
|
|
68
|
+
const { pickedKeys, frameAncestors } = readAppEnvironment(process.env, port)
|
|
69
|
+
|
|
70
|
+
const handler = createAppHandler({
|
|
71
|
+
pickedKeys,
|
|
72
|
+
async fallback(request) {
|
|
73
|
+
const { pathname } = new URL(request.url)
|
|
74
|
+
if (pathname === '/') {
|
|
75
|
+
const html = await readFile(new URL('./home.html', import.meta.url), 'utf8')
|
|
76
|
+
return page(html, { frameAncestors })
|
|
77
|
+
}
|
|
78
|
+
if (pathname === '/app-kit/frame.js') return frameScript()
|
|
79
|
+
return json({ error: 'not_found' }, 404)
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
serve(handler, Number(port))
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`createAppHandler` sends a request for a path that it does not route to `fallback`. Therefore,
|
|
87
|
+
your pages and the requests from Picked use one server.
|
|
88
|
+
[App environment variables](/reference/apps/environment#frame-ancestors) gives the value of
|
|
89
|
+
`PICKED_DASHBOARD_ORIGINS` for each Picked environment, and the value when you do not set it.
|
|
90
|
+
|
|
91
|
+
## 3. Serve the script of `@picked/app-kit/frame`
|
|
92
|
+
|
|
93
|
+
The page needs the browser build of `@picked/app-kit/frame`. Serve it in one of these ways:
|
|
94
|
+
|
|
95
|
+
- **From your Node server.** Answer `/app-kit/frame.js` with `frameScript()` from
|
|
96
|
+
`@picked/app-kit/node`, as in step 2.
|
|
97
|
+
- **As a static file.** Add `app-kit-copy-frame <dir>` to the build script of your app. It
|
|
98
|
+
copies the script to `<dir>/app-kit/frame.js`. Use the directory that your host serves as
|
|
99
|
+
static files:
|
|
100
|
+
|
|
101
|
+
```json [package.json]
|
|
102
|
+
{
|
|
103
|
+
"scripts": {
|
|
104
|
+
"build": "app-kit-copy-frame public"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- **In a bundle.** If a bundler builds the script of your page, import from
|
|
110
|
+
`@picked/app-kit/frame` in place of `/app-kit/frame.js`.
|
|
111
|
+
|
|
112
|
+
## 4. Connect the page to the dashboard
|
|
113
|
+
|
|
114
|
+
In the page, call `connect()` when the page loads. It resolves with the context of the page. Then call `autoResize()`. It keeps the height of the `iframe` equal to the height of
|
|
115
|
+
your content.
|
|
116
|
+
|
|
117
|
+
```html [src/home.html]
|
|
118
|
+
<!doctype html>
|
|
119
|
+
<html lang="en">
|
|
120
|
+
<head>
|
|
121
|
+
<meta charset="utf-8" />
|
|
122
|
+
<style>
|
|
123
|
+
body {
|
|
124
|
+
font:
|
|
125
|
+
14px system-ui,
|
|
126
|
+
sans-serif;
|
|
127
|
+
margin: 0;
|
|
128
|
+
padding: 12px;
|
|
129
|
+
}
|
|
130
|
+
html[data-theme='dark'] body {
|
|
131
|
+
background: #111;
|
|
132
|
+
color: #eee;
|
|
133
|
+
}
|
|
134
|
+
</style>
|
|
135
|
+
</head>
|
|
136
|
+
<body>
|
|
137
|
+
<p id="status">Loading…</p>
|
|
138
|
+
<script type="module">
|
|
139
|
+
import { autoResize, connect } from '/app-kit/frame.js'
|
|
140
|
+
|
|
141
|
+
const context = await connect()
|
|
142
|
+
document.documentElement.dataset.theme = context.theme
|
|
143
|
+
autoResize()
|
|
144
|
+
|
|
145
|
+
const response = await fetch('/api/me', {
|
|
146
|
+
headers: { authorization: `Bearer ${context.sessionToken}` },
|
|
147
|
+
})
|
|
148
|
+
const body = await response.json()
|
|
149
|
+
document.getElementById('status').textContent = response.ok
|
|
150
|
+
? `Project ${body.projectId}, user ${body.userId}`
|
|
151
|
+
: 'Could not read your session'
|
|
152
|
+
</script>
|
|
153
|
+
</body>
|
|
154
|
+
</html>
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Use these fields of the context:
|
|
158
|
+
|
|
159
|
+
- **`theme`.** `light` or `dark`. Show the page in the color scheme of the dashboard.
|
|
160
|
+
- **`location`.** The `location` of the slot that shows the page.
|
|
161
|
+
- **`projectId`.** The project that has the installation.
|
|
162
|
+
- **`sessionToken`.** A token for your server. Step 5 shows how to use it.
|
|
163
|
+
|
|
164
|
+
[Messages between the page and the dashboard](/reference/apps/protocol#messages-between-the-page-and-the-dashboard)
|
|
165
|
+
gives each field of the context.
|
|
166
|
+
|
|
167
|
+
To show a different page for each slot, give each slot a different `url`. You can also read
|
|
168
|
+
`context.location`.
|
|
169
|
+
|
|
170
|
+
`connect()` works only in the `iframe` of the dashboard. In a page that is not in an
|
|
171
|
+
`iframe`, it returns an error. It accepts messages only from the window that contains the
|
|
172
|
+
`iframe`, and only from the origin of the dashboard. It reads that origin from
|
|
173
|
+
`document.referrer`. If the browser does not send the referrer, give the origin:
|
|
174
|
+
`connect({ dashboardOrigin: 'https://dashboard.picked.app' })`.
|
|
175
|
+
|
|
176
|
+
:::note
|
|
177
|
+
The `iframe` has the `sandbox` attribute
|
|
178
|
+
`allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox`.
|
|
179
|
+
The page keeps its own origin, so it can send requests to your server.
|
|
180
|
+
:::
|
|
181
|
+
|
|
182
|
+
## 5. Identify the person on your server
|
|
183
|
+
|
|
184
|
+
Send the session token to your server in the `Authorization` header, as in step 4. On the
|
|
185
|
+
server, verify it with `readSession`. Add this branch to `fallback`:
|
|
186
|
+
|
|
187
|
+
```ts [src/server.ts]
|
|
188
|
+
if (pathname === '/api/me') {
|
|
189
|
+
const session = await readSession(request, pickedKeys)
|
|
190
|
+
if (session === null) return json({ error: 'unauthenticated' }, 401)
|
|
191
|
+
return json({ userId: session.userId, projectId: session.projectId })
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Import `readSession` from `@picked/app-kit/server`. It returns `null` when the request has
|
|
196
|
+
no token, or when the token is not from Picked or is expired. Otherwise it returns the
|
|
197
|
+
fields of the token, for example `userId`, `installationId` and `projectId`.
|
|
198
|
+
[Session tokens](/reference/apps/protocol#session-tokens) gives each field.
|
|
199
|
+
|
|
200
|
+
A session token expires after 10 minutes. To get a new token, call `connect()` again. The
|
|
201
|
+
dashboard sends a new token each time.
|
|
202
|
+
|
|
203
|
+
Do not use the IDs in the URL or in the body of a request from the page. Use the IDs in
|
|
204
|
+
the session.
|
|
205
|
+
|
|
206
|
+
To call the Picked API for the person who uses the page, give `sessionTokenOf(request)` to
|
|
207
|
+
the installation client.
|
|
208
|
+
[How to read project data from an app](/how-to/apps/read-project-data-from-an-app)
|
|
209
|
+
shows how.
|
|
210
|
+
|
|
211
|
+
## 6. Deploy and open the page
|
|
212
|
+
|
|
213
|
+
1. Deploy a new version of the manifest.
|
|
214
|
+
2. Upgrade the installation to that version.
|
|
215
|
+
3. Open the page.
|
|
216
|
+
|
|
217
|
+
If the project does not have the app, install it in place of step 2. Picked shows the slots
|
|
218
|
+
of the version that the installation uses.
|
|
219
|
+
|
|
220
|
+
Where you open the page depends on its `location`:
|
|
221
|
+
|
|
222
|
+
- **`app-home`.** In the project, open **Apps**. On the tab **Installed**, choose **Open**
|
|
223
|
+
on the app. The name of the app is the heading of the page. When the app has one
|
|
224
|
+
`app-home` slot, the `iframe` fills the page, and the page ignores its height.
|
|
225
|
+
- **`workspace-prepublish-actions`.** Publish a workspace. The page shows in the publish
|
|
226
|
+
modal, above the **Publish** button.
|
|
227
|
+
- **`workspace-postpublish-actions`.** Publish a workspace. The page shows in the modal
|
|
228
|
+
after Picked publishes the workspace.
|
|
229
|
+
|
|
230
|
+
If two or more apps have a slot at one location, the dashboard shows all of them. In the
|
|
231
|
+
publish modal, the `title` of the slot is the heading above the page. Without a `title`, the
|
|
232
|
+
heading is the name of the app.
|
|
233
|
+
|
|
234
|
+
If the dashboard cannot show the page, it shows one of these messages:
|
|
235
|
+
|
|
236
|
+
| Message | Cause |
|
|
237
|
+
| -------------------------------------------------------------------------------- | ------------------------------------------------------- |
|
|
238
|
+
| The error from Picked, or `Could not start the app` | The dashboard did not get a session token for the page. |
|
|
239
|
+
| `This app's page can't be shown: it is served from the dashboard's own address.` | The `url` of the slot has the origin of the dashboard. |
|
|
240
|
+
| `This app's page can't be shown: its address is not a valid URL.` | The `url` of the slot is not a valid URL. |
|
|
241
|
+
|
|
242
|
+
If the `iframe` stays empty, look at the console of the browser. A `frame-ancestors` error
|
|
243
|
+
tells you that `PICKED_DASHBOARD_ORIGINS` does not have the origin of the dashboard.
|
|
244
|
+
|
|
245
|
+
## Related
|
|
246
|
+
|
|
247
|
+
- [App manifest](/reference/apps/manifest#slots) — every field of a slot.
|
|
248
|
+
- [`@picked/app-kit`](/reference/apps/app-kit) — `page`, `readSession`, `connect` and
|
|
249
|
+
`autoResize`.
|
|
250
|
+
- [App protocol](/reference/apps/protocol#messages-between-the-page-and-the-dashboard) —
|
|
251
|
+
the messages between the page and the dashboard, and the session token.
|
|
252
|
+
- [How to read project data from an app](/how-to/apps/read-project-data-from-an-app) — call
|
|
253
|
+
Picked from a page request.
|
|
254
|
+
- [How to connect a service with OAuth](/how-to/apps/connect-a-third-party-service-with-oauth)
|
|
255
|
+
— open an authorization window from a page.
|
|
256
|
+
- [How to upgrade or uninstall an app](/how-to/apps/upgrade-or-uninstall-an-app) — move an
|
|
257
|
+
installation to a new version.
|