keycloak-api 0.0.0
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/.turbo/turbo-build.log +24 -0
- package/README.md +8 -0
- package/dist/index.cjs +88 -0
- package/dist/index.d.cts +11320 -0
- package/dist/index.d.mts +11320 -0
- package/dist/index.d.ts +11320 -0
- package/dist/index.mjs +86 -0
- package/package.json +41 -0
- package/tsconfig.json +19 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
function notEmpty(value) {
|
|
2
|
+
return value !== null && value !== void 0;
|
|
3
|
+
}
|
|
4
|
+
function compactObject(obj) {
|
|
5
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async function fetch$1({
|
|
9
|
+
url,
|
|
10
|
+
method,
|
|
11
|
+
body,
|
|
12
|
+
headers,
|
|
13
|
+
pathParams,
|
|
14
|
+
queryParams,
|
|
15
|
+
signal,
|
|
16
|
+
baseUrl,
|
|
17
|
+
token,
|
|
18
|
+
fetchImpl
|
|
19
|
+
}) {
|
|
20
|
+
try {
|
|
21
|
+
const requestHeaders = compactObject({
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
Authorization: token ? `Bearer ${token}` : void 0,
|
|
24
|
+
...headers
|
|
25
|
+
});
|
|
26
|
+
if (requestHeaders["Content-Type"]?.toLowerCase().includes("multipart/form-data")) {
|
|
27
|
+
delete requestHeaders["Content-Type"];
|
|
28
|
+
}
|
|
29
|
+
const payload = body instanceof FormData ? body : requestHeaders["Content-Type"] === "application/json" ? JSON.stringify(body) : body;
|
|
30
|
+
const response = await fetchImpl(`${baseUrl}${resolveUrl(url, queryParams, pathParams)}`, {
|
|
31
|
+
signal,
|
|
32
|
+
method: method.toUpperCase(),
|
|
33
|
+
body: payload,
|
|
34
|
+
headers: requestHeaders
|
|
35
|
+
});
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
let error;
|
|
38
|
+
try {
|
|
39
|
+
error = await response.json();
|
|
40
|
+
} catch (e) {
|
|
41
|
+
error = {
|
|
42
|
+
status: "unknown",
|
|
43
|
+
payload: e instanceof Error ? `Unexpected error (${e.message})` : "Unexpected error"
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
if (response.headers?.get("content-type")?.includes("json")) {
|
|
49
|
+
return await response.json();
|
|
50
|
+
} else {
|
|
51
|
+
return await response.text();
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
let errorObject = {
|
|
55
|
+
name: "unknown",
|
|
56
|
+
message: e instanceof Error ? `Network error (${e.message})` : "Network error",
|
|
57
|
+
stack: e
|
|
58
|
+
};
|
|
59
|
+
throw errorObject;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
63
|
+
let query = new URLSearchParams(queryParams).toString();
|
|
64
|
+
if (query) query = `?${query}`;
|
|
65
|
+
return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)] ?? "") + query;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
class KeycloakApi {
|
|
69
|
+
#baseUrl;
|
|
70
|
+
#token;
|
|
71
|
+
#fetch;
|
|
72
|
+
constructor(options) {
|
|
73
|
+
this.#baseUrl = options.baseUrl;
|
|
74
|
+
this.#token = options.token;
|
|
75
|
+
this.#fetch = options.fetch || fetch;
|
|
76
|
+
if (!this.#fetch) throw new Error("Fetch is required");
|
|
77
|
+
}
|
|
78
|
+
async request(endpoint, params) {
|
|
79
|
+
const [method = "", url = ""] = endpoint.split(" ");
|
|
80
|
+
const extraParams = params || {};
|
|
81
|
+
const result = await fetch$1({ ...extraParams, method, url, baseUrl: this.#baseUrl, token: this.#token, fetchImpl: this.#fetch });
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { KeycloakApi };
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "keycloak-api",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "keycloak API client for Node.js",
|
|
5
|
+
"author": "SferaDev",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/SferaDev/openapi-clients/issues"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/SferaDev/openapi-clients#readme",
|
|
11
|
+
"main": "dist/index.cjs",
|
|
12
|
+
"module": "dist/index.mjs",
|
|
13
|
+
"typings": "dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
".": {
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"default": "./dist/index.mjs"
|
|
20
|
+
},
|
|
21
|
+
"require": {
|
|
22
|
+
"types": "./dist/index.d.cts",
|
|
23
|
+
"default": "./dist/index.cjs"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"tsc": "tsc --noEmit",
|
|
29
|
+
"build": "unbuild",
|
|
30
|
+
"prepack": "unbuild",
|
|
31
|
+
"generate": "openapi-codegen admin"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/SferaDev/openapi-clients.git"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"case": "^1.6.3",
|
|
39
|
+
"openapi3-ts": "^4.4.0"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2020",
|
|
4
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
+
"module": "esnext",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"noImplicitAny": true,
|
|
11
|
+
"strictNullChecks": true,
|
|
12
|
+
"noUnusedLocals": true,
|
|
13
|
+
"noUnusedParameters": true,
|
|
14
|
+
"exactOptionalPropertyTypes": true,
|
|
15
|
+
"noImplicitReturns": true,
|
|
16
|
+
"noFallthroughCasesInSwitch": true,
|
|
17
|
+
"noUncheckedIndexedAccess": true
|
|
18
|
+
}
|
|
19
|
+
}
|