@jam-comments/server-utilities 3.2.1 → 4.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/dist/cjs/index.js +4 -2
- package/dist/cjs/markupFetcher.js +1 -1
- package/dist/cjs/markupFetcher.test.js +7 -7
- package/dist/cjs/utils.js +9 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/markupFetcher.js +1 -1
- package/dist/esm/markupFetcher.test.js +7 -7
- package/dist/esm/utils.js +7 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/utils.d.ts +1 -0
- package/package.json +6 -6
package/dist/cjs/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
3
|
+
exports.logError = exports.log = exports.reAppendMarkup = exports.markupFetcher = void 0;
|
|
4
|
+
var markupFetcher_1 = require("./markupFetcher");
|
|
5
5
|
Object.defineProperty(exports, "markupFetcher", { enumerable: true, get: function () { return markupFetcher_1.markupFetcher; } });
|
|
6
|
+
var utils_1 = require("./utils");
|
|
7
|
+
Object.defineProperty(exports, "reAppendMarkup", { enumerable: true, get: function () { return utils_1.reAppendMarkup; } });
|
|
6
8
|
var log_1 = require("./log");
|
|
7
9
|
Object.defineProperty(exports, "log", { enumerable: true, get: function () { return log_1.log; } });
|
|
8
10
|
Object.defineProperty(exports, "logError", { enumerable: true, get: function () { return log_1.logError; } });
|
|
@@ -18,7 +18,7 @@ const markupFetcher = (platform, fetchImplementation = fetch) => {
|
|
|
18
18
|
if (environment !== "production") {
|
|
19
19
|
params.set("stub", "true");
|
|
20
20
|
}
|
|
21
|
-
const requestUrl = `${baseUrl}/api/
|
|
21
|
+
const requestUrl = `${baseUrl}/api/v3/markup?${params}`;
|
|
22
22
|
const response = await fetchImplementation(requestUrl, {
|
|
23
23
|
method: "GET",
|
|
24
24
|
headers: {
|
|
@@ -18,7 +18,7 @@ const markupFetcher_1 = require("./markupFetcher");
|
|
|
18
18
|
apiKey: "123abc",
|
|
19
19
|
environment: "production",
|
|
20
20
|
});
|
|
21
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
21
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v3/markup?path=%2Ftest&domain=test.com", vitest_1.expect.objectContaining({
|
|
22
22
|
headers: vitest_1.expect.objectContaining({
|
|
23
23
|
Accept: "application/json",
|
|
24
24
|
Authorization: "Bearer 123abc",
|
|
@@ -43,7 +43,7 @@ const markupFetcher_1 = require("./markupFetcher");
|
|
|
43
43
|
apiKey: "123abc",
|
|
44
44
|
environment: "development",
|
|
45
45
|
});
|
|
46
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
46
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v3/markup?path=%2Ftest&domain=test.com&stub=true", vitest_1.expect.anything());
|
|
47
47
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
48
48
|
});
|
|
49
49
|
(0, vitest_1.it)("uses different base URL", async () => {
|
|
@@ -62,7 +62,7 @@ const markupFetcher_1 = require("./markupFetcher");
|
|
|
62
62
|
baseUrl: "http://ur-mom.com",
|
|
63
63
|
environment: "production",
|
|
64
64
|
});
|
|
65
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
65
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v3/markup?path=%2Ftest&domain=test.com", vitest_1.expect.anything());
|
|
66
66
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
67
67
|
});
|
|
68
68
|
(0, vitest_1.it)("respects production!!!", async () => {
|
|
@@ -81,7 +81,7 @@ const markupFetcher_1 = require("./markupFetcher");
|
|
|
81
81
|
baseUrl: "http://ur-mom.com",
|
|
82
82
|
environment: "production",
|
|
83
83
|
});
|
|
84
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
84
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v3/markup?path=%2Ftest&domain=test.com", vitest_1.expect.anything());
|
|
85
85
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
86
86
|
});
|
|
87
87
|
(0, vitest_1.it)("falls back to root path", async () => {
|
|
@@ -99,7 +99,7 @@ const markupFetcher_1 = require("./markupFetcher");
|
|
|
99
99
|
apiKey: "123abc",
|
|
100
100
|
environment: "production",
|
|
101
101
|
});
|
|
102
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
102
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v3/markup?path=%2F&domain=test.com", vitest_1.expect.anything());
|
|
103
103
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
104
104
|
});
|
|
105
105
|
(0, vitest_1.it)("credentials are invalid", async () => {
|
|
@@ -161,7 +161,7 @@ const markupFetcher_1 = require("./markupFetcher");
|
|
|
161
161
|
tz: "America/New_York",
|
|
162
162
|
environment: "production",
|
|
163
163
|
});
|
|
164
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
164
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v3/markup?path=%2F&domain=test.com&tz=America%2FNew_York", vitest_1.expect.anything());
|
|
165
165
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
166
166
|
});
|
|
167
167
|
(0, vitest_1.it)("trims a valid timezone", async () => {
|
|
@@ -180,7 +180,7 @@ const markupFetcher_1 = require("./markupFetcher");
|
|
|
180
180
|
tz: " America/Chicago ",
|
|
181
181
|
environment: "production",
|
|
182
182
|
});
|
|
183
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
183
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v3/markup?path=%2F&domain=test.com&tz=America%2FChicago", vitest_1.expect.anything());
|
|
184
184
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
185
185
|
});
|
|
186
186
|
});
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEnvironment = exports.isValidTimezone = void 0;
|
|
3
|
+
exports.reAppendMarkup = exports.getEnvironment = exports.isValidTimezone = void 0;
|
|
4
4
|
function isValidTimezone(tz) {
|
|
5
5
|
try {
|
|
6
6
|
Intl.DateTimeFormat(undefined, { timeZone: tz });
|
|
@@ -18,3 +18,11 @@ function getEnvironment() {
|
|
|
18
18
|
return process.env?.NODE_ENV || "development";
|
|
19
19
|
}
|
|
20
20
|
exports.getEnvironment = getEnvironment;
|
|
21
|
+
function reAppendMarkup(element, markup) {
|
|
22
|
+
const range = document.createRange();
|
|
23
|
+
range.selectNode(element);
|
|
24
|
+
const documentFragment = range.createContextualFragment(markup);
|
|
25
|
+
element.innerHTML = "";
|
|
26
|
+
element.append(documentFragment);
|
|
27
|
+
}
|
|
28
|
+
exports.reAppendMarkup = reAppendMarkup;
|
package/dist/esm/index.js
CHANGED
|
@@ -15,7 +15,7 @@ export const markupFetcher = (platform, fetchImplementation = fetch) => {
|
|
|
15
15
|
if (environment !== "production") {
|
|
16
16
|
params.set("stub", "true");
|
|
17
17
|
}
|
|
18
|
-
const requestUrl = `${baseUrl}/api/
|
|
18
|
+
const requestUrl = `${baseUrl}/api/v3/markup?${params}`;
|
|
19
19
|
const response = await fetchImplementation(requestUrl, {
|
|
20
20
|
method: "GET",
|
|
21
21
|
headers: {
|
|
@@ -16,7 +16,7 @@ describe("markupFetcher", () => {
|
|
|
16
16
|
apiKey: "123abc",
|
|
17
17
|
environment: "production",
|
|
18
18
|
});
|
|
19
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
19
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v3/markup?path=%2Ftest&domain=test.com", expect.objectContaining({
|
|
20
20
|
headers: expect.objectContaining({
|
|
21
21
|
Accept: "application/json",
|
|
22
22
|
Authorization: "Bearer 123abc",
|
|
@@ -41,7 +41,7 @@ describe("markupFetcher", () => {
|
|
|
41
41
|
apiKey: "123abc",
|
|
42
42
|
environment: "development",
|
|
43
43
|
});
|
|
44
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
44
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v3/markup?path=%2Ftest&domain=test.com&stub=true", expect.anything());
|
|
45
45
|
expect(result).toEqual("results!");
|
|
46
46
|
});
|
|
47
47
|
it("uses different base URL", async () => {
|
|
@@ -60,7 +60,7 @@ describe("markupFetcher", () => {
|
|
|
60
60
|
baseUrl: "http://ur-mom.com",
|
|
61
61
|
environment: "production",
|
|
62
62
|
});
|
|
63
|
-
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
63
|
+
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v3/markup?path=%2Ftest&domain=test.com", expect.anything());
|
|
64
64
|
expect(result).toEqual("results!");
|
|
65
65
|
});
|
|
66
66
|
it("respects production!!!", async () => {
|
|
@@ -79,7 +79,7 @@ describe("markupFetcher", () => {
|
|
|
79
79
|
baseUrl: "http://ur-mom.com",
|
|
80
80
|
environment: "production",
|
|
81
81
|
});
|
|
82
|
-
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
82
|
+
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v3/markup?path=%2Ftest&domain=test.com", expect.anything());
|
|
83
83
|
expect(result).toEqual("results!");
|
|
84
84
|
});
|
|
85
85
|
it("falls back to root path", async () => {
|
|
@@ -97,7 +97,7 @@ describe("markupFetcher", () => {
|
|
|
97
97
|
apiKey: "123abc",
|
|
98
98
|
environment: "production",
|
|
99
99
|
});
|
|
100
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
100
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v3/markup?path=%2F&domain=test.com", expect.anything());
|
|
101
101
|
expect(result).toEqual("results!");
|
|
102
102
|
});
|
|
103
103
|
it("credentials are invalid", async () => {
|
|
@@ -159,7 +159,7 @@ describe("markupFetcher", () => {
|
|
|
159
159
|
tz: "America/New_York",
|
|
160
160
|
environment: "production",
|
|
161
161
|
});
|
|
162
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
162
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v3/markup?path=%2F&domain=test.com&tz=America%2FNew_York", expect.anything());
|
|
163
163
|
expect(result).toEqual("results!");
|
|
164
164
|
});
|
|
165
165
|
it("trims a valid timezone", async () => {
|
|
@@ -178,7 +178,7 @@ describe("markupFetcher", () => {
|
|
|
178
178
|
tz: " America/Chicago ",
|
|
179
179
|
environment: "production",
|
|
180
180
|
});
|
|
181
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
181
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v3/markup?path=%2F&domain=test.com&tz=America%2FChicago", expect.anything());
|
|
182
182
|
expect(result).toEqual("results!");
|
|
183
183
|
});
|
|
184
184
|
});
|
package/dist/esm/utils.js
CHANGED
|
@@ -13,3 +13,10 @@ export function getEnvironment() {
|
|
|
13
13
|
}
|
|
14
14
|
return process.env?.NODE_ENV || "development";
|
|
15
15
|
}
|
|
16
|
+
export function reAppendMarkup(element, markup) {
|
|
17
|
+
const range = document.createRange();
|
|
18
|
+
range.selectNode(element);
|
|
19
|
+
const documentFragment = range.createContextualFragment(markup);
|
|
20
|
+
element.innerHTML = "";
|
|
21
|
+
element.append(documentFragment);
|
|
22
|
+
}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/utils.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jam-comments/server-utilities",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Various JavaScript utilities for JamComments.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"homepage": "https://jamcomments.com",
|
|
22
22
|
"license": "GPL-2.0",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@types/node": "^20.
|
|
25
|
-
"prettier": "^
|
|
26
|
-
"typescript": "^5.
|
|
27
|
-
"vite": "^4.
|
|
28
|
-
"vitest": "^0.
|
|
24
|
+
"@types/node": "^20.9.0",
|
|
25
|
+
"prettier": "^3.0.3",
|
|
26
|
+
"typescript": "^5.2.2",
|
|
27
|
+
"vite": "^4.5.0",
|
|
28
|
+
"vitest": "^0.34.6"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|