@eik/node-client 2.0.7 → 2.0.9
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 +14 -0
- package/dist/index.cjs +2 -59
- package/package.json +3 -4
- package/src/index.js +2 -59
- package/types/index.d.ts +1 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [2.0.9](https://github.com/eik-lib/node-client/compare/v2.0.8...v2.0.9) (2025-05-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency @eik/common to v5.1.1 ([#232](https://github.com/eik-lib/node-client/issues/232)) ([4550b29](https://github.com/eik-lib/node-client/commit/4550b290cb0f86ef82d6de0e1fe5653bd9aeec32))
|
|
7
|
+
|
|
8
|
+
## [2.0.8](https://github.com/eik-lib/node-client/compare/v2.0.7...v2.0.8) (2025-05-08)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update eik/common to use the shared fetch ([#231](https://github.com/eik-lib/node-client/issues/231)) ([8ff38e8](https://github.com/eik-lib/node-client/commit/8ff38e844bdc971f5a6bc2b81dd1f062cef92ece))
|
|
14
|
+
|
|
1
15
|
## [2.0.7](https://github.com/eik-lib/node-client/compare/v2.0.6...v2.0.7) (2025-05-08)
|
|
2
16
|
|
|
3
17
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var common = require('@eik/common');
|
|
4
|
-
var undici = require('undici');
|
|
5
4
|
var path = require('path');
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -60,63 +59,12 @@ const trimSlash = (value = "") => {
|
|
|
60
59
|
return value;
|
|
61
60
|
};
|
|
62
61
|
|
|
63
|
-
/**
|
|
64
|
-
* @param {string[]} urls
|
|
65
|
-
* @param {object} options
|
|
66
|
-
* @param {number} options.maxRedirections - undici option for limiting redirects
|
|
67
|
-
* @returns {Promise<ImportMap[]>}
|
|
68
|
-
*/
|
|
69
|
-
const fetchImportMaps = async (urls = [], options) => {
|
|
70
|
-
try {
|
|
71
|
-
const maps = urls.map(async (map) => {
|
|
72
|
-
const response = await undici.request(map, {
|
|
73
|
-
dispatcher: new undici.Agent().compose(
|
|
74
|
-
undici.interceptors.redirect({
|
|
75
|
-
maxRedirections: options.maxRedirections,
|
|
76
|
-
}),
|
|
77
|
-
),
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
if (response.statusCode === 404) {
|
|
81
|
-
throw new Error("Import map could not be found on server");
|
|
82
|
-
} else if (response.statusCode >= 400 && response.statusCode < 500) {
|
|
83
|
-
throw new Error("Server rejected client request");
|
|
84
|
-
} else if (response.statusCode >= 500) {
|
|
85
|
-
throw new Error("Server error");
|
|
86
|
-
}
|
|
87
|
-
let contentType = response.headers["content-type"];
|
|
88
|
-
if (!Array.isArray(contentType)) contentType = [contentType];
|
|
89
|
-
|
|
90
|
-
if (!contentType.find((type) => type.startsWith("application/json"))) {
|
|
91
|
-
const content = await response.body.text();
|
|
92
|
-
if (content.length === 0) {
|
|
93
|
-
throw new Error(
|
|
94
|
-
`${map} did not return JSON, got an empty response. HTTP status: ${response.statusCode}`,
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
throw new Error(
|
|
98
|
-
`${map} did not return JSON, got: ${content}. HTTP status: ${response.statusCode}`,
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const json = await response.body.json();
|
|
103
|
-
return /** @type {ImportMap}*/ (json);
|
|
104
|
-
});
|
|
105
|
-
return await Promise.all(maps);
|
|
106
|
-
} catch (err) {
|
|
107
|
-
throw new Error(
|
|
108
|
-
`Unable to load import map file from server: ${err.message}`,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
62
|
/**
|
|
114
63
|
* @typedef {object} Options
|
|
115
64
|
* @property {string} [base=null]
|
|
116
65
|
* @property {boolean} [development=false]
|
|
117
66
|
* @property {boolean} [loadMaps=false]
|
|
118
67
|
* @property {string} [path=process.cwd()]
|
|
119
|
-
* @property {number} [maxRedirections=2] Maximum number of redirects when looking up URLs.
|
|
120
68
|
*/
|
|
121
69
|
|
|
122
70
|
/**
|
|
@@ -190,7 +138,6 @@ class Eik {
|
|
|
190
138
|
#path;
|
|
191
139
|
#base;
|
|
192
140
|
#maps;
|
|
193
|
-
#maxRedirections;
|
|
194
141
|
|
|
195
142
|
/**
|
|
196
143
|
* @param {Options} options
|
|
@@ -200,7 +147,6 @@ class Eik {
|
|
|
200
147
|
loadMaps = false,
|
|
201
148
|
base = "",
|
|
202
149
|
path = process.cwd(),
|
|
203
|
-
maxRedirections = 2,
|
|
204
150
|
} = {}) {
|
|
205
151
|
this.#development = development;
|
|
206
152
|
this.#loadMaps = loadMaps;
|
|
@@ -208,7 +154,6 @@ class Eik {
|
|
|
208
154
|
this.#path = path;
|
|
209
155
|
this.#base = trimSlash(base);
|
|
210
156
|
this.#maps = [];
|
|
211
|
-
this.#maxRedirections = maxRedirections;
|
|
212
157
|
}
|
|
213
158
|
|
|
214
159
|
/**
|
|
@@ -219,11 +164,9 @@ class Eik {
|
|
|
219
164
|
* use in {@link maps}.
|
|
220
165
|
*/
|
|
221
166
|
async load() {
|
|
222
|
-
this.#config =
|
|
167
|
+
this.#config = common.helpers.getDefaults(this.#path);
|
|
223
168
|
if (this.#loadMaps) {
|
|
224
|
-
this.#maps = await fetchImportMaps(this.#config.map
|
|
225
|
-
maxRedirections: this.#maxRedirections,
|
|
226
|
-
});
|
|
169
|
+
this.#maps = await common.helpers.fetchImportMaps(this.#config.map);
|
|
227
170
|
}
|
|
228
171
|
}
|
|
229
172
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eik/node-client",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "Utilities for working with assets and import maps on an Eik server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -43,9 +43,8 @@
|
|
|
43
43
|
},
|
|
44
44
|
"homepage": "https://github.com/eik-lib/node-client#readme",
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@eik/common": "5.
|
|
47
|
-
"abslog": "2.4.4"
|
|
48
|
-
"undici": "7.8.0"
|
|
46
|
+
"@eik/common": "5.1.1",
|
|
47
|
+
"abslog": "2.4.4"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
50
|
"@eik/eslint-config": "1.0.13",
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { helpers } from "@eik/common";
|
|
2
|
-
import { request, interceptors, Agent } from "undici";
|
|
3
2
|
import { join } from "path";
|
|
4
3
|
import { Asset } from "./asset.js";
|
|
5
4
|
|
|
@@ -8,63 +7,12 @@ const trimSlash = (value = "") => {
|
|
|
8
7
|
return value;
|
|
9
8
|
};
|
|
10
9
|
|
|
11
|
-
/**
|
|
12
|
-
* @param {string[]} urls
|
|
13
|
-
* @param {object} options
|
|
14
|
-
* @param {number} options.maxRedirections - undici option for limiting redirects
|
|
15
|
-
* @returns {Promise<ImportMap[]>}
|
|
16
|
-
*/
|
|
17
|
-
const fetchImportMaps = async (urls = [], options) => {
|
|
18
|
-
try {
|
|
19
|
-
const maps = urls.map(async (map) => {
|
|
20
|
-
const response = await request(map, {
|
|
21
|
-
dispatcher: new Agent().compose(
|
|
22
|
-
interceptors.redirect({
|
|
23
|
-
maxRedirections: options.maxRedirections,
|
|
24
|
-
}),
|
|
25
|
-
),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (response.statusCode === 404) {
|
|
29
|
-
throw new Error("Import map could not be found on server");
|
|
30
|
-
} else if (response.statusCode >= 400 && response.statusCode < 500) {
|
|
31
|
-
throw new Error("Server rejected client request");
|
|
32
|
-
} else if (response.statusCode >= 500) {
|
|
33
|
-
throw new Error("Server error");
|
|
34
|
-
}
|
|
35
|
-
let contentType = response.headers["content-type"];
|
|
36
|
-
if (!Array.isArray(contentType)) contentType = [contentType];
|
|
37
|
-
|
|
38
|
-
if (!contentType.find((type) => type.startsWith("application/json"))) {
|
|
39
|
-
const content = await response.body.text();
|
|
40
|
-
if (content.length === 0) {
|
|
41
|
-
throw new Error(
|
|
42
|
-
`${map} did not return JSON, got an empty response. HTTP status: ${response.statusCode}`,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
throw new Error(
|
|
46
|
-
`${map} did not return JSON, got: ${content}. HTTP status: ${response.statusCode}`,
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const json = await response.body.json();
|
|
51
|
-
return /** @type {ImportMap}*/ (json);
|
|
52
|
-
});
|
|
53
|
-
return await Promise.all(maps);
|
|
54
|
-
} catch (err) {
|
|
55
|
-
throw new Error(
|
|
56
|
-
`Unable to load import map file from server: ${err.message}`,
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
10
|
/**
|
|
62
11
|
* @typedef {object} Options
|
|
63
12
|
* @property {string} [base=null]
|
|
64
13
|
* @property {boolean} [development=false]
|
|
65
14
|
* @property {boolean} [loadMaps=false]
|
|
66
15
|
* @property {string} [path=process.cwd()]
|
|
67
|
-
* @property {number} [maxRedirections=2] Maximum number of redirects when looking up URLs.
|
|
68
16
|
*/
|
|
69
17
|
|
|
70
18
|
/**
|
|
@@ -138,7 +86,6 @@ export default class Eik {
|
|
|
138
86
|
#path;
|
|
139
87
|
#base;
|
|
140
88
|
#maps;
|
|
141
|
-
#maxRedirections;
|
|
142
89
|
|
|
143
90
|
/**
|
|
144
91
|
* @param {Options} options
|
|
@@ -148,7 +95,6 @@ export default class Eik {
|
|
|
148
95
|
loadMaps = false,
|
|
149
96
|
base = "",
|
|
150
97
|
path = process.cwd(),
|
|
151
|
-
maxRedirections = 2,
|
|
152
98
|
} = {}) {
|
|
153
99
|
this.#development = development;
|
|
154
100
|
this.#loadMaps = loadMaps;
|
|
@@ -156,7 +102,6 @@ export default class Eik {
|
|
|
156
102
|
this.#path = path;
|
|
157
103
|
this.#base = trimSlash(base);
|
|
158
104
|
this.#maps = [];
|
|
159
|
-
this.#maxRedirections = maxRedirections;
|
|
160
105
|
}
|
|
161
106
|
|
|
162
107
|
/**
|
|
@@ -167,11 +112,9 @@ export default class Eik {
|
|
|
167
112
|
* use in {@link maps}.
|
|
168
113
|
*/
|
|
169
114
|
async load() {
|
|
170
|
-
this.#config =
|
|
115
|
+
this.#config = helpers.getDefaults(this.#path);
|
|
171
116
|
if (this.#loadMaps) {
|
|
172
|
-
this.#maps = await fetchImportMaps(this.#config.map
|
|
173
|
-
maxRedirections: this.#maxRedirections,
|
|
174
|
-
});
|
|
117
|
+
this.#maps = await helpers.fetchImportMaps(this.#config.map);
|
|
175
118
|
}
|
|
176
119
|
}
|
|
177
120
|
|
package/types/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* @property {boolean} [development=false]
|
|
5
5
|
* @property {boolean} [loadMaps=false]
|
|
6
6
|
* @property {string} [path=process.cwd()]
|
|
7
|
-
* @property {number} [maxRedirections=2] Maximum number of redirects when looking up URLs.
|
|
8
7
|
*/
|
|
9
8
|
/**
|
|
10
9
|
* @typedef {object} ImportMap
|
|
@@ -73,7 +72,7 @@ export default class Eik {
|
|
|
73
72
|
/**
|
|
74
73
|
* @param {Options} options
|
|
75
74
|
*/
|
|
76
|
-
constructor({ development, loadMaps, base, path,
|
|
75
|
+
constructor({ development, loadMaps, base, path, }?: Options);
|
|
77
76
|
/**
|
|
78
77
|
* Reads the Eik config from disk into the object instance, used for building {@link file} links in production.
|
|
79
78
|
*
|
|
@@ -213,10 +212,6 @@ export type Options = {
|
|
|
213
212
|
development?: boolean;
|
|
214
213
|
loadMaps?: boolean;
|
|
215
214
|
path?: string;
|
|
216
|
-
/**
|
|
217
|
-
* Maximum number of redirects when looking up URLs.
|
|
218
|
-
*/
|
|
219
|
-
maxRedirections?: number;
|
|
220
215
|
};
|
|
221
216
|
export type ImportMap = {
|
|
222
217
|
imports: Record<string, string>;
|