keycloakify 7.11.0 → 7.11.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
@@ -44,7 +44,7 @@
|
|
44
44
|
We are exclusively sponsored by [Cloud IAM](https://www.cloud-iam.com), a French company offering Keycloak as a service.
|
45
45
|
Their dedicated support helps us continue the development and maintenance of this project.
|
46
46
|
|
47
|
-
[Cloud IAM](https://
|
47
|
+
[Cloud IAM](https://cloud-iam.com/?mtm_campaign=keycloakify-deal&mtm_source=keycloakify-github) provides the following services:
|
48
48
|
|
49
49
|
- Simplify and secure your Keycloak Identity and Access Management. Keycloak as a Service.
|
50
50
|
- Custom theme building for your brand using Keycloakify.
|
@@ -59,7 +59,7 @@ Their dedicated support helps us continue the development and maintenance of thi
|
|
59
59
|
<i>5% of your annual subscription will be donated to us, and you'll get 5% off too.</i>
|
60
60
|
</p>
|
61
61
|
|
62
|
-
Thank you, [Cloud IAM](https://
|
62
|
+
Thank you, [Cloud IAM](https://cloud-iam.com/?mtm_campaign=keycloakify-deal&mtm_source=keycloakify-github), for your support!
|
63
63
|
|
64
64
|
## Contributors ✨
|
65
65
|
|
@@ -62,6 +62,15 @@ var __read = (this && this.__read) || function (o, n) {
|
|
62
62
|
}
|
63
63
|
return ar;
|
64
64
|
};
|
65
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
66
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
67
|
+
if (ar || !(i in from)) {
|
68
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
69
|
+
ar[i] = from[i];
|
70
|
+
}
|
71
|
+
}
|
72
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
73
|
+
};
|
65
74
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
66
75
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
67
76
|
};
|
@@ -102,10 +111,34 @@ function exists(path) {
|
|
102
111
|
});
|
103
112
|
});
|
104
113
|
}
|
114
|
+
function ensureArray(arg0) {
|
115
|
+
return Array.isArray(arg0) ? arg0 : typeof arg0 === "undefined" ? [] : [arg0];
|
116
|
+
}
|
117
|
+
function ensureSingleOrNone(arg0) {
|
118
|
+
if (!Array.isArray(arg0))
|
119
|
+
return arg0;
|
120
|
+
if (arg0.length === 0)
|
121
|
+
return undefined;
|
122
|
+
if (arg0.length === 1)
|
123
|
+
return arg0[0];
|
124
|
+
throw new Error("Illegal configuration, expected a single value but found multiple: " + arg0.map(String).join(", "));
|
125
|
+
}
|
126
|
+
var npmConfigReducer = function (cfg, _a) {
|
127
|
+
var _b, _c;
|
128
|
+
var _d = __read(_a, 2), key = _d[0], value = _d[1];
|
129
|
+
return key in cfg ? __assign(__assign({}, cfg), (_b = {}, _b[key] = __spreadArray(__spreadArray([], __read(ensureArray(cfg[key])), false), [value], false), _b)) : __assign(__assign({}, cfg), (_c = {}, _c[key] = value, _c));
|
130
|
+
};
|
105
131
|
/**
|
106
132
|
* Get npm configuration as map
|
107
133
|
*/
|
108
134
|
function getNmpConfig() {
|
135
|
+
return __awaiter(this, void 0, void 0, function () {
|
136
|
+
return __generator(this, function (_a) {
|
137
|
+
return [2 /*return*/, readNpmConfig().then(parseNpmConfig)];
|
138
|
+
});
|
139
|
+
});
|
140
|
+
}
|
141
|
+
function readNpmConfig() {
|
109
142
|
return __awaiter(this, void 0, void 0, function () {
|
110
143
|
var stdout;
|
111
144
|
return __generator(this, function (_a) {
|
@@ -113,38 +146,69 @@ function getNmpConfig() {
|
|
113
146
|
case 0: return [4 /*yield*/, exec("npm config get", { encoding: "utf8" })];
|
114
147
|
case 1:
|
115
148
|
stdout = (_a.sent()).stdout;
|
116
|
-
return [2 /*return*/, stdout
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
149
|
+
return [2 /*return*/, stdout];
|
150
|
+
}
|
151
|
+
});
|
152
|
+
});
|
153
|
+
}
|
154
|
+
function parseNpmConfig(stdout) {
|
155
|
+
return stdout
|
156
|
+
.split("\n")
|
157
|
+
.filter(function (line) { return !line.startsWith(";"); })
|
158
|
+
.map(function (line) { return line.trim(); })
|
159
|
+
.map(function (line) { return line.split("=", 2); })
|
160
|
+
.reduce(npmConfigReducer, {});
|
161
|
+
}
|
162
|
+
function maybeBoolean(arg0) {
|
163
|
+
return typeof arg0 === "undefined" ? undefined : Boolean(arg0);
|
164
|
+
}
|
165
|
+
function chunks(arr, size) {
|
166
|
+
if (size === void 0) { size = 2; }
|
167
|
+
return arr.map(function (_, i) { return i % size == 0 && arr.slice(i, i + size); }).filter(Boolean);
|
168
|
+
}
|
169
|
+
function readCafile(cafile) {
|
170
|
+
return __awaiter(this, void 0, void 0, function () {
|
171
|
+
var cafileContent;
|
172
|
+
return __generator(this, function (_a) {
|
173
|
+
switch (_a.label) {
|
174
|
+
case 0: return [4 /*yield*/, (0, promises_1.readFile)(cafile, "utf-8")];
|
175
|
+
case 1:
|
176
|
+
cafileContent = _a.sent();
|
177
|
+
return [2 /*return*/, chunks(cafileContent.split(/(-----END CERTIFICATE-----)/), 2).map(function (ca) { return ca.join("").replace(/^\n/, "").replace(/\n/g, "\\n"); })];
|
126
178
|
}
|
127
179
|
});
|
128
180
|
});
|
129
181
|
}
|
130
182
|
/**
|
131
|
-
* Get proxy configuration from npm config files. Note that we don't care about
|
183
|
+
* Get proxy and ssl configuration from npm config files. Note that we don't care about
|
132
184
|
* proxy config in env vars, because make-fetch-happen will do that for us.
|
133
185
|
*
|
134
186
|
* @returns proxy configuration
|
135
187
|
*/
|
136
|
-
function
|
137
|
-
var _a, _b;
|
188
|
+
function getFetchOptions() {
|
189
|
+
var _a, _b, _c;
|
138
190
|
return __awaiter(this, void 0, void 0, function () {
|
139
|
-
var cfg, proxy, noProxy;
|
140
|
-
return __generator(this, function (
|
141
|
-
switch (
|
191
|
+
var cfg, proxy, noProxy, strictSSL, cert, ca, cafile, _d, _e, _f, _g;
|
192
|
+
return __generator(this, function (_h) {
|
193
|
+
switch (_h.label) {
|
142
194
|
case 0: return [4 /*yield*/, getNmpConfig()];
|
143
195
|
case 1:
|
144
|
-
cfg =
|
145
|
-
proxy = (_a = cfg["https-proxy"]) !== null && _a !== void 0 ? _a : cfg["proxy"];
|
196
|
+
cfg = _h.sent();
|
197
|
+
proxy = ensureSingleOrNone((_a = cfg["https-proxy"]) !== null && _a !== void 0 ? _a : cfg["proxy"]);
|
146
198
|
noProxy = (_b = cfg["noproxy"]) !== null && _b !== void 0 ? _b : cfg["no-proxy"];
|
147
|
-
|
199
|
+
strictSSL = maybeBoolean(ensureSingleOrNone(cfg["strict-ssl"]));
|
200
|
+
cert = cfg["cert"];
|
201
|
+
ca = ensureArray((_c = cfg["ca"]) !== null && _c !== void 0 ? _c : cfg["ca[]"]);
|
202
|
+
cafile = ensureSingleOrNone(cfg["cafile"]);
|
203
|
+
if (!(typeof cafile !== "undefined" && cafile !== "null")) return [3 /*break*/, 3];
|
204
|
+
_e = (_d = ca.push).apply;
|
205
|
+
_f = [ca];
|
206
|
+
_g = [[]];
|
207
|
+
return [4 /*yield*/, readCafile(cafile)];
|
208
|
+
case 2:
|
209
|
+
_e.apply(_d, _f.concat([__spreadArray.apply(void 0, _g.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
|
210
|
+
_h.label = 3;
|
211
|
+
case 3: return [2 /*return*/, { proxy: proxy, noProxy: noProxy, strictSSL: strictSSL, cert: cert, ca: ca.length === 0 ? undefined : ca }];
|
148
212
|
}
|
149
213
|
});
|
150
214
|
});
|
@@ -152,7 +216,7 @@ function getNpmProxyConfig() {
|
|
152
216
|
function downloadAndUnzip(params) {
|
153
217
|
var _a, _b;
|
154
218
|
return __awaiter(this, void 0, void 0, function () {
|
155
|
-
var url, destDirPath, pathOfDirToExtractInArchive, downloadHash, projectRoot, cacheRoot, zipFilePath, extractDirPath,
|
219
|
+
var url, destDirPath, pathOfDirToExtractInArchive, downloadHash, projectRoot, cacheRoot, zipFilePath, extractDirPath, opts, response;
|
156
220
|
return __generator(this, function (_c) {
|
157
221
|
switch (_c.label) {
|
158
222
|
case 0:
|
@@ -165,10 +229,10 @@ function downloadAndUnzip(params) {
|
|
165
229
|
return [4 /*yield*/, exists(zipFilePath)];
|
166
230
|
case 1:
|
167
231
|
if (!!(_c.sent())) return [3 /*break*/, 6];
|
168
|
-
return [4 /*yield*/,
|
232
|
+
return [4 /*yield*/, getFetchOptions()];
|
169
233
|
case 2:
|
170
|
-
|
171
|
-
return [4 /*yield*/, (0, make_fetch_happen_1.default)(url,
|
234
|
+
opts = _c.sent();
|
235
|
+
return [4 /*yield*/, (0, make_fetch_happen_1.default)(url, opts)];
|
172
236
|
case 3:
|
173
237
|
response = _c.sent();
|
174
238
|
return [4 /*yield*/, (0, promises_1.mkdir)((0, path_1.dirname)(zipFilePath), { "recursive": true })];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"downloadAndUnzip.js","sourceRoot":"","sources":["../../src/bin/tools/downloadAndUnzip.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"downloadAndUnzip.js","sourceRoot":"","sources":["../../src/bin/tools/downloadAndUnzip.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAqD;AACrD,iCAAoC;AACpC,wCAA+D;AAC/D,wEAA6D;AAC7D,6BAAgE;AAChE,+BAA+B;AAC/B,6BAAiC;AACjC,mDAAkD;AAClD,yDAAwD;AACxD,iCAAgC;AAEhC,IAAM,IAAI,GAAG,IAAA,gBAAS,EAAC,oBAAY,CAAC,CAAC;AAErC,SAAS,IAAI,CAAC,CAAS;IACnB,OAAO,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AAED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I,0CAAE,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;oBACjD,IAAA,cAAM,EAAC,OAAO,QAAQ,CAAC,IAAI,KAAK,WAAW,IAAI,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC;oBACtE,qBAAM,IAAA,oBAAS,EAAC,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAA;;oBAA3C,SAA2C,CAAC;;wBAGhD,qBAAM,IAAA,aAAK,EAAC,WAAW,EAAE,cAAc,EAAE,2BAA2B,CAAC,EAAA;;oBAArE,SAAqE,CAAC;oBAEtE,IAAA,qCAAiB,EAAC;wBACd,YAAY,EAAE,cAAc;wBAC5B,aAAa,EAAE,WAAW;qBAC7B,CAAC,CAAC;;;;;CACN;AA/BD,4CA+BC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { exec as execCallback } from "child_process";
|
2
2
|
import { createHash } from "crypto";
|
3
|
-
import { mkdir, stat, writeFile } from "fs/promises";
|
3
|
+
import { mkdir, readFile, stat, writeFile } from "fs/promises";
|
4
4
|
import fetch, { type FetchOptions } from "make-fetch-happen";
|
5
5
|
import { dirname as pathDirname, join as pathJoin } from "path";
|
6
6
|
import { assert } from "tsafe";
|
@@ -25,32 +25,75 @@ async function exists(path: string) {
|
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
28
|
+
function ensureArray<T>(arg0: T | T[]) {
|
29
|
+
return Array.isArray(arg0) ? arg0 : typeof arg0 === "undefined" ? [] : [arg0];
|
30
|
+
}
|
31
|
+
|
32
|
+
function ensureSingleOrNone<T>(arg0: T | T[]) {
|
33
|
+
if (!Array.isArray(arg0)) return arg0;
|
34
|
+
if (arg0.length === 0) return undefined;
|
35
|
+
if (arg0.length === 1) return arg0[0];
|
36
|
+
throw new Error("Illegal configuration, expected a single value but found multiple: " + arg0.map(String).join(", "));
|
37
|
+
}
|
38
|
+
|
39
|
+
type NPMConfig = Record<string, string | string[]>;
|
40
|
+
|
41
|
+
const npmConfigReducer = (cfg: NPMConfig, [key, value]: [string, string]) =>
|
42
|
+
key in cfg ? { ...cfg, [key]: [...ensureArray(cfg[key]), value] } : { ...cfg, [key]: value };
|
43
|
+
|
28
44
|
/**
|
29
45
|
* Get npm configuration as map
|
30
46
|
*/
|
31
|
-
async function getNmpConfig()
|
47
|
+
async function getNmpConfig() {
|
48
|
+
return readNpmConfig().then(parseNpmConfig);
|
49
|
+
}
|
50
|
+
|
51
|
+
async function readNpmConfig() {
|
32
52
|
const { stdout } = await exec("npm config get", { encoding: "utf8" });
|
53
|
+
return stdout;
|
54
|
+
}
|
55
|
+
|
56
|
+
function parseNpmConfig(stdout: string) {
|
33
57
|
return stdout
|
34
58
|
.split("\n")
|
35
59
|
.filter(line => !line.startsWith(";"))
|
36
60
|
.map(line => line.trim())
|
37
|
-
.map(line => line.split("=", 2))
|
38
|
-
.reduce(
|
61
|
+
.map(line => line.split("=", 2) as [string, string])
|
62
|
+
.reduce(npmConfigReducer, {} as NPMConfig);
|
63
|
+
}
|
64
|
+
|
65
|
+
function maybeBoolean(arg0: string | undefined) {
|
66
|
+
return typeof arg0 === "undefined" ? undefined : Boolean(arg0);
|
67
|
+
}
|
68
|
+
|
69
|
+
function chunks<T>(arr: T[], size: number = 2) {
|
70
|
+
return arr.map((_, i) => i % size == 0 && arr.slice(i, i + size)).filter(Boolean) as T[][];
|
71
|
+
}
|
72
|
+
|
73
|
+
async function readCafile(cafile: string) {
|
74
|
+
const cafileContent = await readFile(cafile, "utf-8");
|
75
|
+
return chunks(cafileContent.split(/(-----END CERTIFICATE-----)/), 2).map(ca => ca.join("").replace(/^\n/, "").replace(/\n/g, "\\n"));
|
39
76
|
}
|
40
77
|
|
41
78
|
/**
|
42
|
-
* Get proxy configuration from npm config files. Note that we don't care about
|
79
|
+
* Get proxy and ssl configuration from npm config files. Note that we don't care about
|
43
80
|
* proxy config in env vars, because make-fetch-happen will do that for us.
|
44
81
|
*
|
45
82
|
* @returns proxy configuration
|
46
83
|
*/
|
47
|
-
async function
|
84
|
+
async function getFetchOptions(): Promise<Pick<FetchOptions, "proxy" | "noProxy" | "strictSSL" | "ca" | "cert">> {
|
48
85
|
const cfg = await getNmpConfig();
|
49
86
|
|
50
|
-
const proxy = cfg["https-proxy"] ?? cfg["proxy"];
|
87
|
+
const proxy = ensureSingleOrNone(cfg["https-proxy"] ?? cfg["proxy"]);
|
51
88
|
const noProxy = cfg["noproxy"] ?? cfg["no-proxy"];
|
89
|
+
const strictSSL = maybeBoolean(ensureSingleOrNone(cfg["strict-ssl"]));
|
90
|
+
const cert = cfg["cert"];
|
91
|
+
const ca = ensureArray(cfg["ca"] ?? cfg["ca[]"]);
|
92
|
+
const cafile = ensureSingleOrNone(cfg["cafile"]);
|
93
|
+
|
94
|
+
if (typeof cafile !== "undefined" && cafile !== "null") ca.push(...(await readCafile(cafile)));
|
52
95
|
|
53
|
-
return { proxy, noProxy };
|
96
|
+
return { proxy, noProxy, strictSSL, cert, ca: ca.length === 0 ? undefined : ca };
|
54
97
|
}
|
55
98
|
|
56
99
|
export async function downloadAndUnzip(params: { url: string; destDirPath: string; pathOfDirToExtractInArchive?: string }) {
|
@@ -63,8 +106,8 @@ export async function downloadAndUnzip(params: { url: string; destDirPath: strin
|
|
63
106
|
const extractDirPath = pathJoin(cacheRoot, "keycloakify", "unzip", `_${downloadHash}`);
|
64
107
|
|
65
108
|
if (!(await exists(zipFilePath))) {
|
66
|
-
const
|
67
|
-
const response = await fetch(url,
|
109
|
+
const opts = await getFetchOptions();
|
110
|
+
const response = await fetch(url, opts);
|
68
111
|
await mkdir(pathDirname(zipFilePath), { "recursive": true });
|
69
112
|
/**
|
70
113
|
* The correct way to fix this is to upgrade node-fetch beyond 3.2.5
|