@picked/app-protocol 0.0.117-next.2 → 0.0.117-next.3

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.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @file `@picked/app-protocol`: the app manifest, the Ed25519 keys both sides sign with, and the
3
+ * signed requests, session tokens and app assertions Picked and an app exchange.
4
+ */
5
+ export * from './manifest.js';
6
+ export * from './protocol.js';
7
+ export * from './keys.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,QAAQ,CAAA"}
@@ -0,0 +1,166 @@
1
+ /**
2
+ * @file Ed25519 keys and the EdDSA JWTs signed with them.
3
+ *
4
+ * Picked signs what it sends an app with Picked's key, and an app signs what it sends Picked
5
+ * with its own; each side holds only the other's public key. A private key is the one-line
6
+ * base64 of its PKCS#8 DER (a PKCS#8 PEM of it reads the same), a public key the base64url of
7
+ * its 32 raw bytes, and a key id the first 16 base64url characters of the public key's SHA-256.
8
+ */
9
+ /** A public key and the id signatures name it by. */
10
+ export interface PublicKey {
11
+ kid: string;
12
+ /** The base64url of the key's 32 raw bytes. */
13
+ publicKey: string;
14
+ }
15
+ /** A private key ready to sign, with its public half. */
16
+ export interface Signer extends PublicKey {
17
+ /** Signs a message, returning the base64url signature. */
18
+ sign: (message: string) => Promise<string>;
19
+ }
20
+ /** The public keys a verifier trusts, found by key id. */
21
+ export interface PublicKeySet {
22
+ /** The key with this id, or null when the set holds none. */
23
+ get: (kid: string) => Promise<CryptoKey | null>;
24
+ }
25
+ /** A JSON Web Key Set of Ed25519 public keys. */
26
+ export interface Jwks {
27
+ keys: {
28
+ kty: 'OKP';
29
+ crv: 'Ed25519';
30
+ alg: 'EdDSA';
31
+ use: 'sig';
32
+ kid: string;
33
+ x: string;
34
+ }[];
35
+ }
36
+ /**
37
+ * Encodes bytes as unpadded base64url.
38
+ *
39
+ * @param {Uint8Array} bytes - The bytes.
40
+ * @returns {string} The encoding.
41
+ * @example toBase64url(new Uint8Array([251])) // '-w'
42
+ */
43
+ export declare function toBase64url(bytes: Uint8Array): string;
44
+ /**
45
+ * Decodes unpadded base64url or base64 to bytes.
46
+ *
47
+ * @param {string} encoded - The encoding.
48
+ * @returns {Uint8Array<ArrayBuffer>} The bytes.
49
+ * @example fromBase64url('-w') // Uint8Array [251]
50
+ */
51
+ export declare function fromBase64url(encoded: string): Uint8Array<ArrayBuffer>;
52
+ /**
53
+ * Computes a public key's id.
54
+ *
55
+ * @param {string} publicKey - The base64url public key.
56
+ * @returns {Promise<string>} The key id.
57
+ * @example await keyIdOf(publicKey)
58
+ */
59
+ export declare function keyIdOf(publicKey: string): Promise<string>;
60
+ /**
61
+ * Generates an Ed25519 key pair.
62
+ *
63
+ * @returns {Promise<PublicKey & { privateKey: string }>} The private key as the one-line base64 of its PKCS#8 DER, the public key and its id.
64
+ * @example const { privateKey, publicKey, kid } = await generateKeyPair()
65
+ */
66
+ export declare function generateKeyPair(): Promise<PublicKey & {
67
+ privateKey: string;
68
+ }>;
69
+ /**
70
+ * Imports a private key as a signer.
71
+ *
72
+ * @param {string} privateKey - The base64 of the PKCS#8 DER, or a PKCS#8 PEM of it.
73
+ * @returns {Promise<Signer>} The signer.
74
+ * @throws {Error} When the value is not an Ed25519 private key.
75
+ * @example const signer = await createSigner(process.env.PICKED_APP_PRIVATE_KEY ?? '')
76
+ */
77
+ export declare function createSigner(privateKey: string): Promise<Signer>;
78
+ /**
79
+ * Derives an AES-GCM key from a private key for one purpose, so an app can encrypt what only it
80
+ * reads back without holding a second secret.
81
+ *
82
+ * @param {string} privateKey - The base64 of the PKCS#8 DER, or a PKCS#8 PEM of it.
83
+ * @param {string} purpose - What the key is for; another purpose derives another key.
84
+ * @returns {Promise<CryptoKey>} The key.
85
+ * @example await deriveSecretKey(environment.privateKey, 'oauth-state')
86
+ */
87
+ export declare function deriveSecretKey(privateKey: string, purpose: string): Promise<CryptoKey>;
88
+ /**
89
+ * Imports a private key as a signer once per process.
90
+ *
91
+ * @param {string} privateKey - The base64 of the PKCS#8 DER, or a PKCS#8 PEM of it.
92
+ * @returns {Promise<Signer>} The signer.
93
+ * @example await signerFor(environment.privateKey)
94
+ */
95
+ export declare function signerFor(privateKey: string): Promise<Signer>;
96
+ /**
97
+ * Imports a base64url public key for verifying.
98
+ *
99
+ * @param {string} publicKey - The public key.
100
+ * @returns {Promise<CryptoKey | null>} The key, or null when it is not an Ed25519 public key.
101
+ * @example await importPublicKey(publicKey)
102
+ */
103
+ export declare function importPublicKey(publicKey: string): Promise<CryptoKey | null>;
104
+ /**
105
+ * Checks a signature against a key in a set.
106
+ *
107
+ * @param {PublicKeySet} keys - The trusted keys.
108
+ * @param {string} kid - The id of the key that signed.
109
+ * @param {string} message - What was signed.
110
+ * @param {string} signature - The base64url signature.
111
+ * @returns {Promise<boolean>} Whether a trusted key signed the message.
112
+ * @example await verifySignature(keys, kid, message, signature)
113
+ */
114
+ export declare function verifySignature(keys: PublicKeySet, kid: string, message: string, signature: string): Promise<boolean>;
115
+ /**
116
+ * A key set holding the given public keys.
117
+ *
118
+ * @param {readonly PublicKey[]} keys - The trusted keys.
119
+ * @returns {PublicKeySet} The set.
120
+ * @example staticKeySet([{ kid, publicKey }])
121
+ */
122
+ export declare function staticKeySet(keys: readonly PublicKey[]): PublicKeySet;
123
+ /**
124
+ * Renders public keys as a JSON Web Key Set.
125
+ *
126
+ * @param {readonly PublicKey[]} keys - The keys.
127
+ * @returns {Jwks} The set.
128
+ * @example toJwks([signer])
129
+ */
130
+ export declare function toJwks(keys: readonly PublicKey[]): Jwks;
131
+ /**
132
+ * A key set read from a JSON Web Key Set URL. It fetches the set on first use, and again for a
133
+ * key id it does not hold once `refreshAfterMs` has passed since the last fetch. A fetch that
134
+ * takes longer than ten seconds is aborted.
135
+ *
136
+ * @param {object} options - Where the set lives.
137
+ * @param {string} options.url - The set's URL.
138
+ * @param {typeof fetch} [options.fetch] - The fetch to read it with.
139
+ * @param {number} [options.refreshAfterMs] - The least time between fetches; one minute by default.
140
+ * @returns {PublicKeySet} The set.
141
+ * @example remoteKeySet({ url: 'https://api.picked.app/.well-known/picked-app-keys.json' })
142
+ */
143
+ export declare function remoteKeySet(options: {
144
+ url: string;
145
+ fetch?: typeof fetch;
146
+ refreshAfterMs?: number;
147
+ }): PublicKeySet;
148
+ /**
149
+ * Signs claims as an EdDSA JWT.
150
+ *
151
+ * @param {Signer} signer - The key to sign with.
152
+ * @param {Record<string, unknown>} claims - The claims.
153
+ * @returns {Promise<string>} The JWT.
154
+ * @example await signJwt(signer, { sub: 'appi_1', exp })
155
+ */
156
+ export declare function signJwt(signer: Signer, claims: Record<string, unknown>): Promise<string>;
157
+ /**
158
+ * Checks an EdDSA JWT and reads its claims. A token past its `exp` fails.
159
+ *
160
+ * @param {PublicKeySet} keys - The trusted keys.
161
+ * @param {string} token - The JWT.
162
+ * @returns {Promise<Record<string, unknown> | null>} The claims, or null when the token fails.
163
+ * @example await verifyJwt(keys, token)
164
+ */
165
+ export declare function verifyJwt(keys: PublicKeySet, token: string): Promise<Record<string, unknown> | null>;
166
+ //# sourceMappingURL=keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/keys.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,qDAAqD;AACrD,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,yDAAyD;AACzD,MAAM,WAAW,MAAO,SAAQ,SAAS;IACvC,0DAA0D;IAC1D,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CAC3C;AAED,0DAA0D;AAC1D,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ASG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,YAAY,EAClB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC,CAalB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,GAAG,YAAY,CAGrE;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,SAAS,EAAE,GAAG,IAAI,CAWvD;AAwBD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE;IACpC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;IACpB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,GAAG,YAAY,CAyBf;AAaD;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAG9F;AAiBD;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,YAAY,EAClB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAezC"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * @file The app manifest: what an app version declares to Picked, and the parser
3
+ * the API and the CLI both run over it.
4
+ */
5
+ /** The dashboard locations an app can render a slot into. */
6
+ export declare const APP_SLOT_LOCATIONS: readonly ['app-home', 'workspace-prepublish-actions', 'workspace-postpublish-actions'];
7
+ /** A dashboard location an app can render a slot into. */
8
+ export type AppSlotLocation = (typeof APP_SLOT_LOCATIONS)[number];
9
+ /** The events an app can subscribe to: Picked POSTs each to `<endpoint>/events`. */
10
+ export declare const APP_EVENTS: readonly ['workspace.published'];
11
+ /** An event an app can subscribe to. */
12
+ export type AppEventName = (typeof APP_EVENTS)[number];
13
+ /** The value types a workflow tool argument or output field takes. */
14
+ export declare const APP_VALUE_TYPES: readonly ['string', 'number', 'boolean', 'json'];
15
+ /** A value type a workflow tool argument or output field takes. */
16
+ export type AppValueType = (typeof APP_VALUE_TYPES)[number];
17
+ /** One iframe an app renders at a dashboard location. */
18
+ export interface AppSlot {
19
+ /** Where the slot renders. */
20
+ location: AppSlotLocation;
21
+ /** The page the iframe loads. HTTPS, or `http://localhost` while developing. */
22
+ url: string;
23
+ /** The heading the dashboard shows above the iframe. */
24
+ title?: string;
25
+ /** The iframe's starting height in pixels; the frame can resize itself. */
26
+ height?: number;
27
+ }
28
+ /** One argument a workflow tool takes. */
29
+ export interface AppToolArgument {
30
+ /** The argument's name for authors. */
31
+ label: string;
32
+ /** The value type the argument takes. */
33
+ type: AppValueType;
34
+ /** What the argument means, shown under the field. */
35
+ description?: string;
36
+ /** Whether a node must set the argument. */
37
+ required?: boolean;
38
+ /** The values a `string` argument is limited to. */
39
+ options?: string[];
40
+ }
41
+ /** One property a workflow tool records for later nodes. */
42
+ export interface AppToolOutputField {
43
+ /** The property's name for authors. */
44
+ label: string;
45
+ /** The value type the property holds. */
46
+ type: AppValueType;
47
+ /** What the property holds. */
48
+ description?: string;
49
+ /** Whether a call can leave the property out. */
50
+ optional?: boolean;
51
+ }
52
+ /** A workflow tool whose calls Picked POSTs to the app's endpoint. */
53
+ export interface AppWorkflowTool {
54
+ /** The tool's name within the app: lower-case letters, digits and underscores. */
55
+ name: string;
56
+ /** The tool's name for authors. */
57
+ label: string;
58
+ /** What the tool does, for authors. */
59
+ description: string;
60
+ /** `write` when a call changes something outside the run; a test run skips writes. */
61
+ effect: 'read' | 'write';
62
+ /** The arguments a node sets, by name. */
63
+ arguments: Record<string, AppToolArgument>;
64
+ /** What a call records for later nodes, by property name. */
65
+ output: Record<string, AppToolOutputField>;
66
+ }
67
+ /** What an app version declares. */
68
+ export interface AppManifest {
69
+ /** The app's handle, unique in its organisation: lower-case letters, digits and hyphens. */
70
+ handle: string;
71
+ /** The app's name. */
72
+ name: string;
73
+ /** A sentence on what the app does. */
74
+ description?: string;
75
+ /**
76
+ * The base URL Picked appends request paths to: `/lifecycle`, `/events` and
77
+ * `/tools/<name>`. An app with no endpoint has slots, an MCP server, or both.
78
+ */
79
+ endpoint?: string;
80
+ /** The Picked API scopes the installation token carries, such as `organization_leads/read`. */
81
+ scopes?: string[];
82
+ /** The iframes the app renders in the dashboard. */
83
+ slots?: AppSlot[];
84
+ /** The workflow tools the app adds to every project it is installed on. */
85
+ workflowTools?: AppWorkflowTool[];
86
+ /** An MCP server the dashboard agent can use, at an https `url`. */
87
+ mcp?: {
88
+ url: string;
89
+ };
90
+ /** The events Picked sends the app for every project it is installed on. */
91
+ events?: AppEventName[];
92
+ /**
93
+ * Whether the app mints installation tokens on its own, outside a request from Picked, such
94
+ * as for a scheduled sync. The installing user consents to it. Without it, the app calls
95
+ * Picked with the token each request from Picked carries.
96
+ */
97
+ offlineAccess?: boolean;
98
+ }
99
+ /** The result of parsing a manifest: the manifest, or every issue found. */
100
+ export type ParseManifestResult = {
101
+ ok: true;
102
+ manifest: AppManifest;
103
+ } | {
104
+ ok: false;
105
+ issues: string[];
106
+ };
107
+ /**
108
+ * Checks a URL is HTTPS, or HTTP on a loopback host.
109
+ *
110
+ * @param {unknown} value - The candidate URL.
111
+ * @returns {boolean} Whether Picked may load or call it.
112
+ * @example isAppUrl('https://example.com') // true
113
+ */
114
+ export declare function isAppUrl(value: unknown): value is string;
115
+ /**
116
+ * Removes every trailing occurrence of a character.
117
+ *
118
+ * @param {string} text - The text.
119
+ * @param {string} char - The character, such as `/`.
120
+ * @returns {string} The text without it at the end.
121
+ * @example trimTrailing('https://x.dev//', '/') // 'https://x.dev'
122
+ */
123
+ export declare function trimTrailing(text: string, char: string): string;
124
+ /**
125
+ * Parses a manifest, reporting every issue rather than the first.
126
+ *
127
+ * @param {unknown} value - The candidate manifest, such as a JSON body.
128
+ * @returns {ParseManifestResult} The manifest, or the issues.
129
+ * @example parseManifest({ handle: 'acme', name: 'Acme' })
130
+ */
131
+ export declare function parseManifest(value: unknown): ParseManifestResult;
132
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/manifest.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,6DAA6D;AAC7D,eAAO,MAAM,kBAAkB,YAC7B,UAAU,EACV,8BAA8B,EAC9B,+BAA+B,CACvB,CAAA;AAEV,0DAA0D;AAC1D,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEjE,oFAAoF;AACpF,eAAO,MAAM,UAAU,YAAI,qBAAqB,CAAU,CAAA;AAE1D,wCAAwC;AACxC,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtD,sEAAsE;AACtE,eAAO,MAAM,eAAe,YAAI,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAU,CAAA;AAE/E,mEAAmE;AACnE,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAA;AAE3D,yDAAyD;AACzD,MAAM,WAAW,OAAO;IACtB,8BAA8B;IAC9B,QAAQ,EAAE,eAAe,CAAA;IACzB,gFAAgF;IAChF,GAAG,EAAE,MAAM,CAAA;IACX,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,0CAA0C;AAC1C,MAAM,WAAW,eAAe;IAC9B,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAA;IACb,yCAAyC;IACzC,IAAI,EAAE,YAAY,CAAA;IAClB,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4CAA4C;IAC5C,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AAC,EAAE,YAAY,EAAE,CAAA;IACvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,4EAA4E;AAC5E,MAAM,MAAM,mBAAmB,GAC7B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,WAAW,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAA;AAiBvE;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CASxD;AAyLD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI/D;AA8GD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,CAwCjE"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,221 @@
1
+ /**
2
+ * @file What Picked sends an app and what the app answers: lifecycle events, workflow tool
3
+ * calls, app events, and the signatures and session tokens both sides check.
4
+ *
5
+ * Every request Picked sends carries `picked-signature: t=<unix seconds>,kid=<key id>,v1=<sig>`,
6
+ * the base64url Ed25519 signature of `<t>.<body>` by Picked's key, whose public half Picked
7
+ * publishes at {@link PICKED_KEYS_PATH}. Session tokens are EdDSA JWTs Picked signs the same
8
+ * way. An app calls Picked with an app assertion: a JWT it signs with its own key, whose
9
+ * public half it registered on deploy.
10
+ */
11
+ import { type PublicKeySet, type Signer } from './keys.js';
12
+ /** The header a signed request carries. */
13
+ export declare const SIGNATURE_HEADER = "picked-signature";
14
+ /** The header naming the installation a request is for. */
15
+ export declare const INSTALLATION_HEADER = "picked-installation-id";
16
+ /** The header an app sends its app assertion in. */
17
+ export declare const APP_ASSERTION_HEADER = "picked-app-assertion";
18
+ /**
19
+ * The header an MCP request carries its installation in: the base64url JSON of an
20
+ * {@link InstallationRef}, which the request's signature covers with the body.
21
+ */
22
+ export declare const CONTEXT_HEADER = "picked-context";
23
+ /** Where Picked publishes the public keys it signs with, beneath its API origin. */
24
+ export declare const PICKED_KEYS_PATH = "/.well-known/picked-app-keys.json";
25
+ /**
26
+ * Where Picked publishes its app config beneath its API origin: a JSON object whose
27
+ * `dashboardOrigins` lists every origin the dashboard of that Picked environment is served at.
28
+ */
29
+ export declare const PICKED_CONFIG_PATH = "/.well-known/picked-app-config.json";
30
+ /** The app config Picked publishes at {@link PICKED_CONFIG_PATH}. */
31
+ export interface PickedAppConfig {
32
+ /** The origins the dashboard of that Picked environment is served at. */
33
+ dashboardOrigins: string[];
34
+ }
35
+ /** Where an installation lives, and the Picked API it calls back. */
36
+ export interface InstallationRef {
37
+ installationId: string;
38
+ organizationId: string;
39
+ projectId: string;
40
+ /** The origin of the Picked API that sent this, which the installation calls back. */
41
+ apiUrl: string;
42
+ /**
43
+ * A one-hour token carrying the installation's scopes, on every request from Picked. It
44
+ * reaches the installation's own labels.
45
+ */
46
+ token?: string;
47
+ /** When `token` expires. */
48
+ tokenExpiresAt?: string;
49
+ }
50
+ /** Sent when the app is installed on a project. */
51
+ export interface InstallationCreatedEvent extends InstallationRef {
52
+ type: 'installation.created';
53
+ /** The scopes the installation's tokens carry. */
54
+ scopes: string[];
55
+ }
56
+ /** Sent when an installation moves to another version of the app. */
57
+ export interface InstallationUpgradedEvent extends InstallationRef {
58
+ type: 'installation.upgraded';
59
+ /** The version the installation now runs. */
60
+ version: number;
61
+ /** The scopes the installation's tokens now carry. */
62
+ scopes: string[];
63
+ }
64
+ /** Sent when the app is removed from a project, just before its tokens and labels go. */
65
+ export interface InstallationDeletedEvent extends InstallationRef {
66
+ type: 'installation.deleted';
67
+ }
68
+ /** A lifecycle event. */
69
+ export type LifecycleEvent = InstallationCreatedEvent | InstallationUpgradedEvent | InstallationDeletedEvent;
70
+ /** Sent to an app that subscribes to `workspace.published` when a project's workspace publishes. */
71
+ export interface WorkspacePublishedEvent extends InstallationRef {
72
+ type: 'workspace.published';
73
+ /** The id the event carries across redeliveries. */
74
+ eventId: string;
75
+ workspaceId: string;
76
+ /** The version the publish wrote. */
77
+ workspaceVersionId: string;
78
+ /** When it published, as an ISO 8601 timestamp. */
79
+ occurredAt: string;
80
+ }
81
+ /** An event an app subscribes to in its manifest's `events`. */
82
+ export type AppEvent = WorkspacePublishedEvent;
83
+ /** A workflow node calling one of the app's tools. */
84
+ export interface ToolCall extends InstallationRef {
85
+ type: 'workflow_tool.call';
86
+ /** The tool's name, as the manifest declares it. */
87
+ tool: string;
88
+ /** The node's resolved arguments. */
89
+ arguments: Record<string, unknown>;
90
+ /** Identifies the call across retries; the same key means the same call. */
91
+ idempotencyKey: string;
92
+ /** The run the call belongs to. */
93
+ run: {
94
+ runId: string;
95
+ nodeId: string;
96
+ test: boolean;
97
+ };
98
+ }
99
+ /** What a tool answers: its output, or why it failed. */
100
+ export type ToolResult = {
101
+ output: Record<string, unknown>;
102
+ } | {
103
+ error: {
104
+ message: string;
105
+ retryable?: boolean;
106
+ };
107
+ };
108
+ /** What a session token asserts: who is looking at the app's frame, where. */
109
+ export interface SessionClaims extends InstallationRef {
110
+ /** The signed-in dashboard user. */
111
+ userId: string;
112
+ /** Expiry, in unix seconds. */
113
+ exp: number;
114
+ }
115
+ /**
116
+ * Signs a request body for the `picked-signature` header.
117
+ *
118
+ * @param {Signer} signer - Picked's key.
119
+ * @param {string} body - The exact body sent.
120
+ * @param {number} [timestamp] - Unix seconds; now when absent.
121
+ * @returns {Promise<string>} The header value.
122
+ * @example await signBody(signer, '{}')
123
+ */
124
+ export declare function signBody(signer: Signer, body: string, timestamp?: number): Promise<string>;
125
+ /**
126
+ * Checks a `picked-signature` header against a body.
127
+ *
128
+ * @param {PublicKeySet} keys - Picked's public keys.
129
+ * @param {string} body - The exact body received.
130
+ * @param {string | null} header - The header value.
131
+ * @returns {Promise<boolean>} Whether Picked signed the body recently.
132
+ * @example await verifyBody(keys, '{}', request.headers.get('picked-signature'))
133
+ */
134
+ export declare function verifyBody(keys: PublicKeySet, body: string, header: string | null): Promise<boolean>;
135
+ /**
136
+ * Signs an MCP request Picked forwards to an app: the signature covers the installation it
137
+ * is for as well as the JSON-RPC body, which does not name it.
138
+ *
139
+ * @param {Signer} signer - Picked's key.
140
+ * @param {InstallationRef} ref - The installation.
141
+ * @param {string} body - The exact body forwarded.
142
+ * @returns {Promise<Record<string, string>>} The headers to send.
143
+ * @example await signMcpRequest(signer, ref, body)
144
+ */
145
+ export declare function signMcpRequest(signer: Signer, ref: InstallationRef, body: string): Promise<Record<string, string>>;
146
+ /**
147
+ * Checks an MCP request's signature and reads the installation it is for.
148
+ *
149
+ * @param {PublicKeySet} keys - Picked's public keys.
150
+ * @param {Headers} headers - The request's headers.
151
+ * @param {string} body - The exact body received.
152
+ * @returns {Promise<InstallationRef | null>} The installation, or null when the request is not Picked's.
153
+ * @example await verifyMcpRequest(keys, request.headers, body)
154
+ */
155
+ export declare function verifyMcpRequest(keys: PublicKeySet, headers: Headers, body: string): Promise<InstallationRef | null>;
156
+ /**
157
+ * Mints a session token: an EdDSA JWT of the claims, signed by Picked.
158
+ *
159
+ * @param {Signer} signer - Picked's key.
160
+ * @param {SessionClaims} claims - What the token asserts.
161
+ * @returns {Promise<string>} The token.
162
+ * @example await createSessionToken(signer, claims)
163
+ */
164
+ export declare function createSessionToken(signer: Signer, claims: SessionClaims): Promise<string>;
165
+ /**
166
+ * Checks a session token and reads its claims.
167
+ *
168
+ * @param {PublicKeySet} keys - Picked's public keys.
169
+ * @param {string} token - The token the frame was handed.
170
+ * @returns {Promise<SessionClaims | null>} The claims, or null when the token is forged or expired.
171
+ * @example await verifySessionToken(keys, token)
172
+ */
173
+ export declare function verifySessionToken(keys: PublicKeySet, token: string): Promise<SessionClaims | null>;
174
+ /** What an app assertion asserts. */
175
+ export interface AppAssertionClaims {
176
+ /** The installation the app acts for. */
177
+ installationId: string;
178
+ /** The assertion's id, which Picked accepts once. */
179
+ jti: string;
180
+ /** Expiry, in unix seconds. */
181
+ exp: number;
182
+ }
183
+ /**
184
+ * Makes an app assertion: a JWT, signed with the app's key, naming the installation the app
185
+ * acts for and the Picked API it calls. It lives one minute.
186
+ *
187
+ * @param {Signer} signer - The app's key.
188
+ * @param {object} options - What it asserts.
189
+ * @param {string} options.installationId - The installation.
190
+ * @param {string} options.audience - The origin of the Picked API it is sent to.
191
+ * @returns {Promise<string>} The assertion, for the `picked-app-assertion` header.
192
+ * @example await createAppAssertion(signer, { installationId, audience: apiUrl })
193
+ */
194
+ export declare function createAppAssertion(signer: Signer, options: {
195
+ installationId: string;
196
+ audience: string;
197
+ }): Promise<string>;
198
+ /**
199
+ * Checks an app assertion for an audience. One that lives longer than five minutes fails, so
200
+ * a verifier remembers each `jti` for at most that long.
201
+ *
202
+ * @param {PublicKeySet} keys - The app's public keys.
203
+ * @param {string} assertion - The assertion.
204
+ * @param {object} options - What it must assert.
205
+ * @param {string} options.audience - The origin of the Picked API verifying it.
206
+ * @returns {Promise<AppAssertionClaims | null>} Its claims, or null when it fails.
207
+ * @example await verifyAppAssertion(keys, assertion, { audience })
208
+ */
209
+ export declare function verifyAppAssertion(keys: PublicKeySet, assertion: string, options: {
210
+ audience: string;
211
+ }): Promise<AppAssertionClaims | null>;
212
+ /**
213
+ * Reads the installation an app assertion names, without checking it. A verifier uses it to
214
+ * find the app whose keys must then verify the assertion.
215
+ *
216
+ * @param {string} assertion - The assertion.
217
+ * @returns {string | null} The installation, or null when the assertion names none.
218
+ * @example unverifiedAssertionSubject(assertion)
219
+ */
220
+ export declare function unverifiedAssertionSubject(assertion: string): string | null;
221
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAML,KAAK,YAAY,EACjB,KAAK,MAAM,EACZ,MAAM,QAAQ,CA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AO,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC5B,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAgBpC;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAU3E"}
@@ -2,7 +2,7 @@
2
2
  * @file `@picked/app-protocol`: the app manifest, the Ed25519 keys both sides sign with, and the
3
3
  * signed requests, session tokens and app assertions Picked and an app exchange.
4
4
  */
5
- export * from './manifest';
6
- export * from './protocol';
7
- export * from './keys';
5
+ export * from './manifest.js';
6
+ export * from './protocol.js';
7
+ export * from './keys.js';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -8,7 +8,7 @@
8
8
  * way. An app calls Picked with an app assertion: a JWT it signs with its own key, whose
9
9
  * public half it registered on deploy.
10
10
  */
11
- import { type PublicKeySet, type Signer } from './keys';
11
+ import { type PublicKeySet, type Signer } from './keys.js';
12
12
  /** The header a signed request carries. */
13
13
  export declare const SIGNATURE_HEADER = "picked-signature";
14
14
  /** The header naming the installation a request is for. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@picked/app-protocol",
3
3
  "description": "The Picked app contract: the app manifest, Ed25519 keys and the signed requests Picked and an app exchange",
4
- "version": "0.0.117-next.2",
4
+ "version": "0.0.117-next.3",
5
5
  "dependencies": {},
6
6
  "devDependencies": {
7
7
  "@repo/eslint-config": "workspace:*",
@@ -14,9 +14,14 @@
14
14
  },
15
15
  "exports": {
16
16
  ".": {
17
- "types": "./dist/types/index.d.ts",
18
- "import": "./dist/esm/index.js",
19
- "require": "./dist/cjs/index.js",
17
+ "import": {
18
+ "types": "./dist/types/index.d.ts",
19
+ "default": "./dist/esm/index.js"
20
+ },
21
+ "require": {
22
+ "types": "./dist/cjs/index.d.ts",
23
+ "default": "./dist/cjs/index.js"
24
+ },
20
25
  "default": "./dist/esm/index.js"
21
26
  }
22
27
  },
@@ -48,13 +53,14 @@
48
53
  "access": "public"
49
54
  },
50
55
  "scripts": {
51
- "build": "vite build && tsgo -p tsconfig.build.json",
56
+ "build": "vite build && tsgo -p tsconfig.build.json && node ../../scripts/sdk-dist.mjs",
52
57
  "dev": "node ../../scripts/sdk-watch-build.mjs",
53
58
  "lint": "eslint .",
54
59
  "lint-files": "eslint",
55
60
  "lint:report": "eslint . -o './.reports/eslint.json' -f json || true",
56
61
  "test": "vitest run",
57
62
  "test:coverage": "../../scripts/vitest-coverage.sh",
63
+ "test:packaged-types": "attw --pack --profile node16",
58
64
  "type-check": "tsgo -p . --noEmit"
59
65
  },
60
66
  "type": "module",