@jam-comments/server-utilities 5.10.0 → 5.10.2

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 CHANGED
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Store = exports.logError = exports.log = exports.removeFalseyValues = exports.fetchAll = exports.markupFetcher = void 0;
7
4
  var markupFetcher_1 = require("./markupFetcher");
@@ -13,4 +10,4 @@ var log_1 = require("./log");
13
10
  Object.defineProperty(exports, "log", { enumerable: true, get: function () { return log_1.log; } });
14
11
  Object.defineProperty(exports, "logError", { enumerable: true, get: function () { return log_1.logError; } });
15
12
  var store_1 = require("./store");
16
- Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return __importDefault(store_1).default; } });
13
+ Object.defineProperty(exports, "Store", { enumerable: true, get: function () { return store_1.Store; } });
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.fetchAll = fetchAll;
7
4
  exports.batchMarkupFetcher = batchMarkupFetcher;
@@ -10,9 +7,9 @@ exports.makeMarkupRequest = makeMarkupRequest;
10
7
  exports.markupFetcher = markupFetcher;
11
8
  const injectSchema_1 = require("./injectSchema");
12
9
  const utils_1 = require("./utils");
13
- const store_1 = __importDefault(require("./store"));
10
+ const store_1 = require("./store");
14
11
  const BASE_URL = "https://go.jamcomments.com";
15
- async function fetchAll({ tz = undefined, dateFormat = undefined, domain, apiKey, baseUrl = BASE_URL, environment = (0, utils_1.getEnvironment)(), copy = {}, }, platform, fetchImplementation = fetch, batchMarkupFetcherImpl = batchMarkupFetcher, store = new store_1.default()) {
12
+ async function fetchAll({ tz = undefined, dateFormat = undefined, domain, apiKey, baseUrl = BASE_URL, environment = (0, utils_1.getEnvironment)(), copy = {}, }, platform, fetchImplementation = fetch, batchMarkupFetcherImpl = batchMarkupFetcher, store = new store_1.Store()) {
16
13
  const fetchBatchMarkup = batchMarkupFetcherImpl(platform, fetchImplementation);
17
14
  let shouldKeepFetching = true;
18
15
  let page = 1;
@@ -100,7 +97,7 @@ async function makeMarkupRequest({ tz, path, page, domain, apiKey, dateFormat, c
100
97
  }
101
98
  return response;
102
99
  }
103
- function markupFetcher(platform, fetchImplementation = fetch, store = new store_1.default()) {
100
+ function markupFetcher(platform, fetchImplementation = fetch, store = new store_1.Store()) {
104
101
  return async ({ tz = undefined, path, domain, apiKey, schema, dateFormat, baseUrl = BASE_URL, environment = (0, utils_1.getEnvironment)(), copy = {}, }) => {
105
102
  path = path || "/";
106
103
  const cachedMarkup = (() => {
package/dist/cjs/store.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Store = void 0;
3
4
  class Store {
4
5
  store;
5
6
  constructor() {
@@ -8,10 +9,10 @@ class Store {
8
9
  this.store = globalThis.jamCommentsStore;
9
10
  }
10
11
  set(path, markup) {
11
- this.store.set(path, markup);
12
+ this.store.set(this.#normalizePath(path), markup);
12
13
  }
13
14
  get(path) {
14
- return this.store.get(path) || null;
15
+ return this.store.get(this.#normalizePath(path)) || null;
15
16
  }
16
17
  clear() {
17
18
  this.store.clear();
@@ -22,5 +23,15 @@ class Store {
22
23
  get emptyMarkup() {
23
24
  return this.store.get("EMPTY") || null;
24
25
  }
26
+ #normalizePath(path) {
27
+ if (path === "EMPTY") {
28
+ return path;
29
+ }
30
+ let withLeadingSlash = path.startsWith("/") ? path : `/${path}`;
31
+ let withNoTrailingSlash = withLeadingSlash.endsWith("/")
32
+ ? withLeadingSlash.slice(0, -1)
33
+ : withLeadingSlash;
34
+ return withNoTrailingSlash.toLowerCase();
35
+ }
25
36
  }
26
- exports.default = Store;
37
+ exports.Store = Store;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const store_1 = require("./store");
5
+ (0, vitest_1.describe)("paths", () => {
6
+ (0, vitest_1.it)("cleans path when setting markup", () => {
7
+ const store = new store_1.Store();
8
+ store.set("/path", "markup");
9
+ (0, vitest_1.expect)(store.get("/path")).toEqual("markup");
10
+ (0, vitest_1.expect)(store.get("path")).toEqual("markup");
11
+ (0, vitest_1.expect)(store.get("path/")).toEqual("markup");
12
+ });
13
+ (0, vitest_1.it)("cleans path with mixed casing", () => {
14
+ const store = new store_1.Store();
15
+ store.set("/Path", "markup");
16
+ (0, vitest_1.expect)(store.get("/path")).toEqual("markup");
17
+ (0, vitest_1.expect)(store.get("path")).toEqual("markup");
18
+ (0, vitest_1.expect)(store.get("path/")).toEqual("markup");
19
+ });
20
+ (0, vitest_1.it)("works just fine with deep paths", () => {
21
+ const store = new store_1.Store();
22
+ store.set("/path/to/deep", "markup");
23
+ (0, vitest_1.expect)(store.get("/path/to/deep")).toEqual("markup");
24
+ (0, vitest_1.expect)(store.get("path/to/deep")).toEqual("markup");
25
+ (0, vitest_1.expect)(store.get("path/to/deep/")).toEqual("markup");
26
+ });
27
+ });
28
+ (0, vitest_1.it)("retrieves EMPTY markup", () => {
29
+ const store = new store_1.Store();
30
+ store.set("EMPTY", "empty markup");
31
+ (0, vitest_1.expect)(store.emptyMarkup).toEqual("empty markup");
32
+ });
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { markupFetcher, fetchAll } from "./markupFetcher";
2
2
  export { removeFalseyValues } from "./utils";
3
3
  export { log, logError } from "./log";
4
- export { default as Store } from "./store";
4
+ export { Store } from "./store";
@@ -1,6 +1,6 @@
1
1
  import { injectSchema } from "./injectSchema";
2
2
  import { getEnvironment, isValidTimezone, parseJson } from "./utils";
3
- import Store from "./store";
3
+ import { Store } from "./store";
4
4
  const BASE_URL = "https://go.jamcomments.com";
5
5
  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
6
  const fetchBatchMarkup = batchMarkupFetcherImpl(platform, fetchImplementation);
package/dist/esm/store.js CHANGED
@@ -1,4 +1,4 @@
1
- class Store {
1
+ export class Store {
2
2
  store;
3
3
  constructor() {
4
4
  globalThis.jamCommentsStore =
@@ -6,10 +6,10 @@ class Store {
6
6
  this.store = globalThis.jamCommentsStore;
7
7
  }
8
8
  set(path, markup) {
9
- this.store.set(path, markup);
9
+ this.store.set(this.#normalizePath(path), markup);
10
10
  }
11
11
  get(path) {
12
- return this.store.get(path) || null;
12
+ return this.store.get(this.#normalizePath(path)) || null;
13
13
  }
14
14
  clear() {
15
15
  this.store.clear();
@@ -20,5 +20,14 @@ class Store {
20
20
  get emptyMarkup() {
21
21
  return this.store.get("EMPTY") || null;
22
22
  }
23
+ #normalizePath(path) {
24
+ if (path === "EMPTY") {
25
+ return path;
26
+ }
27
+ let withLeadingSlash = path.startsWith("/") ? path : `/${path}`;
28
+ let withNoTrailingSlash = withLeadingSlash.endsWith("/")
29
+ ? withLeadingSlash.slice(0, -1)
30
+ : withLeadingSlash;
31
+ return withNoTrailingSlash.toLowerCase();
32
+ }
23
33
  }
24
- export default Store;
@@ -0,0 +1,30 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { Store } from "./store";
3
+ describe("paths", () => {
4
+ it("cleans path when setting markup", () => {
5
+ const store = new Store();
6
+ store.set("/path", "markup");
7
+ expect(store.get("/path")).toEqual("markup");
8
+ expect(store.get("path")).toEqual("markup");
9
+ expect(store.get("path/")).toEqual("markup");
10
+ });
11
+ it("cleans path with mixed casing", () => {
12
+ const store = new Store();
13
+ store.set("/Path", "markup");
14
+ expect(store.get("/path")).toEqual("markup");
15
+ expect(store.get("path")).toEqual("markup");
16
+ expect(store.get("path/")).toEqual("markup");
17
+ });
18
+ it("works just fine with deep paths", () => {
19
+ const store = new Store();
20
+ store.set("/path/to/deep", "markup");
21
+ expect(store.get("/path/to/deep")).toEqual("markup");
22
+ expect(store.get("path/to/deep")).toEqual("markup");
23
+ expect(store.get("path/to/deep/")).toEqual("markup");
24
+ });
25
+ });
26
+ it("retrieves EMPTY markup", () => {
27
+ const store = new Store();
28
+ store.set("EMPTY", "empty markup");
29
+ expect(store.emptyMarkup).toEqual("empty markup");
30
+ });
@@ -2,4 +2,4 @@ export type { CustomCopy } from "./markupFetcher";
2
2
  export { markupFetcher, fetchAll } from "./markupFetcher";
3
3
  export { removeFalseyValues } from "./utils";
4
4
  export { log, logError } from "./log";
5
- export { default as Store } from "./store";
5
+ export { Store } from "./store";
@@ -1,4 +1,4 @@
1
- import Store from "./store";
1
+ import { Store } from "./store";
2
2
  export interface CustomCopy {
3
3
  confirmationMessage?: string;
4
4
  submitButton?: string;
@@ -1,4 +1,5 @@
1
- declare class Store {
1
+ export declare class Store {
2
+ #private;
2
3
  store: Map<string, string>;
3
4
  constructor();
4
5
  set(path: string, markup: string): void;
@@ -7,4 +8,3 @@ declare class Store {
7
8
  get hasData(): boolean;
8
9
  get emptyMarkup(): string | null;
9
10
  }
10
- export default Store;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jam-comments/server-utilities",
3
- "version": "5.10.0",
3
+ "version": "5.10.2",
4
4
  "description": "Various JavaScript utilities for JamComments.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -22,11 +22,11 @@
22
22
  "homepage": "https://jamcomments.com",
23
23
  "license": "GPL-2.0",
24
24
  "devDependencies": {
25
- "@types/node": "^22.5.1",
25
+ "@types/node": "^22.9.0",
26
26
  "prettier": "^3.3.3",
27
- "typescript": "^5.5.4",
28
- "vite": "^5.4.2",
29
- "vitest": "^2.0.5"
27
+ "typescript": "^5.6.3",
28
+ "vite": "^5.4.11",
29
+ "vitest": "^2.1.5"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"