@vocalstack/payload 0.8.0 → 0.8.1

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/README.md CHANGED
@@ -188,7 +188,7 @@ Transcripts stay in the workspace that made them. After a change, the transcript
188
188
 
189
189
  ## One-click connect (protocol)
190
190
 
191
- The alternative to pasting a key: **Connect VocalStack** opens the dashboard in a new tab, the person chooses a workspace and clicks **Authenticate**, and the tab closes. **Change** runs the same flow while connected; the stored key is replaced only once the new one has been issued. This is OAuth 2.0 authorization code + PKCE (RFC 7636) with an API key as the access token. There is no client registration: the consent screen shows the `redirect_uri` host instead.
191
+ The alternative to pasting a key: **Connect VocalStack** opens the dashboard in a new tab, the person chooses a workspace and clicks **Authenticate**, and the tab closes. **Change** runs the same flow while connected; the stored key is replaced only once the new one has been issued. While connected, the link also carries `workspace=<id>` (the workspace of the key in use), so the consent screen starts on that workspace; it is left out when the workspace cannot be told. This is OAuth 2.0 authorization code + PKCE (RFC 7636) with an API key as the access token. There is no client registration: the consent screen shows the `redirect_uri` host instead.
192
192
 
193
193
  ```
194
194
  CMS admin CMS server app.vocalstack.com / api.vocalstack.com
@@ -8,6 +8,7 @@ export declare const forgetOwners: () => void;
8
8
  *
9
9
  * 1. POST /api/vocalstack/connect → state + verifier stored here; the admin opens
10
10
  * {dashboard}/connect?response_type=code&redirect_uri=…&state=…&code_challenge=…
11
+ * (and workspace=<id> of the key in use, so the consent screen starts on it)
11
12
  * 2. The person clicks Authenticate on the dashboard, which redirects to
12
13
  * /api/vocalstack/callback?code=…&state=…
13
14
  * 3. The callback redeems the code server-to-server at {api}/v1/connect/token with
@@ -42,12 +42,24 @@ async function lookUpOwner(apiKey, apiURL) {
42
42
  remember(apiKey, apiURL, last, owner ? OWNER_FRESH_MS : OWNER_RETRY_MS);
43
43
  return last;
44
44
  }
45
+ /**
46
+ * The id of the workspace a key belongs to, for the consent screen to start on. A key
47
+ * never changes workspace, so what was read before is used however old it is; a key not
48
+ * read yet is asked about with the usual time limit. `undefined` when it cannot be told.
49
+ */
50
+ async function workspaceIdOf(apiKey, apiURL) {
51
+ const known = owners.get(ownerKey(apiKey, apiURL))?.owner?.workspace?.id;
52
+ if (known)
53
+ return known;
54
+ return (await lookUpOwner(apiKey, apiURL))?.workspace?.id;
55
+ }
45
56
  /**
46
57
  * One-click connect, as OAuth 2.0 authorization code + PKCE (RFC 7636) whose
47
58
  * token is a VocalStack API key:
48
59
  *
49
60
  * 1. POST /api/vocalstack/connect → state + verifier stored here; the admin opens
50
61
  * {dashboard}/connect?response_type=code&redirect_uri=…&state=…&code_challenge=…
62
+ * (and workspace=<id> of the key in use, so the consent screen starts on it)
51
63
  * 2. The person clicks Authenticate on the dashboard, which redirects to
52
64
  * /api/vocalstack/callback?code=…&state=…
53
65
  * 3. The callback redeems the code server-to-server at {api}/v1/connect/token with
@@ -135,7 +147,7 @@ export function connectionEndpoints(options) {
135
147
  await writeSettings(req, { connectExpiresAt: new Date(Date.now() + CONNECT_TTL_MS).toISOString(), connectState: state, connectVerifier: verifier });
136
148
  const site = new URL(req.payload.config.serverURL || req.origin);
137
149
  const url = new URL('/connect', dashboardURL);
138
- url.search = new URLSearchParams({
150
+ const query = new URLSearchParams({
139
151
  client_name: `${site.host} (Payload CMS)`,
140
152
  code_challenge: challenge,
141
153
  code_challenge_method: 'S256',
@@ -143,7 +155,15 @@ export function connectionEndpoints(options) {
143
155
  response_type: 'code',
144
156
  scope: 'read write',
145
157
  state,
146
- }).toString();
158
+ });
159
+ // Already connected: the consent screen starts on the workspace in use. Left out when it cannot be told.
160
+ const workspace = await (async () => {
161
+ const apiKey = options.apiKey ?? (await readSettings(req)).apiKey;
162
+ return apiKey ? await workspaceIdOf(apiKey, apiURL) : undefined;
163
+ })().catch(() => undefined);
164
+ if (workspace)
165
+ query.set('workspace', workspace);
166
+ url.search = query.toString();
147
167
  return json({ url: url.toString() });
148
168
  },
149
169
  },
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export declare const PACKAGE_NAME = "@vocalstack/payload";
2
- export declare const VERSION = "0.8.0";
2
+ export declare const VERSION = "0.8.1";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Written by scripts/version.mjs from package.json. Do not edit.
2
2
  export const PACKAGE_NAME = "@vocalstack/payload";
3
- export const VERSION = "0.8.0";
3
+ export const VERSION = "0.8.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocalstack/payload",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "VocalStack for Payload CMS: transcribe audio, translate it into other languages and read it aloud, kept in your own database and storage.",
5
5
  "license": "MIT",
6
6
  "type": "module",