windmill-components 1.700.1 → 1.700.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.
@@ -1,8 +1,10 @@
1
1
  /**
2
- * When OpenAPI.TOKEN is set we cannot rely on a plain `<a href>` browser navigation
3
- * because the browser does not attach the Authorization header. In that case fetch
4
- * the file via the OpenAPI client (which uses OpenAPI.BASE and the Bearer token) and
5
- * trigger a download from a blob URL. Otherwise let the default link behavior happen.
2
+ * When OpenAPI is configured to authenticate via headers (TOKEN, basic auth,
3
+ * or arbitrary HEADERS) we cannot rely on a plain `<a href>` browser
4
+ * navigation because the browser does not attach those headers. In that case
5
+ * fetch the file via the OpenAPI client (which carries the configured auth)
6
+ * and trigger a download from a blob URL. Cookie-only auth still works with
7
+ * a plain link.
6
8
  *
7
9
  * `apiPath` should be the path relative to OpenAPI.BASE, starting with `/`
8
10
  * (e.g. `/w/foo/job_helpers/download_s3_file?file_key=...`).
@@ -1,31 +1,25 @@
1
1
  import { OpenAPI } from '../gen';
2
+ import { getHeaders } from '../gen/core/request';
2
3
  import { sendUserToast } from '../toast';
3
- async function resolveToken() {
4
- const t = OpenAPI.TOKEN;
5
- if (!t)
6
- return undefined;
7
- return typeof t === 'string' ? t : await t({});
8
- }
9
4
  /**
10
- * When OpenAPI.TOKEN is set we cannot rely on a plain `<a href>` browser navigation
11
- * because the browser does not attach the Authorization header. In that case fetch
12
- * the file via the OpenAPI client (which uses OpenAPI.BASE and the Bearer token) and
13
- * trigger a download from a blob URL. Otherwise let the default link behavior happen.
5
+ * When OpenAPI is configured to authenticate via headers (TOKEN, basic auth,
6
+ * or arbitrary HEADERS) we cannot rely on a plain `<a href>` browser
7
+ * navigation because the browser does not attach those headers. In that case
8
+ * fetch the file via the OpenAPI client (which carries the configured auth)
9
+ * and trigger a download from a blob URL. Cookie-only auth still works with
10
+ * a plain link.
14
11
  *
15
12
  * `apiPath` should be the path relative to OpenAPI.BASE, starting with `/`
16
13
  * (e.g. `/w/foo/job_helpers/download_s3_file?file_key=...`).
17
14
  */
18
15
  export function shouldDownloadViaClient() {
19
- return Boolean(OpenAPI.TOKEN);
16
+ return Boolean(OpenAPI.TOKEN || OpenAPI.HEADERS || OpenAPI.USERNAME);
20
17
  }
21
18
  export async function downloadViaClient(apiPath, filename) {
22
- const token = await resolveToken();
23
19
  const url = `${OpenAPI.BASE}${apiPath}`;
24
- const headers = {};
25
- if (token)
26
- headers['Authorization'] = `Bearer ${token}`;
27
20
  let response;
28
21
  try {
22
+ const headers = await getHeaders(OpenAPI, { method: 'GET', url: apiPath });
29
23
  response = await fetch(url, { headers, credentials: OpenAPI.CREDENTIALS });
30
24
  }
31
25
  catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "windmill-components",
3
- "version": "1.700.1",
3
+ "version": "1.700.2",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build",