@jam-comments/server-utilities 5.16.0 → 5.16.1-beta.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/markupFetcher.js +3 -2
- package/dist/cjs/markupFetcher.test.js +18 -18
- package/dist/cjs/simpleMarkupFetcher.test.js +10 -10
- package/dist/esm/markupFetcher.js +3 -2
- package/dist/esm/markupFetcher.test.js +18 -18
- package/dist/esm/simpleMarkupFetcher.test.js +10 -10
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ exports.markupFetcher = markupFetcher;
|
|
|
9
9
|
const injectSchema_1 = require("./injectSchema");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
const store_1 = require("./store");
|
|
12
|
+
const MARKUP_VERSION = "v4";
|
|
12
13
|
exports.BASE_URL = "https://go.jamcomments.com";
|
|
13
14
|
async function fetchAll({ tz = undefined, dateFormat = undefined, domain, apiKey, baseUrl = exports.BASE_URL, environment = (0, utils_1.getEnvironment)(), copy = {}, }, platform, fetchImplementation = fetch, batchMarkupFetcherImpl = batchMarkupFetcher, store = new store_1.Store()) {
|
|
14
15
|
const fetchBatchMarkup = batchMarkupFetcherImpl(platform, fetchImplementation);
|
|
@@ -47,12 +48,12 @@ async function fetchAll({ tz = undefined, dateFormat = undefined, domain, apiKey
|
|
|
47
48
|
}
|
|
48
49
|
function batchMarkupFetcher(platform, fetchImplementation = fetch) {
|
|
49
50
|
return async ({ tz, copy, domain, apiKey, dateFormat, baseUrl = exports.BASE_URL, environment = (0, utils_1.getEnvironment)(), page = 1, }) => {
|
|
50
|
-
const response = await makeMarkupRequest({ tz, domain, apiKey, baseUrl, environment, page, copy, dateFormat },
|
|
51
|
+
const response = await makeMarkupRequest({ tz, domain, apiKey, baseUrl, environment, page, copy, dateFormat }, `/api/${MARKUP_VERSION}/markup/all`, fetchImplementation, platform);
|
|
51
52
|
return response.json();
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
async function fetchFreshMarkup({ tz, path, copy, cache, domain, apiKey, dateFormat, baseUrl = exports.BASE_URL, environment = (0, utils_1.getEnvironment)(), }, fetchImplementation = fetch, platform) {
|
|
55
|
-
const response = await makeMarkupRequest({ tz, path, domain, apiKey, baseUrl, environment, copy, dateFormat, cache },
|
|
56
|
+
const response = await makeMarkupRequest({ tz, path, domain, apiKey, baseUrl, environment, copy, dateFormat, cache }, `/api/${MARKUP_VERSION}/markup`, fetchImplementation, platform);
|
|
56
57
|
return response.text();
|
|
57
58
|
}
|
|
58
59
|
async function makeMarkupRequest({ tz, path, page, cache, domain, apiKey, dateFormat, copy = {}, baseUrl = exports.BASE_URL, environment = (0, utils_1.getEnvironment)(), }, baseServicePath, fetchImplementation = fetch, platform) {
|
|
@@ -277,7 +277,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
277
277
|
environment: "production",
|
|
278
278
|
});
|
|
279
279
|
(0, vitest_1.expect)(injectSchemaSpy).not.toHaveBeenCalled();
|
|
280
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
280
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup/all?domain=test.com&page=1", vitest_1.expect.objectContaining({
|
|
281
281
|
headers: vitest_1.expect.objectContaining({
|
|
282
282
|
Accept: "application/json",
|
|
283
283
|
Authorization: "Bearer 123abc",
|
|
@@ -301,7 +301,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
301
301
|
apiKey: "123abc",
|
|
302
302
|
environment: "development",
|
|
303
303
|
});
|
|
304
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
304
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup/all?domain=test.com&page=1&stub=true", vitest_1.expect.anything());
|
|
305
305
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
306
306
|
});
|
|
307
307
|
(0, vitest_1.it)("uses different base URL", async () => {
|
|
@@ -319,7 +319,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
319
319
|
baseUrl: "http://ur-mom.com",
|
|
320
320
|
environment: "production",
|
|
321
321
|
});
|
|
322
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
322
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v4/markup/all?domain=test.com&page=1", vitest_1.expect.anything());
|
|
323
323
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
324
324
|
});
|
|
325
325
|
});
|
|
@@ -341,7 +341,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
341
341
|
environment: "production",
|
|
342
342
|
});
|
|
343
343
|
(0, vitest_1.expect)(injectSchemaSpy).not.toHaveBeenCalled();
|
|
344
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
344
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest", vitest_1.expect.objectContaining({
|
|
345
345
|
headers: vitest_1.expect.objectContaining({
|
|
346
346
|
Accept: "application/json",
|
|
347
347
|
Authorization: "Bearer 123abc",
|
|
@@ -366,7 +366,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
366
366
|
apiKey: "123abc",
|
|
367
367
|
environment: "development",
|
|
368
368
|
});
|
|
369
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
369
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest&stub=true", vitest_1.expect.anything());
|
|
370
370
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
371
371
|
});
|
|
372
372
|
(0, vitest_1.it)("sets cache control header on response", async () => {
|
|
@@ -385,7 +385,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
385
385
|
environment: "development",
|
|
386
386
|
cache: true,
|
|
387
387
|
});
|
|
388
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
388
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&cache=true&path=%2Ftest&stub=true", vitest_1.expect.anything());
|
|
389
389
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
390
390
|
});
|
|
391
391
|
(0, vitest_1.it)("uses different base URL", async () => {
|
|
@@ -404,7 +404,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
404
404
|
baseUrl: "http://ur-mom.com",
|
|
405
405
|
environment: "production",
|
|
406
406
|
});
|
|
407
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
407
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v4/markup?domain=test.com&path=%2Ftest", vitest_1.expect.anything());
|
|
408
408
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
409
409
|
});
|
|
410
410
|
(0, vitest_1.it)("respects production!!!", async () => {
|
|
@@ -423,7 +423,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
423
423
|
baseUrl: "http://ur-mom.com",
|
|
424
424
|
environment: "production",
|
|
425
425
|
});
|
|
426
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
426
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v4/markup?domain=test.com&path=%2Ftest", vitest_1.expect.anything());
|
|
427
427
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
428
428
|
});
|
|
429
429
|
(0, vitest_1.it)("falls back to root path", async () => {
|
|
@@ -441,7 +441,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
441
441
|
apiKey: "123abc",
|
|
442
442
|
environment: "production",
|
|
443
443
|
});
|
|
444
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
444
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2F", vitest_1.expect.anything());
|
|
445
445
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
446
446
|
});
|
|
447
447
|
(0, vitest_1.it)("credentials are invalid", async () => {
|
|
@@ -493,7 +493,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
493
493
|
copy_submit_button: "custom submit button",
|
|
494
494
|
},
|
|
495
495
|
});
|
|
496
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
496
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2F©_confirmation_message=custom+confirmation+message©_submit_button=custom+submit+button", vitest_1.expect.anything());
|
|
497
497
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
498
498
|
});
|
|
499
499
|
(0, vitest_1.it)("passes date format string", async () => {
|
|
@@ -512,7 +512,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
512
512
|
environment: "production",
|
|
513
513
|
dateFormat: "yyyy-MM-dd",
|
|
514
514
|
});
|
|
515
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
515
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2F&date_format=yyyy-MM-dd", vitest_1.expect.anything());
|
|
516
516
|
});
|
|
517
517
|
(0, vitest_1.it)("response isn't ok", async () => {
|
|
518
518
|
const fetchMock = vitest_1.vi.fn().mockImplementation(() => {
|
|
@@ -550,7 +550,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
550
550
|
environment: "production",
|
|
551
551
|
});
|
|
552
552
|
(0, vitest_1.expect)(store.get).not.toHaveBeenCalled();
|
|
553
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
553
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest", vitest_1.expect.anything());
|
|
554
554
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
555
555
|
});
|
|
556
556
|
(0, vitest_1.it)("uses saved markup when it exists", async () => {
|
|
@@ -609,7 +609,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
609
609
|
copy_submit_button: "custom submit button",
|
|
610
610
|
},
|
|
611
611
|
});
|
|
612
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
612
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Fsome%2Fpath©_confirmation_message=custom+confirmation+message©_submit_button=custom+submit+button", vitest_1.expect.anything());
|
|
613
613
|
});
|
|
614
614
|
});
|
|
615
615
|
(0, vitest_1.describe)("timezone validation", () => {
|
|
@@ -641,7 +641,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
641
641
|
tz: "America/New_York",
|
|
642
642
|
environment: "production",
|
|
643
643
|
});
|
|
644
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
644
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Fsome%2Fpath&tz=America%2FNew_York", vitest_1.expect.anything());
|
|
645
645
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
646
646
|
});
|
|
647
647
|
(0, vitest_1.it)("trims a valid timezone", async () => {
|
|
@@ -660,7 +660,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
660
660
|
tz: " America/Chicago ",
|
|
661
661
|
environment: "production",
|
|
662
662
|
});
|
|
663
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
663
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Fsome%2Fpath&tz=America%2FChicago", vitest_1.expect.anything());
|
|
664
664
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
665
665
|
});
|
|
666
666
|
});
|
|
@@ -684,7 +684,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
684
684
|
environment: "production",
|
|
685
685
|
});
|
|
686
686
|
(0, vitest_1.expect)(injectSchemaSpy).toHaveBeenCalledWith("results!", { foo: "bar" });
|
|
687
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
687
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest", vitest_1.expect.anything());
|
|
688
688
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
689
689
|
});
|
|
690
690
|
(0, vitest_1.it)("does not stringify schema if given a string", async () => {
|
|
@@ -705,7 +705,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
705
705
|
environment: "production",
|
|
706
706
|
});
|
|
707
707
|
(0, vitest_1.expect)(injectSchemaSpy).toHaveBeenCalledWith("results!", { foo: "bar" });
|
|
708
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
708
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest", vitest_1.expect.anything());
|
|
709
709
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
710
710
|
});
|
|
711
711
|
(0, vitest_1.it)("returns markup if invalid json is provided", async () => {
|
|
@@ -726,7 +726,7 @@ const { markupFetcher, batchMarkupFetcher } = fetcherExports;
|
|
|
726
726
|
environment: "production",
|
|
727
727
|
});
|
|
728
728
|
(0, vitest_1.expect)(injectSchemaSpy).not.toHaveBeenCalled();
|
|
729
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
729
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest", vitest_1.expect.anything());
|
|
730
730
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
731
731
|
});
|
|
732
732
|
});
|
|
@@ -54,7 +54,7 @@ const simpleMarkupFetcher_1 = require("./simpleMarkupFetcher");
|
|
|
54
54
|
environment: "production",
|
|
55
55
|
});
|
|
56
56
|
(0, vitest_1.expect)(injectSchemaSpy).not.toHaveBeenCalled();
|
|
57
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
57
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest", vitest_1.expect.objectContaining({
|
|
58
58
|
headers: vitest_1.expect.objectContaining({
|
|
59
59
|
Accept: "application/json",
|
|
60
60
|
Authorization: "Bearer 123abc",
|
|
@@ -79,7 +79,7 @@ const simpleMarkupFetcher_1 = require("./simpleMarkupFetcher");
|
|
|
79
79
|
apiKey: "123abc",
|
|
80
80
|
environment: "development",
|
|
81
81
|
});
|
|
82
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
82
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest&stub=true", vitest_1.expect.anything());
|
|
83
83
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
84
84
|
});
|
|
85
85
|
(0, vitest_1.it)("uses different base URL", async () => {
|
|
@@ -98,7 +98,7 @@ const simpleMarkupFetcher_1 = require("./simpleMarkupFetcher");
|
|
|
98
98
|
baseUrl: "http://ur-mom.com",
|
|
99
99
|
environment: "production",
|
|
100
100
|
});
|
|
101
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
101
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v4/markup?domain=test.com&path=%2Ftest", vitest_1.expect.anything());
|
|
102
102
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
103
103
|
});
|
|
104
104
|
(0, vitest_1.it)("respects production!!!", async () => {
|
|
@@ -117,7 +117,7 @@ const simpleMarkupFetcher_1 = require("./simpleMarkupFetcher");
|
|
|
117
117
|
baseUrl: "http://ur-mom.com",
|
|
118
118
|
environment: "production",
|
|
119
119
|
});
|
|
120
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
120
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v4/markup?domain=test.com&path=%2Ftest", vitest_1.expect.anything());
|
|
121
121
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
122
122
|
});
|
|
123
123
|
(0, vitest_1.it)("falls back to root path", async () => {
|
|
@@ -135,7 +135,7 @@ const simpleMarkupFetcher_1 = require("./simpleMarkupFetcher");
|
|
|
135
135
|
apiKey: "123abc",
|
|
136
136
|
environment: "production",
|
|
137
137
|
});
|
|
138
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
138
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2F", vitest_1.expect.anything());
|
|
139
139
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
140
140
|
});
|
|
141
141
|
(0, vitest_1.it)("credentials are invalid", async () => {
|
|
@@ -187,7 +187,7 @@ const simpleMarkupFetcher_1 = require("./simpleMarkupFetcher");
|
|
|
187
187
|
copy_submit_button: "custom submit button",
|
|
188
188
|
},
|
|
189
189
|
});
|
|
190
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
190
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2F©_confirmation_message=custom+confirmation+message©_submit_button=custom+submit+button", vitest_1.expect.anything());
|
|
191
191
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
192
192
|
});
|
|
193
193
|
(0, vitest_1.it)("passes date format string", async () => {
|
|
@@ -206,7 +206,7 @@ const simpleMarkupFetcher_1 = require("./simpleMarkupFetcher");
|
|
|
206
206
|
environment: "production",
|
|
207
207
|
dateFormat: "yyyy-MM-dd",
|
|
208
208
|
});
|
|
209
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
209
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2F&date_format=yyyy-MM-dd", vitest_1.expect.anything());
|
|
210
210
|
});
|
|
211
211
|
(0, vitest_1.it)("response isn't ok", async () => {
|
|
212
212
|
const fetchMock = vitest_1.vi.fn().mockImplementation(() => {
|
|
@@ -243,7 +243,7 @@ const simpleMarkupFetcher_1 = require("./simpleMarkupFetcher");
|
|
|
243
243
|
copy_submit_button: "custom submit button",
|
|
244
244
|
},
|
|
245
245
|
});
|
|
246
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
246
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Fsome%2Fpath©_confirmation_message=custom+confirmation+message©_submit_button=custom+submit+button", vitest_1.expect.anything());
|
|
247
247
|
});
|
|
248
248
|
});
|
|
249
249
|
(0, vitest_1.describe)("timezone validation", () => {
|
|
@@ -275,7 +275,7 @@ const simpleMarkupFetcher_1 = require("./simpleMarkupFetcher");
|
|
|
275
275
|
tz: "America/New_York",
|
|
276
276
|
environment: "production",
|
|
277
277
|
});
|
|
278
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
278
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Fsome%2Fpath&tz=America%2FNew_York", vitest_1.expect.anything());
|
|
279
279
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
280
280
|
});
|
|
281
281
|
(0, vitest_1.it)("trims a valid timezone", async () => {
|
|
@@ -294,7 +294,7 @@ const simpleMarkupFetcher_1 = require("./simpleMarkupFetcher");
|
|
|
294
294
|
tz: " America/Chicago ",
|
|
295
295
|
environment: "production",
|
|
296
296
|
});
|
|
297
|
-
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
297
|
+
(0, vitest_1.expect)(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Fsome%2Fpath&tz=America%2FChicago", vitest_1.expect.anything());
|
|
298
298
|
(0, vitest_1.expect)(result).toEqual("results!");
|
|
299
299
|
});
|
|
300
300
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { injectSchema } from "./injectSchema";
|
|
2
2
|
import { getEnvironment, isValidTimezone, parseJson } from "./utils";
|
|
3
3
|
import { Store } from "./store";
|
|
4
|
+
const MARKUP_VERSION = "v4";
|
|
4
5
|
export const BASE_URL = "https://go.jamcomments.com";
|
|
5
6
|
export async function fetchAll({ tz = undefined, dateFormat = undefined, domain, apiKey, baseUrl = BASE_URL, environment = getEnvironment(), copy = {}, }, platform, fetchImplementation = fetch, batchMarkupFetcherImpl = batchMarkupFetcher, store = new Store()) {
|
|
6
7
|
const fetchBatchMarkup = batchMarkupFetcherImpl(platform, fetchImplementation);
|
|
@@ -39,12 +40,12 @@ export async function fetchAll({ tz = undefined, dateFormat = undefined, domain,
|
|
|
39
40
|
}
|
|
40
41
|
export function batchMarkupFetcher(platform, fetchImplementation = fetch) {
|
|
41
42
|
return async ({ tz, copy, domain, apiKey, dateFormat, baseUrl = BASE_URL, environment = getEnvironment(), page = 1, }) => {
|
|
42
|
-
const response = await makeMarkupRequest({ tz, domain, apiKey, baseUrl, environment, page, copy, dateFormat },
|
|
43
|
+
const response = await makeMarkupRequest({ tz, domain, apiKey, baseUrl, environment, page, copy, dateFormat }, `/api/${MARKUP_VERSION}/markup/all`, fetchImplementation, platform);
|
|
43
44
|
return response.json();
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
47
|
export async function fetchFreshMarkup({ tz, path, copy, cache, domain, apiKey, dateFormat, baseUrl = BASE_URL, environment = getEnvironment(), }, fetchImplementation = fetch, platform) {
|
|
47
|
-
const response = await makeMarkupRequest({ tz, path, domain, apiKey, baseUrl, environment, copy, dateFormat, cache },
|
|
48
|
+
const response = await makeMarkupRequest({ tz, path, domain, apiKey, baseUrl, environment, copy, dateFormat, cache }, `/api/${MARKUP_VERSION}/markup`, fetchImplementation, platform);
|
|
48
49
|
return response.text();
|
|
49
50
|
}
|
|
50
51
|
export async function makeMarkupRequest({ tz, path, page, cache, domain, apiKey, dateFormat, copy = {}, baseUrl = BASE_URL, environment = getEnvironment(), }, baseServicePath, fetchImplementation = fetch, platform) {
|
|
@@ -242,7 +242,7 @@ describe("batchMarkupFetcher", () => {
|
|
|
242
242
|
environment: "production",
|
|
243
243
|
});
|
|
244
244
|
expect(injectSchemaSpy).not.toHaveBeenCalled();
|
|
245
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
245
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup/all?domain=test.com&page=1", expect.objectContaining({
|
|
246
246
|
headers: expect.objectContaining({
|
|
247
247
|
Accept: "application/json",
|
|
248
248
|
Authorization: "Bearer 123abc",
|
|
@@ -266,7 +266,7 @@ describe("batchMarkupFetcher", () => {
|
|
|
266
266
|
apiKey: "123abc",
|
|
267
267
|
environment: "development",
|
|
268
268
|
});
|
|
269
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
269
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup/all?domain=test.com&page=1&stub=true", expect.anything());
|
|
270
270
|
expect(result).toEqual("results!");
|
|
271
271
|
});
|
|
272
272
|
it("uses different base URL", async () => {
|
|
@@ -284,7 +284,7 @@ describe("batchMarkupFetcher", () => {
|
|
|
284
284
|
baseUrl: "http://ur-mom.com",
|
|
285
285
|
environment: "production",
|
|
286
286
|
});
|
|
287
|
-
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
287
|
+
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v4/markup/all?domain=test.com&page=1", expect.anything());
|
|
288
288
|
expect(result).toEqual("results!");
|
|
289
289
|
});
|
|
290
290
|
});
|
|
@@ -306,7 +306,7 @@ describe("markupFetcher", () => {
|
|
|
306
306
|
environment: "production",
|
|
307
307
|
});
|
|
308
308
|
expect(injectSchemaSpy).not.toHaveBeenCalled();
|
|
309
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
309
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest", expect.objectContaining({
|
|
310
310
|
headers: expect.objectContaining({
|
|
311
311
|
Accept: "application/json",
|
|
312
312
|
Authorization: "Bearer 123abc",
|
|
@@ -331,7 +331,7 @@ describe("markupFetcher", () => {
|
|
|
331
331
|
apiKey: "123abc",
|
|
332
332
|
environment: "development",
|
|
333
333
|
});
|
|
334
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
334
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest&stub=true", expect.anything());
|
|
335
335
|
expect(result).toEqual("results!");
|
|
336
336
|
});
|
|
337
337
|
it("sets cache control header on response", async () => {
|
|
@@ -350,7 +350,7 @@ describe("markupFetcher", () => {
|
|
|
350
350
|
environment: "development",
|
|
351
351
|
cache: true,
|
|
352
352
|
});
|
|
353
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
353
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&cache=true&path=%2Ftest&stub=true", expect.anything());
|
|
354
354
|
expect(result).toEqual("results!");
|
|
355
355
|
});
|
|
356
356
|
it("uses different base URL", async () => {
|
|
@@ -369,7 +369,7 @@ describe("markupFetcher", () => {
|
|
|
369
369
|
baseUrl: "http://ur-mom.com",
|
|
370
370
|
environment: "production",
|
|
371
371
|
});
|
|
372
|
-
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
372
|
+
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v4/markup?domain=test.com&path=%2Ftest", expect.anything());
|
|
373
373
|
expect(result).toEqual("results!");
|
|
374
374
|
});
|
|
375
375
|
it("respects production!!!", async () => {
|
|
@@ -388,7 +388,7 @@ describe("markupFetcher", () => {
|
|
|
388
388
|
baseUrl: "http://ur-mom.com",
|
|
389
389
|
environment: "production",
|
|
390
390
|
});
|
|
391
|
-
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
391
|
+
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v4/markup?domain=test.com&path=%2Ftest", expect.anything());
|
|
392
392
|
expect(result).toEqual("results!");
|
|
393
393
|
});
|
|
394
394
|
it("falls back to root path", async () => {
|
|
@@ -406,7 +406,7 @@ describe("markupFetcher", () => {
|
|
|
406
406
|
apiKey: "123abc",
|
|
407
407
|
environment: "production",
|
|
408
408
|
});
|
|
409
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
409
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2F", expect.anything());
|
|
410
410
|
expect(result).toEqual("results!");
|
|
411
411
|
});
|
|
412
412
|
it("credentials are invalid", async () => {
|
|
@@ -458,7 +458,7 @@ describe("markupFetcher", () => {
|
|
|
458
458
|
copy_submit_button: "custom submit button",
|
|
459
459
|
},
|
|
460
460
|
});
|
|
461
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
461
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2F©_confirmation_message=custom+confirmation+message©_submit_button=custom+submit+button", expect.anything());
|
|
462
462
|
expect(result).toEqual("results!");
|
|
463
463
|
});
|
|
464
464
|
it("passes date format string", async () => {
|
|
@@ -477,7 +477,7 @@ describe("markupFetcher", () => {
|
|
|
477
477
|
environment: "production",
|
|
478
478
|
dateFormat: "yyyy-MM-dd",
|
|
479
479
|
});
|
|
480
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
480
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2F&date_format=yyyy-MM-dd", expect.anything());
|
|
481
481
|
});
|
|
482
482
|
it("response isn't ok", async () => {
|
|
483
483
|
const fetchMock = vi.fn().mockImplementation(() => {
|
|
@@ -515,7 +515,7 @@ describe("markupFetcher", () => {
|
|
|
515
515
|
environment: "production",
|
|
516
516
|
});
|
|
517
517
|
expect(store.get).not.toHaveBeenCalled();
|
|
518
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
518
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest", expect.anything());
|
|
519
519
|
expect(result).toEqual("results!");
|
|
520
520
|
});
|
|
521
521
|
it("uses saved markup when it exists", async () => {
|
|
@@ -574,7 +574,7 @@ describe("markupFetcher", () => {
|
|
|
574
574
|
copy_submit_button: "custom submit button",
|
|
575
575
|
},
|
|
576
576
|
});
|
|
577
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
577
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Fsome%2Fpath©_confirmation_message=custom+confirmation+message©_submit_button=custom+submit+button", expect.anything());
|
|
578
578
|
});
|
|
579
579
|
});
|
|
580
580
|
describe("timezone validation", () => {
|
|
@@ -606,7 +606,7 @@ describe("markupFetcher", () => {
|
|
|
606
606
|
tz: "America/New_York",
|
|
607
607
|
environment: "production",
|
|
608
608
|
});
|
|
609
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
609
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Fsome%2Fpath&tz=America%2FNew_York", expect.anything());
|
|
610
610
|
expect(result).toEqual("results!");
|
|
611
611
|
});
|
|
612
612
|
it("trims a valid timezone", async () => {
|
|
@@ -625,7 +625,7 @@ describe("markupFetcher", () => {
|
|
|
625
625
|
tz: " America/Chicago ",
|
|
626
626
|
environment: "production",
|
|
627
627
|
});
|
|
628
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
628
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Fsome%2Fpath&tz=America%2FChicago", expect.anything());
|
|
629
629
|
expect(result).toEqual("results!");
|
|
630
630
|
});
|
|
631
631
|
});
|
|
@@ -649,7 +649,7 @@ describe("passing schema", function () {
|
|
|
649
649
|
environment: "production",
|
|
650
650
|
});
|
|
651
651
|
expect(injectSchemaSpy).toHaveBeenCalledWith("results!", { foo: "bar" });
|
|
652
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
652
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest", expect.anything());
|
|
653
653
|
expect(result).toEqual("results!");
|
|
654
654
|
});
|
|
655
655
|
it("does not stringify schema if given a string", async () => {
|
|
@@ -670,7 +670,7 @@ describe("passing schema", function () {
|
|
|
670
670
|
environment: "production",
|
|
671
671
|
});
|
|
672
672
|
expect(injectSchemaSpy).toHaveBeenCalledWith("results!", { foo: "bar" });
|
|
673
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
673
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest", expect.anything());
|
|
674
674
|
expect(result).toEqual("results!");
|
|
675
675
|
});
|
|
676
676
|
it("returns markup if invalid json is provided", async () => {
|
|
@@ -691,7 +691,7 @@ describe("passing schema", function () {
|
|
|
691
691
|
environment: "production",
|
|
692
692
|
});
|
|
693
693
|
expect(injectSchemaSpy).not.toHaveBeenCalled();
|
|
694
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
694
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest", expect.anything());
|
|
695
695
|
expect(result).toEqual("results!");
|
|
696
696
|
});
|
|
697
697
|
});
|
|
@@ -19,7 +19,7 @@ describe("simpleMarkupFetcher", () => {
|
|
|
19
19
|
environment: "production",
|
|
20
20
|
});
|
|
21
21
|
expect(injectSchemaSpy).not.toHaveBeenCalled();
|
|
22
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
22
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest", expect.objectContaining({
|
|
23
23
|
headers: expect.objectContaining({
|
|
24
24
|
Accept: "application/json",
|
|
25
25
|
Authorization: "Bearer 123abc",
|
|
@@ -44,7 +44,7 @@ describe("simpleMarkupFetcher", () => {
|
|
|
44
44
|
apiKey: "123abc",
|
|
45
45
|
environment: "development",
|
|
46
46
|
});
|
|
47
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
47
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Ftest&stub=true", expect.anything());
|
|
48
48
|
expect(result).toEqual("results!");
|
|
49
49
|
});
|
|
50
50
|
it("uses different base URL", async () => {
|
|
@@ -63,7 +63,7 @@ describe("simpleMarkupFetcher", () => {
|
|
|
63
63
|
baseUrl: "http://ur-mom.com",
|
|
64
64
|
environment: "production",
|
|
65
65
|
});
|
|
66
|
-
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
66
|
+
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v4/markup?domain=test.com&path=%2Ftest", expect.anything());
|
|
67
67
|
expect(result).toEqual("results!");
|
|
68
68
|
});
|
|
69
69
|
it("respects production!!!", async () => {
|
|
@@ -82,7 +82,7 @@ describe("simpleMarkupFetcher", () => {
|
|
|
82
82
|
baseUrl: "http://ur-mom.com",
|
|
83
83
|
environment: "production",
|
|
84
84
|
});
|
|
85
|
-
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/
|
|
85
|
+
expect(fetchMock).toHaveBeenCalledWith("http://ur-mom.com/api/v4/markup?domain=test.com&path=%2Ftest", expect.anything());
|
|
86
86
|
expect(result).toEqual("results!");
|
|
87
87
|
});
|
|
88
88
|
it("falls back to root path", async () => {
|
|
@@ -100,7 +100,7 @@ describe("simpleMarkupFetcher", () => {
|
|
|
100
100
|
apiKey: "123abc",
|
|
101
101
|
environment: "production",
|
|
102
102
|
});
|
|
103
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
103
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2F", expect.anything());
|
|
104
104
|
expect(result).toEqual("results!");
|
|
105
105
|
});
|
|
106
106
|
it("credentials are invalid", async () => {
|
|
@@ -152,7 +152,7 @@ describe("simpleMarkupFetcher", () => {
|
|
|
152
152
|
copy_submit_button: "custom submit button",
|
|
153
153
|
},
|
|
154
154
|
});
|
|
155
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
155
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2F©_confirmation_message=custom+confirmation+message©_submit_button=custom+submit+button", expect.anything());
|
|
156
156
|
expect(result).toEqual("results!");
|
|
157
157
|
});
|
|
158
158
|
it("passes date format string", async () => {
|
|
@@ -171,7 +171,7 @@ describe("simpleMarkupFetcher", () => {
|
|
|
171
171
|
environment: "production",
|
|
172
172
|
dateFormat: "yyyy-MM-dd",
|
|
173
173
|
});
|
|
174
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
174
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2F&date_format=yyyy-MM-dd", expect.anything());
|
|
175
175
|
});
|
|
176
176
|
it("response isn't ok", async () => {
|
|
177
177
|
const fetchMock = vi.fn().mockImplementation(() => {
|
|
@@ -208,7 +208,7 @@ describe("simpleMarkupFetcher", () => {
|
|
|
208
208
|
copy_submit_button: "custom submit button",
|
|
209
209
|
},
|
|
210
210
|
});
|
|
211
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
211
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Fsome%2Fpath©_confirmation_message=custom+confirmation+message©_submit_button=custom+submit+button", expect.anything());
|
|
212
212
|
});
|
|
213
213
|
});
|
|
214
214
|
describe("timezone validation", () => {
|
|
@@ -240,7 +240,7 @@ describe("simpleMarkupFetcher", () => {
|
|
|
240
240
|
tz: "America/New_York",
|
|
241
241
|
environment: "production",
|
|
242
242
|
});
|
|
243
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
243
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Fsome%2Fpath&tz=America%2FNew_York", expect.anything());
|
|
244
244
|
expect(result).toEqual("results!");
|
|
245
245
|
});
|
|
246
246
|
it("trims a valid timezone", async () => {
|
|
@@ -259,7 +259,7 @@ describe("simpleMarkupFetcher", () => {
|
|
|
259
259
|
tz: " America/Chicago ",
|
|
260
260
|
environment: "production",
|
|
261
261
|
});
|
|
262
|
-
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/
|
|
262
|
+
expect(fetchMock).toHaveBeenCalledWith("https://go.jamcomments.com/api/v4/markup?domain=test.com&path=%2Fsome%2Fpath&tz=America%2FChicago", expect.anything());
|
|
263
263
|
expect(result).toEqual("results!");
|
|
264
264
|
});
|
|
265
265
|
});
|