picked 0.0.115 → 0.0.116-next.2
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/apps.md +4 -0
- package/docs/how-to/apps/add-a-page-to-the-dashboard.md +10 -8
- package/docs/how-to/apps/connect-a-google-app.md +100 -0
- package/docs/how-to/apps/connect-a-third-party-service-with-oauth.md +19 -12
- package/docs/how-to/apps/connect-vercel.md +101 -0
- package/docs/how-to/apps/connect-zoho-crm.md +105 -0
- package/docs/how-to/apps/host-an-app-on-vercel.md +5 -2
- package/docs/how-to/apps/link-to-an-installation-from-your-site.md +57 -21
- package/docs/how-to/apps/read-project-data-from-an-app.md +4 -3
- package/docs/how-to/apps/run-code-when-a-workspace-publishes.md +2 -0
- package/docs/how-to/apps/use-an-app-tool-in-a-workflow.md +7 -0
- package/docs/how-to/install-the-gtm-template.md +9 -9
- package/docs/reference/apps/app-kit.md +132 -56
- package/docs/reference/apps/environment.md +48 -12
- package/docs/reference/apps/google.md +235 -0
- package/docs/reference/apps/protocol.md +24 -6
- package/docs/reference/apps/vercel.md +222 -0
- package/docs/reference/apps/zoho-crm.md +214 -0
- package/docs/reference/glossary.md +8 -7
- package/docs/reference/management-api/schema/project.md +70 -2
- package/docs/reference/tools/mcp.md +11 -7
- package/package.json +4 -4
|
@@ -52,13 +52,17 @@ declares its manifest in the `app` section of `picked.config.ts`, with `defineCo
|
|
|
52
52
|
|
|
53
53
|
### Protocol
|
|
54
54
|
|
|
55
|
-
| Constant | Value
|
|
56
|
-
| ---------------------- |
|
|
57
|
-
| `SIGNATURE_HEADER` | `'picked-signature'`
|
|
58
|
-
| `INSTALLATION_HEADER` | `'picked-installation-id'`
|
|
59
|
-
| `APP_ASSERTION_HEADER` | `'picked-app-assertion'`
|
|
60
|
-
| `CONTEXT_HEADER` | `'picked-context'`
|
|
61
|
-
| `PICKED_KEYS_PATH` | `'/.well-known/picked-app-keys.json'`
|
|
55
|
+
| Constant | Value |
|
|
56
|
+
| ---------------------- | --------------------------------------- |
|
|
57
|
+
| `SIGNATURE_HEADER` | `'picked-signature'` |
|
|
58
|
+
| `INSTALLATION_HEADER` | `'picked-installation-id'` |
|
|
59
|
+
| `APP_ASSERTION_HEADER` | `'picked-app-assertion'` |
|
|
60
|
+
| `CONTEXT_HEADER` | `'picked-context'` |
|
|
61
|
+
| `PICKED_KEYS_PATH` | `'/.well-known/picked-app-keys.json'` |
|
|
62
|
+
| `PICKED_CONFIG_PATH` | `'/.well-known/picked-app-config.json'` |
|
|
63
|
+
|
|
64
|
+
`PickedAppConfig` is the type of the document at `PICKED_CONFIG_PATH`. See
|
|
65
|
+
[App config of Picked](/reference/apps/protocol#app-config-of-picked).
|
|
62
66
|
|
|
63
67
|
```ts
|
|
64
68
|
verifyBody(keys: PublicKeySet, body: string, header: string | null): Promise<boolean>
|
|
@@ -131,18 +135,18 @@ createAppHandler(options: AppHandlerOptions): (request: Request) => Promise<Resp
|
|
|
131
135
|
|
|
132
136
|
`createAppHandler` returns a `fetch` handler for the `endpoint` of the manifest.
|
|
133
137
|
|
|
134
|
-
| Option | Type | Default | Description
|
|
135
|
-
| ------------- | -------------------------------------------------------------------------------------------------- | -------- |
|
|
136
|
-
| `pickedKeys` | `PublicKeySet` | required | The public keys of Picked. Each signed request must verify with them.
|
|
137
|
-
| `basePath` | `string` | `''` | The path that `endpoint` points to, for example `/picked`. The handler removes it from the path before it finds the route.
|
|
138
|
-
| `onInstall` | `(event: InstallationCreatedEvent) => Promise<void> \| void` | none | Runs for `installation.created`.
|
|
139
|
-
| `onUpgrade` | `(event: InstallationUpgradedEvent) => Promise<void> \| void` | none | Runs for `installation.upgraded`.
|
|
140
|
-
| `onUninstall` | `(event: InstallationDeletedEvent) => Promise<void> \| void` | none | Runs for `installation.deleted`.
|
|
141
|
-
| `onEvent` | `(event: AppEvent) => Promise<void> \| void` | none | Runs for each event that the manifest lists in `events`.
|
|
142
|
-
| `tools` | `Record<string, (call: ToolCall) => Promise<Record<string, unknown>>>` | none | The body of each workflow tool, by the `name` in the manifest. The function returns the `output`.
|
|
138
|
+
| Option | Type | Default | Description |
|
|
139
|
+
| ------------- | -------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
140
|
+
| `pickedKeys` | `PublicKeySet` | required | The public keys of Picked. Each signed request must verify with them. |
|
|
141
|
+
| `basePath` | `string` | `''` | The path that `endpoint` points to, for example `/picked`. The handler removes it from the path before it finds the route. |
|
|
142
|
+
| `onInstall` | `(event: InstallationCreatedEvent) => Promise<void> \| void` | none | Runs for `installation.created`. |
|
|
143
|
+
| `onUpgrade` | `(event: InstallationUpgradedEvent) => Promise<void> \| void` | none | Runs for `installation.upgraded`. |
|
|
144
|
+
| `onUninstall` | `(event: InstallationDeletedEvent) => Promise<void> \| void` | none | Runs for `installation.deleted`. |
|
|
145
|
+
| `onEvent` | `(event: AppEvent) => Promise<void> \| void` | none | Runs for each event that the manifest lists in `events`. |
|
|
146
|
+
| `tools` | `Record<string, (call: ToolCall) => Promise<Record<string, unknown>>>` | none | The body of each workflow tool, by the `name` in the manifest. The function returns the `output`. |
|
|
143
147
|
| `mcp` | `{ path: string; handle: (request: Request, installation: InstallationRef) => Promise<Response> }` | none | `path` is the path of `mcp.url` of the manifest, for example `/mcp`. The handler compares it with the full path of the request, with `basePath`. `handle` answers each MCP request after the handler verifies it. |
|
|
144
|
-
| `manifest` | `AppManifest` | none | The manifest. The handler answers `GET /manifest.json` with it.
|
|
145
|
-
| `fallback` | `(request: Request) => Promise<Response> \| Response` | none | Answers each other request, for example the pages of the app.
|
|
148
|
+
| `manifest` | `AppManifest` | none | The manifest. The handler answers `GET /manifest.json` with it. |
|
|
149
|
+
| `fallback` | `(request: Request) => Promise<Response> \| Response` | none | Answers each other request, for example the pages of the app. |
|
|
146
150
|
|
|
147
151
|
| Request | Answer |
|
|
148
152
|
| ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -206,7 +210,8 @@ readSession(request: Request, pickedKeys: PublicKeySet): Promise<SessionClaims |
|
|
|
206
210
|
| `sessionTokenOf` | Returns the token in the `Authorization: Bearer <token>` header, or `null`. It does not verify the token. |
|
|
207
211
|
| `readSession` | Verifies the token in the `Authorization: Bearer <token>` header. It returns the fields of the token, or `null`. |
|
|
208
212
|
|
|
209
|
-
A page of the app gets the session token from [`connect`](#connect)
|
|
213
|
+
A page of the app gets the session token from [`connect`](#connect) or
|
|
214
|
+
[`keepConnected`](#keepconnected). See
|
|
210
215
|
[Session tokens](/reference/apps/protocol#session-tokens).
|
|
211
216
|
|
|
212
217
|
### Installation client
|
|
@@ -380,20 +385,29 @@ secret label does not match.
|
|
|
380
385
|
|
|
381
386
|
It throws `TypeError` in these conditions:
|
|
382
387
|
|
|
383
|
-
- `appId` does not match `^app_[a-z0-9]+$`.
|
|
388
|
+
- `appId` does not match `^app_[a-z0-9]+$`. `isAppId(value)` returns `true` when `value`
|
|
389
|
+
matches.
|
|
384
390
|
- `namespace` or `key` does not match `^[a-z0-9_-]{1,64}$`.
|
|
385
391
|
- `dashboardOrigin` is not a URL.
|
|
386
392
|
|
|
393
|
+
On the server of the app, use [`readAppEnvironment`](#readappenvironment). Give its `appId`
|
|
394
|
+
and the first of its `dashboardOrigins()` to `installationLinkUrl`. When `PICKED_APP_ID` is not
|
|
395
|
+
set, `appId` is `null`. Before Picked gives the dashboard origins, the list is empty:
|
|
396
|
+
|
|
387
397
|
```ts
|
|
388
|
-
import { installationLinkUrl } from '@picked/app-kit/server'
|
|
398
|
+
import { installationLinkUrl, readAppEnvironment } from '@picked/app-kit/server'
|
|
389
399
|
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
400
|
+
const { dashboardOrigins, appId } = readAppEnvironment(process.env, '4103')
|
|
401
|
+
const [dashboardOrigin] = await dashboardOrigins()
|
|
402
|
+
if (dashboardOrigin !== undefined && appId !== null) {
|
|
403
|
+
const url = installationLinkUrl({
|
|
404
|
+
dashboardOrigin,
|
|
405
|
+
appId,
|
|
406
|
+
namespace: 'vercel',
|
|
407
|
+
key: 'configuration_id',
|
|
408
|
+
value: 'icfg_123',
|
|
409
|
+
})
|
|
410
|
+
}
|
|
397
411
|
```
|
|
398
412
|
|
|
399
413
|
### `readAppEnvironment`
|
|
@@ -402,20 +416,28 @@ const url = installationLinkUrl({
|
|
|
402
416
|
readAppEnvironment(
|
|
403
417
|
env: Record<string, string | undefined>,
|
|
404
418
|
port: string,
|
|
405
|
-
options?: { fetch?: typeof fetch },
|
|
419
|
+
options?: { fetch?: typeof fetch; refreshAfterMs?: number; timeoutMs?: number },
|
|
406
420
|
): AppEnvironment
|
|
407
421
|
```
|
|
408
422
|
|
|
409
|
-
| `AppEnvironment`
|
|
410
|
-
|
|
|
411
|
-
| `privateKey`
|
|
412
|
-
| `pickedUrl`
|
|
413
|
-
| `pickedKeys`
|
|
414
|
-
| `publicUrl`
|
|
415
|
-
| `frameAncestors`
|
|
416
|
-
|
|
417
|
-
`
|
|
418
|
-
|
|
423
|
+
| `AppEnvironment` | Type | Value |
|
|
424
|
+
| ------------------ | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
425
|
+
| `privateKey` | `string` | `PICKED_APP_PRIVATE_KEY`. |
|
|
426
|
+
| `pickedUrl` | `string` | `PICKED_API_URL`, without a `/` at the end. |
|
|
427
|
+
| `pickedKeys` | `PublicKeySet` | A `remoteKeySet` for `<pickedUrl>/.well-known/picked-app-keys.json`. |
|
|
428
|
+
| `publicUrl` | `string` | `APP_PUBLIC_URL`, without a `/` at the end. |
|
|
429
|
+
| `frameAncestors` | `string[]` | The dashboard origins that `PICKED_DASHBOARD_ORIGINS` or `DASHBOARD_PORT` gives, as a list. Empty when the environment gives none. |
|
|
430
|
+
| `dashboardOrigins` | `() => Promise<string[]>` | `frameAncestors`, or the origins in `<pickedUrl>/.well-known/picked-app-config.json` when the environment gives none. Give it to [`page`](#responses). Its first origin is the dashboard to give [`installationLinkUrl`](#installationlinkurl). |
|
|
431
|
+
| `appId` | `string \| null` | `PICKED_APP_ID`. `null` when it is not set, or when it is not an app ID. |
|
|
432
|
+
|
|
433
|
+
| Parameter | Value |
|
|
434
|
+
| ------------------------ | ------------------------------------------------------------------------------- |
|
|
435
|
+
| `port` | The port of the app on your computer. |
|
|
436
|
+
| `options.fetch` | The `fetch` that reads the public keys and the app config of Picked. |
|
|
437
|
+
| `options.refreshAfterMs` | The minimum time between two reads of the app config. The default is 5 minutes. |
|
|
438
|
+
| `options.timeoutMs` | The maximum time of one read of the app config. The default is 5 seconds. |
|
|
439
|
+
|
|
440
|
+
See [App environment variables](/reference/apps/environment) for each variable, the
|
|
419
441
|
values when a variable is not set, and the errors.
|
|
420
442
|
|
|
421
443
|
### `withRewrittenPath`
|
|
@@ -649,6 +671,54 @@ interface FrameContext {
|
|
|
649
671
|
</script>
|
|
650
672
|
```
|
|
651
673
|
|
|
674
|
+
### `keepConnected`
|
|
675
|
+
|
|
676
|
+
```ts
|
|
677
|
+
keepConnected(options?: { dashboardOrigin?: string }): Promise<FrameConnection>
|
|
678
|
+
|
|
679
|
+
interface FrameConnection {
|
|
680
|
+
context: () => FrameContext
|
|
681
|
+
stop: () => void
|
|
682
|
+
}
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
Calls [`connect`](#connect) with `options`, and returns when the dashboard sends the first
|
|
686
|
+
`FrameContext`. Then it sends `picked:ready` again to get a new `FrameContext`. It sends it 2
|
|
687
|
+
minutes before the session token expires, and not more than 4 minutes after the last
|
|
688
|
+
`FrameContext`. It reads the time of the expiry from the `exp` of the token. See
|
|
689
|
+
[Session tokens](/reference/apps/protocol#session-tokens). When it cannot read `exp`, it
|
|
690
|
+
sends `picked:ready` after 4 minutes.
|
|
691
|
+
|
|
692
|
+
`keepConnected` accepts a new `FrameContext` only from `window.parent`, and only from the
|
|
693
|
+
origin that `connect` accepts.
|
|
694
|
+
|
|
695
|
+
After each `FrameContext`, `keepConnected` waits 1 minute or more before it sends
|
|
696
|
+
`picked:ready` again. It compares the time now with the time to send every 15 seconds, and
|
|
697
|
+
when the page becomes visible or active. For this reason, a computer that starts again after
|
|
698
|
+
sleep mode gets a new session token in 15 seconds. If the dashboard does not send a
|
|
699
|
+
`FrameContext` in 10 seconds, `keepConnected` sends `picked:ready` again after 15 seconds.
|
|
700
|
+
Until a new `FrameContext` comes, `context` returns the last one.
|
|
701
|
+
|
|
702
|
+
| `FrameConnection` | Description |
|
|
703
|
+
| ----------------- | --------------------------------------------------------------------------------- |
|
|
704
|
+
| `context` | Returns the newest `FrameContext` from the dashboard. |
|
|
705
|
+
| `stop` | Stops the requests for a new `FrameContext`. `context` then returns the last one. |
|
|
706
|
+
|
|
707
|
+
Use `keepConnected` on a page that stays open for longer than the session token. Read
|
|
708
|
+
`connection.context().sessionToken` for each request, and for each `authorizeInPopup`. Then
|
|
709
|
+
the request does not have an expired session token.
|
|
710
|
+
|
|
711
|
+
```html
|
|
712
|
+
<script type="module">
|
|
713
|
+
import { keepConnected } from '/app-kit/frame.js'
|
|
714
|
+
const connection = await keepConnected()
|
|
715
|
+
const leads = () =>
|
|
716
|
+
fetch('/api/leads', {
|
|
717
|
+
headers: { authorization: 'Bearer ' + connection.context().sessionToken },
|
|
718
|
+
})
|
|
719
|
+
</script>
|
|
720
|
+
```
|
|
721
|
+
|
|
652
722
|
### `resize` and `autoResize`
|
|
653
723
|
|
|
654
724
|
```ts
|
|
@@ -664,7 +734,7 @@ autoResize(): () => void
|
|
|
664
734
|
### `authorizeInPopup`
|
|
665
735
|
|
|
666
736
|
```ts
|
|
667
|
-
authorizeInPopup(request: { sessionToken: string; params?: unknown }): Promise<{ ok: boolean; message: string }>
|
|
737
|
+
authorizeInPopup(request: { sessionToken: string; params?: unknown; connected?: () => Promise<string | null> }): Promise<{ ok: boolean; message: string }>
|
|
668
738
|
```
|
|
669
739
|
|
|
670
740
|
Opens a new window at `/oauth/start` on the origin of the page. When the window sends
|
|
@@ -673,25 +743,31 @@ messages only from that window, and only from the origin of the page. `params` g
|
|
|
673
743
|
to `authorize` on the server. See [Steps of the flow](#steps-of-the-flow). Call `authorizeInPopup` from a
|
|
674
744
|
`click` handler. A browser can stop a new window that the page opens at a different time.
|
|
675
745
|
|
|
676
|
-
| `request` | Description
|
|
677
|
-
| -------------- |
|
|
678
|
-
| `sessionToken` | The session token from [`
|
|
679
|
-
| `params` | A value for `authorize`, for example a region. The default is `null`.
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
|
683
|
-
|
|
|
684
|
-
| `{ ok
|
|
685
|
-
| `{ ok: false, message:
|
|
686
|
-
| `{ ok: false, message:
|
|
687
|
-
| `{ ok: false, message: 'The app
|
|
688
|
-
| `{ ok: false, message: 'The
|
|
746
|
+
| `request` | Description |
|
|
747
|
+
| -------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
748
|
+
| `sessionToken` | The session token from [`keepConnected`](#keepconnected). |
|
|
749
|
+
| `params` | A value for `authorize`, for example a region. The default is `null`. |
|
|
750
|
+
| `connected` | Optional. Reads the connection from your server. It returns the message to show when the connection exists, or `null`. |
|
|
751
|
+
|
|
752
|
+
| Result | When |
|
|
753
|
+
| --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
|
|
754
|
+
| `{ ok, message }` from the callback page | The callback page sends `picked-app:oauth-result`. |
|
|
755
|
+
| `{ ok: false, message: 'Allow pop-ups to connect' }` | The browser stops the new window. |
|
|
756
|
+
| `{ ok: false, message: <error message> }` | `POST /oauth/start` answers with an error, for example `Sign in again`. |
|
|
757
|
+
| `{ ok: false, message: 'The app answered <status>' }` | `POST /oauth/start` answers with an error that has no message, or with no URL. |
|
|
758
|
+
| `{ ok: false, message: 'The app could not start connecting' }` | The window cannot send `POST /oauth/start`, or cannot read its answer. |
|
|
759
|
+
| `{ ok: true, message: <message of connected> }` | The window closes without a result, and `connected` then returns a message. |
|
|
760
|
+
| `{ ok: false, message: 'The connection window closed. If you finished connecting there, it shows here' }` | The window closes without a result, and the page is the active window. With `connected`, it also returns `null` for 30 seconds. |
|
|
689
761
|
|
|
690
762
|
A service can separate the window from the page with a `Cross-Origin-Opener-Policy` header.
|
|
691
763
|
Then the page cannot see the window, and reads it as closed. The person can continue in the
|
|
692
|
-
window. The callback page stays open, and shows its result.
|
|
693
|
-
|
|
694
|
-
|
|
764
|
+
window. The callback page stays open, and shows its result.
|
|
765
|
+
|
|
766
|
+
`authorizeInPopup` waits until the
|
|
767
|
+
page is the active window again. Without `connected`, it then returns the result of a closed
|
|
768
|
+
window. With `connected`, it calls `connected` one time each second, for 30 seconds, and
|
|
769
|
+
returns when `connected` returns a message. Read the connection from the server after
|
|
770
|
+
`authorizeInPopup` returns.
|
|
695
771
|
|
|
696
772
|
## `@picked/app-kit/testing`
|
|
697
773
|
|
|
@@ -17,7 +17,10 @@ deploys an app.
|
|
|
17
17
|
import { readAppEnvironment } from '@picked/app-kit/server'
|
|
18
18
|
|
|
19
19
|
const port = process.env.APP_PORT ?? '4103'
|
|
20
|
-
const { privateKey, pickedKeys, publicUrl,
|
|
20
|
+
const { privateKey, pickedKeys, publicUrl, dashboardOrigins } = readAppEnvironment(
|
|
21
|
+
process.env,
|
|
22
|
+
port,
|
|
23
|
+
)
|
|
21
24
|
```
|
|
22
25
|
|
|
23
26
|
| Variable | Required | Value |
|
|
@@ -28,10 +31,17 @@ const { privateKey, pickedKeys, publicUrl, frameAncestors } = readAppEnvironment
|
|
|
28
31
|
| `PICKED_DASHBOARD_ORIGINS` | No | The dashboard origins that can show the pages of the app in an `iframe`. A `,` separates each origin. |
|
|
29
32
|
| `API_PORT` | No | The port of a Picked API on your computer. |
|
|
30
33
|
| `DASHBOARD_PORT` | No | The port of a Picked dashboard on your computer. |
|
|
34
|
+
| `PICKED_APP_ID` | No | The app ID in this Picked environment, for example `app_k3v9x2m1q8zt`. `picked app deploy` prints it. |
|
|
31
35
|
|
|
32
36
|
`picked app keys generate` prints a value for `PICKED_APP_PRIVATE_KEY`. See
|
|
33
37
|
[CLI](/reference/tools/cli).
|
|
34
38
|
|
|
39
|
+
[`readAppEnvironment`](/reference/apps/app-kit#readappenvironment) returns `PICKED_APP_ID` as
|
|
40
|
+
`appId`. The first origin that `dashboardOrigins()` gives is the dashboard that the app links
|
|
41
|
+
to. When you set `PICKED_DASHBOARD_ORIGINS`, write the main dashboard first, before an origin
|
|
42
|
+
with `*`. See the guide about
|
|
43
|
+
[links to an installation](/how-to/apps/link-to-an-installation-from-your-site).
|
|
44
|
+
|
|
35
45
|
The app reads the public keys of Picked from
|
|
36
46
|
`<PICKED_API_URL>/.well-known/picked-app-keys.json`. It verifies each request from Picked
|
|
37
47
|
with these keys. See [Public keys of Picked](/reference/apps/protocol#public-keys-of-picked).
|
|
@@ -45,7 +55,7 @@ with these keys. See [Public keys of Picked](/reference/apps/protocol#public-key
|
|
|
45
55
|
| `PICKED_APP_PRIVATE_KEY` | 1. The variable. 2. None: `readAppEnvironment` throws an error. |
|
|
46
56
|
| `PICKED_API_URL` | 1. The variable. 2. On Vercel, the related project `picked-api`. 3. When `API_PORT` is set, `http://localhost:$API_PORT`. 4. None: `readAppEnvironment` throws an error. |
|
|
47
57
|
| `APP_PUBLIC_URL` | 1. The variable. 2. On Vercel with `VERCEL_ENV=production`, `https://$VERCEL_PROJECT_PRODUCTION_URL`. 3. On Vercel in a different environment, `https://$VERCEL_BRANCH_URL`. 4. `http://localhost:<port>`. |
|
|
48
|
-
| `PICKED_DASHBOARD_ORIGINS` | 1. The variable. 2.
|
|
58
|
+
| `PICKED_DASHBOARD_ORIGINS` | 1. The variable. 2. When `DASHBOARD_PORT` is set, `http://localhost:$DASHBOARD_PORT` and `http://127.0.0.1:$DASHBOARD_PORT`. 3. The [app config of Picked](#app-config-of-picked). |
|
|
49
59
|
|
|
50
60
|
`<port>` is the second argument of `readAppEnvironment`.
|
|
51
61
|
|
|
@@ -59,18 +69,18 @@ with these keys. See [Public keys of Picked](/reference/apps/protocol#public-key
|
|
|
59
69
|
### Related projects on Vercel
|
|
60
70
|
|
|
61
71
|
On Vercel, `VERCEL_RELATED_PROJECTS` lists the related projects of the deployment.
|
|
62
|
-
`readAppEnvironment` reads the origin of the related
|
|
63
|
-
`picked-dashboard` from it:
|
|
72
|
+
`readAppEnvironment` reads the origin of the related project `picked-api` from it:
|
|
64
73
|
|
|
65
74
|
| `VERCEL_ENV` | Origin of the related project |
|
|
66
75
|
| ------------ | ------------------------------------------------------------------------------------------------------ |
|
|
67
76
|
| `preview` | The preview deployment of the related project for the same custom environment, or for the same branch. |
|
|
68
77
|
| `production` | The production alias of the related project, or its production URL. |
|
|
69
78
|
|
|
70
|
-
The
|
|
79
|
+
The dashboard origins come from the [app config of Picked](#app-config-of-picked) of that API.
|
|
80
|
+
The app config gives the dashboard host of each client.
|
|
71
81
|
|
|
72
|
-
A deployment without
|
|
73
|
-
`PICKED_API_URL`
|
|
82
|
+
A deployment without the related project `picked-api` gets no value from it. Set
|
|
83
|
+
`PICKED_API_URL` on that deployment.
|
|
74
84
|
|
|
75
85
|
## Values for each Picked environment
|
|
76
86
|
|
|
@@ -83,21 +93,47 @@ different app ID.
|
|
|
83
93
|
| Test (`picked-dev.app`) | `https://api.picked-dev.app` | `https://dashboard.picked-dev.app,https://*.picked-dev.app` |
|
|
84
94
|
|
|
85
95
|
`https://*.picked.app` includes the dashboard host of each client, for example
|
|
86
|
-
`https://
|
|
96
|
+
`https://acme.picked.app`. To allow fewer hosts, write each host in the list.
|
|
87
97
|
|
|
88
98
|
The production list has no `picked-dev.app` origin.
|
|
89
99
|
|
|
100
|
+
You do not have to set `PICKED_DASHBOARD_ORIGINS`. Without it, the app uses the
|
|
101
|
+
[app config of Picked](#app-config-of-picked). Set it to allow fewer origins, or an origin that
|
|
102
|
+
the app config does not have.
|
|
103
|
+
|
|
104
|
+
## App config of Picked
|
|
105
|
+
|
|
106
|
+
The Picked API publishes the dashboard origins of its environment at
|
|
107
|
+
`<PICKED_API_URL>/.well-known/picked-app-config.json`. See
|
|
108
|
+
[App config of Picked](/reference/apps/protocol#app-config-of-picked).
|
|
109
|
+
|
|
110
|
+
`dashboardOrigins()` gives `frameAncestors` when the environment gives a dashboard origin.
|
|
111
|
+
When the environment gives no dashboard origin, `dashboardOrigins()` reads the app config:
|
|
112
|
+
|
|
113
|
+
- It reads the app config on the first call.
|
|
114
|
+
- After a read that succeeds, it reads the app config again after 5 minutes or more.
|
|
115
|
+
- Before a read succeeds, it reads the app config again on each call.
|
|
116
|
+
- It stops a read after 5 seconds.
|
|
117
|
+
- When a read fails, it gives the origins of the last read that succeeded.
|
|
118
|
+
- Before the first read succeeds, it gives no origin.
|
|
119
|
+
|
|
120
|
+
The app config comes from `PICKED_API_URL`. The public keys of Picked come from the same API,
|
|
121
|
+
so the app config adds no new source.
|
|
122
|
+
|
|
90
123
|
## `frame-ancestors`
|
|
91
124
|
|
|
92
|
-
`readAppEnvironment` returns the dashboard origins
|
|
93
|
-
|
|
125
|
+
`readAppEnvironment` returns the dashboard origins that the environment gives as
|
|
126
|
+
`frameAncestors`. `dashboardOrigins()` also gives the origins of the app config. Give
|
|
127
|
+
`await dashboardOrigins()` to `page` from `@picked/app-kit/server`. `page` sends the origins
|
|
128
|
+
in the `Content-Security-Policy` header of a page:
|
|
94
129
|
|
|
95
130
|
```text
|
|
96
131
|
Content-Security-Policy: frame-ancestors https://dashboard.picked.app https://*.picked.app https://dashboard.convincely.com
|
|
97
132
|
```
|
|
98
133
|
|
|
99
|
-
When `
|
|
100
|
-
show the page in an `iframe`, and the dashboard
|
|
134
|
+
When the list of origins that you give `page` is empty, the header is
|
|
135
|
+
`frame-ancestors 'none'`. Then no site can show the page in an `iframe`, and the dashboard
|
|
136
|
+
also cannot show it. See
|
|
101
137
|
[`page`](/reference/apps/app-kit#responses).
|
|
102
138
|
|
|
103
139
|
## CLI variables
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: reference
|
|
3
|
+
layout: docs
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Google apps
|
|
7
|
+
|
|
8
|
+
Three apps connect a Picked project to a Google account: Google Ads, Google Analytics and
|
|
9
|
+
Google Tag Manager. Each app keeps the connection and one or two settings, and tests the
|
|
10
|
+
connection.
|
|
11
|
+
|
|
12
|
+
:::note
|
|
13
|
+
At this time, the three apps only keep the connection and test it. They do not read data from
|
|
14
|
+
Google into Picked.
|
|
15
|
+
:::
|
|
16
|
+
|
|
17
|
+
[How to connect Google Ads, Google Analytics or Google Tag Manager](/how-to/apps/connect-a-google-app)
|
|
18
|
+
gives the steps.
|
|
19
|
+
|
|
20
|
+
## Manifests
|
|
21
|
+
|
|
22
|
+
| Property | Google Ads | Google Analytics | Google Tag Manager |
|
|
23
|
+
| --------------- | ----------------------------------------- | ---------------------------------------------------- | ----------------------------------------------------- |
|
|
24
|
+
| `handle` | `google-ads` | `google-analytics` | `google-tag-manager` |
|
|
25
|
+
| `name` | `Google Ads` | `Google Analytics` | `Google Tag Manager` |
|
|
26
|
+
| `scopes` | None | None | None |
|
|
27
|
+
| `offlineAccess` | Not set | Not set | Not set |
|
|
28
|
+
| `events` | None | None | None |
|
|
29
|
+
| `slots` | `app-home` | `app-home` | `app-home` |
|
|
30
|
+
| `workflowTools` | `check_connection` | `check_connection` | `check_connection` |
|
|
31
|
+
| Slot title | `Google Ads connection` | `Google Analytics connection` | `Google Tag Manager connection` |
|
|
32
|
+
| Slot height | `420` | `420` | `420` |
|
|
33
|
+
| Google scope | `https://www.googleapis.com/auth/adwords` | `https://www.googleapis.com/auth/analytics.readonly` | `https://www.googleapis.com/auth/tagmanager.readonly` |
|
|
34
|
+
|
|
35
|
+
The apps ask for no access to the data of the project. The slot height is in pixels. See
|
|
36
|
+
[App manifest](/reference/apps/manifest) for each property.
|
|
37
|
+
|
|
38
|
+
## App page
|
|
39
|
+
|
|
40
|
+
The `app-home` slot shows the app page. The page has these parts:
|
|
41
|
+
|
|
42
|
+
| Part | What it does |
|
|
43
|
+
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
44
|
+
| **Connect <name>** | Opens a new window at the Google sign-in page. Shows when the installation has no connection. |
|
|
45
|
+
| Account line | `Connected as <email>`. Shows `Connected as a Google account` when Google gives no email. |
|
|
46
|
+
| Setting fields | The settings of the app. See [Settings](#settings). The fields show when the installation has a connection. |
|
|
47
|
+
| **Save settings** | Stores the settings. |
|
|
48
|
+
| **Test connection** | Runs the test of the app. See [Connection test](#connection-test). |
|
|
49
|
+
| `Disconnect` | Removes the connection. See [Removal of the connection](#removal-of-the-connection). |
|
|
50
|
+
| Status line | The result of the last action. See [Page messages](#page-messages). |
|
|
51
|
+
| List | After a test, one item for each account, property or container that the Google account opens. The list has the label `What the connection reaches`. |
|
|
52
|
+
|
|
53
|
+
## Google sign-in
|
|
54
|
+
|
|
55
|
+
The app uses the Google OAuth client of Picked. The person who connects does not make a client.
|
|
56
|
+
|
|
57
|
+
The app asks Google for these scopes:
|
|
58
|
+
|
|
59
|
+
- `openid` and `email`, to get the email address of the Google account.
|
|
60
|
+
- The Google scope of the app. See [Manifests](#manifests).
|
|
61
|
+
|
|
62
|
+
The app sends `access_type=offline`. Google then gives a refresh token. Google shows the consent
|
|
63
|
+
page each time that a person connects. The app does not add scopes that the Google account
|
|
64
|
+
gave to Picked before.
|
|
65
|
+
|
|
66
|
+
The connection belongs to the installation. It does not belong to the person who connects.
|
|
67
|
+
|
|
68
|
+
## Settings
|
|
69
|
+
|
|
70
|
+
**Save settings** replaces all of the settings of the installation. The app removes spaces at
|
|
71
|
+
the start and the end of each value.
|
|
72
|
+
|
|
73
|
+
### Google Ads
|
|
74
|
+
|
|
75
|
+
| Field | Key | Required | Format |
|
|
76
|
+
| ---------------------- | ----------------- | -------- | --------------------------------------------------------------------------- |
|
|
77
|
+
| **Customer ID** | `customerId` | Yes | Ten digits. The app removes each hyphen and space. Example: `123-456-7890`. |
|
|
78
|
+
| **Manager account ID** | `loginCustomerId` | No | Ten digits. The app removes each hyphen and space. |
|
|
79
|
+
|
|
80
|
+
**Customer ID** is the Google Ads account of the project. **Manager account ID** is the
|
|
81
|
+
manager account that the Google account uses to get to the customer account. The app sends
|
|
82
|
+
it to Google Ads in the `login-customer-id` header.
|
|
83
|
+
|
|
84
|
+
### Google Analytics
|
|
85
|
+
|
|
86
|
+
| Field | Key | Required | Format |
|
|
87
|
+
| --------------- | ------------ | -------- | ----------------------------------------------------------------------------- |
|
|
88
|
+
| **Property ID** | `propertyId` | Yes | 6 to 12 digits. The app removes a `properties/` prefix. Example: `250000001`. |
|
|
89
|
+
|
|
90
|
+
**Property ID** is a Google Analytics 4 property.
|
|
91
|
+
|
|
92
|
+
### Google Tag Manager
|
|
93
|
+
|
|
94
|
+
| Field | Key | Required | Format |
|
|
95
|
+
| ---------------- | ------------- | -------- | ---------------------------------------------------------------------------------------------------- |
|
|
96
|
+
| **Container ID** | `containerId` | Yes | `GTM-` and 4 to 12 letters or digits. The app changes letters to upper case. Example: `GTM-XXXXXXX`. |
|
|
97
|
+
|
|
98
|
+
**Container ID** is a web container, as Tag Manager shows it.
|
|
99
|
+
|
|
100
|
+
### Settings messages
|
|
101
|
+
|
|
102
|
+
| Message | When |
|
|
103
|
+
| -------------------------------------------------------- | ------------------------------------------- |
|
|
104
|
+
| `Settings saved` | **Save settings** is complete. |
|
|
105
|
+
| `<field> is required` | A required field is empty. |
|
|
106
|
+
| `Customer ID is ten digits, such as 123-456-7890` | **Customer ID** is not ten digits. |
|
|
107
|
+
| `Manager account ID is ten digits, such as 123-456-7890` | **Manager account ID** is not ten digits. |
|
|
108
|
+
| `A property ID is a number, such as 250000001` | **Property ID** is not 6 to 12 digits. |
|
|
109
|
+
| `A container ID looks like GTM-XXXXXXX` | **Container ID** does not match the format. |
|
|
110
|
+
|
|
111
|
+
## Connection test
|
|
112
|
+
|
|
113
|
+
**Test connection** and the `check_connection` tool run the same test. The test does these
|
|
114
|
+
things:
|
|
115
|
+
|
|
116
|
+
1. It makes sure that the installation has a connection.
|
|
117
|
+
2. It makes sure that the Google account gave the Google scope of the app.
|
|
118
|
+
3. When the app has no current access token, it gets one from Google with the refresh token.
|
|
119
|
+
4. It reads the list of what the Google account can open.
|
|
120
|
+
5. It reads the item of the saved setting.
|
|
121
|
+
|
|
122
|
+
| App | List | Item |
|
|
123
|
+
| ------------------ | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
|
|
124
|
+
| Google Ads | The accounts that the Google account can open, from `customers:listAccessibleCustomers`. | The name of the **Customer ID** account, from `googleAds:search`. |
|
|
125
|
+
| Google Analytics | The properties of up to 200 accounts, from `accountSummaries`. | The property of **Property ID**, from the Google Analytics API. |
|
|
126
|
+
| Google Tag Manager | Each container of the first 20 Tag Manager accounts. | The container of **Container ID** in the list. |
|
|
127
|
+
|
|
128
|
+
The Google Ads app sends the developer token of Picked for the Google Ads API with each of its
|
|
129
|
+
requests.
|
|
130
|
+
|
|
131
|
+
Each item of the list on the page has the format `<label>: <value>`:
|
|
132
|
+
|
|
133
|
+
| App | Label | Value |
|
|
134
|
+
| ------------------ | -------------------------------------- | -------------------------------------------- |
|
|
135
|
+
| Google Ads | `Account` | The customer ID, for example `123-456-7890`. |
|
|
136
|
+
| Google Analytics | The name of the account, or `Property` | `<property name> (<property ID>)` |
|
|
137
|
+
| Google Tag Manager | The name of the account | `<container name> (<container ID>)` |
|
|
138
|
+
|
|
139
|
+
### Test messages
|
|
140
|
+
|
|
141
|
+
| Message | When |
|
|
142
|
+
| ----------------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
143
|
+
| `Connected to <name> (<ID>)` | The test passed. `<name>` is the name of the account, property or container. |
|
|
144
|
+
| `<app name> is not connected` | The installation has no connection. |
|
|
145
|
+
| `Connect again and allow <app name> access` | The Google account did not give the Google scope of the app. |
|
|
146
|
+
| `Save the customer ID of the account to use` | Google Ads has no saved **Customer ID**. |
|
|
147
|
+
| `Save the ID of the property to use` | Google Analytics has no saved **Property ID**. |
|
|
148
|
+
| `Save the ID of the container to use` | Google Tag Manager has no saved **Container ID**. |
|
|
149
|
+
| `This Google account reaches no container <ID>` | The container of **Container ID** is not in the list. |
|
|
150
|
+
| `Google refused the request: <error>` | Google did not give an access token for the refresh token. |
|
|
151
|
+
| `Google answered without an access token` | Google accepted the refresh token, but its answer had no access token. |
|
|
152
|
+
| `Google could not be reached` | The app cannot reach Google. |
|
|
153
|
+
| `Google answered <status>` | A Google API refused a request with no message. |
|
|
154
|
+
| The message from Google | A Google API refused a request, for example because the account cannot open the item. |
|
|
155
|
+
|
|
156
|
+
When the test does not pass, the page can still show the list.
|
|
157
|
+
|
|
158
|
+
## Workflow tool `check_connection`
|
|
159
|
+
|
|
160
|
+
| Property | Google Ads | Google Analytics | Google Tag Manager |
|
|
161
|
+
| ------------------ | ----------------------------------------------------------------------------------------- | ----------------------------------------------------- | --------------------------------------------------------- |
|
|
162
|
+
| Tool name | `app.<installation slug>.check_connection`, for example `app.google-ads.check_connection` | `app.<installation slug>.check_connection` | `app.<installation slug>.check_connection` |
|
|
163
|
+
| Label in workflows | `Google Ads: Check Google Ads connection` | `Google Analytics: Check Google Analytics connection` | `Google Tag Manager: Check Google Tag Manager connection` |
|
|
164
|
+
| Effect | `read` | `read` | `read` |
|
|
165
|
+
|
|
166
|
+
The tool has no arguments. It runs the [connection test](#connection-test).
|
|
167
|
+
|
|
168
|
+
### Output
|
|
169
|
+
|
|
170
|
+
| Name | Label | Type | Description |
|
|
171
|
+
| ----------- | --------------------- | --------- | ------------------------------------------------------------- |
|
|
172
|
+
| `connected` | `Connected` | `boolean` | `true` when the test passed. |
|
|
173
|
+
| `message` | `What the test found` | `string` | The message of the test. See [Test messages](#test-messages). |
|
|
174
|
+
|
|
175
|
+
The tool does not fail when the test does not pass. It returns `connected: false`.
|
|
176
|
+
|
|
177
|
+
## Data that Picked keeps
|
|
178
|
+
|
|
179
|
+
Each app keeps the data of each installation in labels of the installation in Picked:
|
|
180
|
+
|
|
181
|
+
| Label | Type | Secret | Value |
|
|
182
|
+
| ------------------- | ------ | ------ | -------------------------------------------------------------------- |
|
|
183
|
+
| `google.connection` | `JSON` | Yes | The connection: `refreshToken`, `email`, `scopes` and `connectedAt`. |
|
|
184
|
+
| `google.settings` | `JSON` | No | The settings, by key. See [Settings](#settings). |
|
|
185
|
+
|
|
186
|
+
The app keeps no other data. See
|
|
187
|
+
[How to store data for an installation](/how-to/apps/store-data-for-an-installation).
|
|
188
|
+
|
|
189
|
+
## Removal of the connection
|
|
190
|
+
|
|
191
|
+
`Disconnect` tells Google to revoke the refresh token. It then deletes `google.connection`.
|
|
192
|
+
The settings stay.
|
|
193
|
+
|
|
194
|
+
When you remove the app from the project, Picked tells the app before it deletes the labels of the
|
|
195
|
+
installation. The app then tells Google to revoke the refresh token. Picked deletes the labels
|
|
196
|
+
also when the app does not answer.
|
|
197
|
+
|
|
198
|
+
The app ignores the answer from Google. When Google does not revoke the token, Picked still
|
|
199
|
+
deletes the connection.
|
|
200
|
+
|
|
201
|
+
## Sign-in messages
|
|
202
|
+
|
|
203
|
+
After a click on **Connect <name>**, the status line shows `Waiting for Google…`. It then
|
|
204
|
+
shows one of these messages:
|
|
205
|
+
|
|
206
|
+
| Message | When |
|
|
207
|
+
| -------------------------------------------------------------------------------- | -------------------------------------------------------- |
|
|
208
|
+
| `Connected <email>` | The connection is complete. |
|
|
209
|
+
| `Connected your Google account` | The connection is complete, and Google gave no email. |
|
|
210
|
+
| `Google access was declined` | The person did not accept the access on the Google page. |
|
|
211
|
+
| `Google sent no code` | Google sent the window back with no authorization code. |
|
|
212
|
+
| `Google answered without a refresh token; connect again` | Google did not give a refresh token. |
|
|
213
|
+
| `Google refused the request: <error>` | Google refused the authorization code. |
|
|
214
|
+
| `Google could not be reached` | The app cannot reach Google. |
|
|
215
|
+
| `<app name> could not be connected` | The connection failed for a different reason. |
|
|
216
|
+
| `This connection link has expired or was opened in another browser; start again` | The window is too old, or it is in a different browser. |
|
|
217
|
+
| `Sign in again` | The session of the page expired. |
|
|
218
|
+
| `The app could not start connecting` | The window did not get the Google sign-in address. |
|
|
219
|
+
| `Allow pop-ups to connect` | The browser did not open the window. |
|
|
220
|
+
| `The connection window closed. If you finished connecting there, it shows here` | The window closed before it sent a result. |
|
|
221
|
+
|
|
222
|
+
## Page messages
|
|
223
|
+
|
|
224
|
+
| Message | When |
|
|
225
|
+
| --------------- | ------------------------------------------------------------------------ |
|
|
226
|
+
| `Loading…` | The page reads the connection and the settings. |
|
|
227
|
+
| `Testing…` | **Test connection** runs. |
|
|
228
|
+
| `Disconnected` | `Disconnect` is complete. The page shows **Connect <name>** again. |
|
|
229
|
+
| `Sign in again` | The session of the page expired. |
|
|
230
|
+
|
|
231
|
+
## Related
|
|
232
|
+
|
|
233
|
+
- [How to connect Google Ads, Google Analytics or Google Tag Manager](/how-to/apps/connect-a-google-app)
|
|
234
|
+
- [How to use an app tool in a workflow](/how-to/apps/use-an-app-tool-in-a-workflow)
|
|
235
|
+
- [Apps](/reference/dashboard/apps)
|