@okam/directus-next-component 2.1.1 → 2.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 2.1.2 (2026-04-09)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - **directus-next-component:** safer directus URL creation ([#470](https://github.com/OKAMca/stack/pull/470))
6
+ - resolve dependabot security alerts and clean up published package dependencies ([#441](https://github.com/OKAMca/stack/pull/441))
7
+
8
+ ### ❤️ Thank You
9
+
10
+ - Claude Opus 4.6 (1M context)
11
+ - Marie-Maxime Tanguay @marie-maxime
12
+ - Pierre-Olivier Clerson @poclerson
13
+
1
14
  ## 2.1.0 (2026-04-06)
2
15
 
3
16
  ### 🩹 Fixes
package/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export { default as DirectusVideo } from './components/DirectusVideo';
8
8
  export type { TDirectusVideoProps } from './components/DirectusVideo/interface';
9
9
  export { logger as DirectusNextComponent } from './logger';
10
10
  export type * from './types';
11
- export { getDirectusFile, useDirectusFile } from './utils/getDirectusFile';
11
+ export { getDirectusFile, getDirectusUrl, useDirectusFile } from './utils/getDirectusFile';
12
12
  export { getDirectusLink, useDirectusLink } from './utils/getDirectusLink';
13
13
  export { getMetadata, useMetadata } from './utils/getDirectusMetadata';
14
14
  export { getDirectusSearchParams } from './utils/getDirectusSearchParams';
package/index.js CHANGED
@@ -16,6 +16,7 @@ exports.DirectusLink = index$2;
16
16
  exports.DirectusVideo = index$3;
17
17
  exports.DirectusNextComponent = logger.logger;
18
18
  exports.getDirectusFile = index$4.getDirectusFile;
19
+ exports.getDirectusUrl = index$4.getDirectusUrl;
19
20
  exports.useDirectusFile = index$4.useDirectusFile;
20
21
  exports.getDirectusLink = index$5.getDirectusLink;
21
22
  exports.useDirectusLink = index$5.useDirectusLink;
package/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { default as default3 } from "./components/DirectusImg/index.mjs";
3
3
  import { default as default4 } from "./components/DirectusLink/index.mjs";
4
4
  import { default as default5 } from "./components/DirectusVideo/index.mjs";
5
5
  import { logger } from "./logger.mjs";
6
- import { getDirectusFile, useDirectusFile } from "./utils/getDirectusFile/index.mjs";
6
+ import { getDirectusFile, getDirectusUrl, useDirectusFile } from "./utils/getDirectusFile/index.mjs";
7
7
  import { getDirectusLink, useDirectusLink } from "./utils/getDirectusLink/index.mjs";
8
8
  import { getMetadata, useMetadata } from "./utils/getDirectusMetadata/index.mjs";
9
9
  import { getDirectusSearchParams } from "./utils/getDirectusSearchParams/index.mjs";
@@ -17,6 +17,7 @@ export {
17
17
  getDirectusFile,
18
18
  getDirectusLink,
19
19
  getDirectusSearchParams,
20
+ getDirectusUrl,
20
21
  getMetadata,
21
22
  getNavigationItems,
22
23
  useDirectusFile,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@okam/directus-next-component",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "repository": {
5
5
  "url": "https://github.com/OKAMca/stack.git"
6
6
  },
@@ -1,6 +1,20 @@
1
1
  import { TFiles } from '@okam/directus-next';
2
2
  import { Nullable } from '@okam/stack-ui';
3
+ /**
4
+ * Creates a Directus asset URL from a Directus file
5
+ * @param file Directus file to create the asset URL from
6
+ * @param baseUrl Override Directus asset URL creation. By default, this falls back to `NEXT_PUBLIC_IMG_DOMAIN`, `NEXT_PUBLIC_IMG_PORT` and `NEXT_PUBLIC_IMG_PROTOCOL`
7
+ * @param searchParams Additional search params to append to the URL
8
+ * @returns Directus asset URL
9
+ */
3
10
  export declare function getDirectusUrl(file: Nullable<TFiles>, baseUrl?: URL, searchParams?: Record<string, Nullable<string>>): URL | null;
11
+ /**
12
+ * Wrapper for {@link getDirectusUrl} to format a Directus file into `next/image` `Image` props
13
+ * @param file Directus file to create the asset URL from
14
+ * @param baseUrl Override Directus asset URL creation. By default, this falls back to `NEXT_PUBLIC_IMG_DOMAIN`, `NEXT_PUBLIC_IMG_PORT` and `NEXT_PUBLIC_IMG_PROTOCOL`
15
+ * @param searchParams Additional search params to append to the URL
16
+ * @returns Props ready to be passed to `next/image` `Image` component
17
+ */
4
18
  export declare function getDirectusFile(file: Nullable<TFiles>, baseUrl?: URL, searchParams?: Record<string, Nullable<string>>): {
5
19
  tags?: unknown;
6
20
  location?: string | null;
@@ -1,39 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const radashi = require("radashi");
3
4
  const logger = require("../../logger.js");
4
5
  const IMG_DOMAIN = process.env.NEXT_PUBLIC_IMG_DOMAIN;
5
6
  const IMG_PORT = process.env.NEXT_PUBLIC_IMG_PORT;
6
7
  const IMG_PROTOCOL = process.env.NEXT_PUBLIC_IMG_PROTOCOL ?? "https";
7
- function setSearchParams(url, searchParams) {
8
- Object.entries(searchParams).forEach(([key, value]) => {
9
- if (value == null || value === "")
10
- return;
11
- url.searchParams.set(key, value);
12
- });
13
- }
14
8
  function getDirectusUrl(file, baseUrl, searchParams) {
15
9
  const { id, filename_download, filenameDownload } = file ?? {};
16
- const { protocol = IMG_PROTOCOL, port = IMG_PORT, hostname = IMG_DOMAIN } = baseUrl ?? {};
17
- if (hostname == null || hostname === "" || id == null || id === "")
10
+ const protocol = (baseUrl?.protocol ?? IMG_PROTOCOL).replace(/:$/, "");
11
+ const hostname = baseUrl?.hostname ?? IMG_DOMAIN;
12
+ const port = baseUrl?.port ?? IMG_PORT;
13
+ if (radashi.isEmpty(hostname) || radashi.isEmpty(id)) {
14
+ logger.logger.log("Invalid props or environment variables", "warn", { hostname, props: file });
18
15
  return null;
16
+ }
19
17
  try {
20
18
  const url = new URL(`/assets/${id}/${filename_download ?? filenameDownload ?? ""}`, `${protocol}://${hostname}`);
21
- if (port != null && port !== "")
19
+ if (!radashi.isEmpty(port))
22
20
  url.port = port;
23
- if (searchParams != null)
24
- setSearchParams(url, searchParams);
21
+ if (!radashi.isNullish(searchParams)) {
22
+ for (const [key, value] of Object.entries(searchParams)) {
23
+ if (!radashi.isEmpty(value))
24
+ url.searchParams.set(key, value);
25
+ }
26
+ }
25
27
  return url;
26
28
  } catch (error) {
27
- logger.logger.log("Couldn't create URL", "warn", { error });
29
+ logger.logger.log("Couldn't create URL", "warn", { error, props: file });
28
30
  return null;
29
31
  }
30
32
  }
31
33
  function getDirectusFile(file, baseUrl, searchParams) {
32
34
  const { description, width, height, title, id, ...rest } = file ?? {};
33
- if (file == null || id == null || id === "")
35
+ if (radashi.isEmpty(file) || radashi.isEmpty(id))
34
36
  return null;
35
37
  const url = getDirectusUrl(file, baseUrl, searchParams);
36
- if (url == null)
38
+ if (radashi.isNullish(url))
37
39
  return null;
38
40
  return {
39
41
  src: url.href,
@@ -1,37 +1,39 @@
1
+ import { isEmpty, isNullish } from "radashi";
1
2
  import { logger } from "../../logger.mjs";
2
3
  const IMG_DOMAIN = process.env.NEXT_PUBLIC_IMG_DOMAIN;
3
4
  const IMG_PORT = process.env.NEXT_PUBLIC_IMG_PORT;
4
5
  const IMG_PROTOCOL = process.env.NEXT_PUBLIC_IMG_PROTOCOL ?? "https";
5
- function setSearchParams(url, searchParams) {
6
- Object.entries(searchParams).forEach(([key, value]) => {
7
- if (value == null || value === "")
8
- return;
9
- url.searchParams.set(key, value);
10
- });
11
- }
12
6
  function getDirectusUrl(file, baseUrl, searchParams) {
13
7
  const { id, filename_download, filenameDownload } = file ?? {};
14
- const { protocol = IMG_PROTOCOL, port = IMG_PORT, hostname = IMG_DOMAIN } = baseUrl ?? {};
15
- if (hostname == null || hostname === "" || id == null || id === "")
8
+ const protocol = (baseUrl?.protocol ?? IMG_PROTOCOL).replace(/:$/, "");
9
+ const hostname = baseUrl?.hostname ?? IMG_DOMAIN;
10
+ const port = baseUrl?.port ?? IMG_PORT;
11
+ if (isEmpty(hostname) || isEmpty(id)) {
12
+ logger.log("Invalid props or environment variables", "warn", { hostname, props: file });
16
13
  return null;
14
+ }
17
15
  try {
18
16
  const url = new URL(`/assets/${id}/${filename_download ?? filenameDownload ?? ""}`, `${protocol}://${hostname}`);
19
- if (port != null && port !== "")
17
+ if (!isEmpty(port))
20
18
  url.port = port;
21
- if (searchParams != null)
22
- setSearchParams(url, searchParams);
19
+ if (!isNullish(searchParams)) {
20
+ for (const [key, value] of Object.entries(searchParams)) {
21
+ if (!isEmpty(value))
22
+ url.searchParams.set(key, value);
23
+ }
24
+ }
23
25
  return url;
24
26
  } catch (error) {
25
- logger.log("Couldn't create URL", "warn", { error });
27
+ logger.log("Couldn't create URL", "warn", { error, props: file });
26
28
  return null;
27
29
  }
28
30
  }
29
31
  function getDirectusFile(file, baseUrl, searchParams) {
30
32
  const { description, width, height, title, id, ...rest } = file ?? {};
31
- if (file == null || id == null || id === "")
33
+ if (isEmpty(file) || isEmpty(id))
32
34
  return null;
33
35
  const url = getDirectusUrl(file, baseUrl, searchParams);
34
- if (url == null)
36
+ if (isNullish(url))
35
37
  return null;
36
38
  return {
37
39
  src: url.href,