@keycloak/keycloak-admin-client 26.4.5 → 26.4.6

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,6 +1,6 @@
1
- import urlJoin from "url-join";
2
1
  import { parseTemplate } from "url-template";
3
2
  import { fetchWithError, NetworkError, parseResponse, } from "../utils/fetchWithError.js";
3
+ import { joinPath } from "../utils/joinPath.js";
4
4
  import { stringifyQueryParams } from "../utils/stringifyQueryParams.js";
5
5
  // constants
6
6
  const SLASH = "/";
@@ -85,11 +85,6 @@ export class Agent {
85
85
  };
86
86
  }
87
87
  async #requestWithParams({ method, path, payload, urlParams, queryParams, catchNotFound, payloadKey, returnResourceIdInLocationHeader, headers, }) {
88
- const newPath = urlJoin(this.#basePath, path);
89
- // Parse template and replace with values from urlParams
90
- const pathTemplate = parseTemplate(newPath);
91
- const parsedPath = pathTemplate.expand(urlParams);
92
- const url = new URL(`${this.#getBaseUrl?.() ?? ""}${parsedPath}`);
93
88
  const requestOptions = { ...this.#client.getRequestOptions() };
94
89
  const requestHeaders = new Headers([
95
90
  ...new Headers(requestOptions.headers).entries(),
@@ -124,6 +119,9 @@ export class Agent {
124
119
  if (queryParams) {
125
120
  Object.assign(searchParams, queryParams);
126
121
  }
122
+ const url = new URL(this.#getBaseUrl());
123
+ const pathTemplate = parseTemplate(joinPath(this.#basePath, path));
124
+ url.pathname = joinPath(url.pathname, pathTemplate.expand(urlParams));
127
125
  url.search = stringifyQueryParams(searchParams);
128
126
  try {
129
127
  const res = await fetchWithError(url, {
package/lib/utils/auth.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import camelize from "camelize-ts";
2
+ import { parseTemplate } from "url-template";
2
3
  import { defaultBaseUrl, defaultRealm } from "./constants.js";
3
4
  import { fetchWithError } from "./fetchWithError.js";
5
+ import { joinPath } from "./joinPath.js";
4
6
  import { stringifyQueryParams } from "./stringifyQueryParams.js";
5
7
  // See: https://developer.mozilla.org/en-US/docs/Glossary/Base64
6
8
  const bytesToBase64 = (bytes) => btoa(Array.from(bytes, (byte) => String.fromCodePoint(byte)).join(""));
@@ -11,10 +13,11 @@ const encodeRFC3986URIComponent = (input) => encodeURIComponent(input).replace(/
11
13
  // Specifically, the section on encoding `application/x-www-form-urlencoded`.
12
14
  const encodeFormURIComponent = (data) => encodeRFC3986URIComponent(data).replaceAll("%20", "+");
13
15
  export const getToken = async (settings) => {
14
- // Construct URL
15
- const baseUrl = settings.baseUrl || defaultBaseUrl;
16
- const realmName = settings.realmName || defaultRealm;
17
- const url = `${baseUrl}/realms/${realmName}/protocol/openid-connect/token`;
16
+ const url = new URL(settings.baseUrl ?? defaultBaseUrl);
17
+ const pathTemplate = parseTemplate("/realms/{realmName}/protocol/openid-connect/token");
18
+ url.pathname = joinPath(url.pathname, pathTemplate.expand({
19
+ realmName: settings.realmName ?? defaultRealm,
20
+ }));
18
21
  // Prepare credentials for openid-connect token request
19
22
  // ref: http://openid.net/specs/openid-connect-core-1_0.html#TokenEndpoint
20
23
  const credentials = settings.credentials || {};
@@ -0,0 +1 @@
1
+ export declare function joinPath(...paths: string[]): string;
@@ -0,0 +1,17 @@
1
+ const PATH_SEPARATOR = "/";
2
+ export function joinPath(...paths) {
3
+ const normalizedPaths = paths.map((path, index) => {
4
+ const isFirst = index === 0;
5
+ const isLast = index === paths.length - 1;
6
+ // Strip out any leading slashes from the path.
7
+ if (!isFirst && path.startsWith(PATH_SEPARATOR)) {
8
+ path = path.slice(1);
9
+ }
10
+ // Strip out any trailing slashes from the path.
11
+ if (!isLast && path.endsWith(PATH_SEPARATOR)) {
12
+ path = path.slice(0, -1);
13
+ }
14
+ return path;
15
+ }, []);
16
+ return normalizedPaths.join(PATH_SEPARATOR);
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keycloak/keycloak-admin-client",
3
- "version": "26.4.5",
3
+ "version": "26.4.6",
4
4
  "description": "A client to interact with Keycloak's Administration API",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -34,7 +34,6 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "camelize-ts": "^3.0.0",
37
- "url-join": "^5.0.0",
38
37
  "url-template": "^3.1.1"
39
38
  },
40
39
  "devDependencies": {