@jjlmoya/utils-tabletop 1.40.1 → 1.42.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jjlmoya/utils-tabletop",
3
- "version": "1.40.1",
3
+ "version": "1.42.0",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -0,0 +1,14 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { getCacheControl, LONG_LIVED_ASSET_CACHE, SITEMAP_CACHE } from "../worker";
3
+
4
+ describe("MFE cache contract", () => {
5
+ it("caches versioned assets and manifests for one year", () => {
6
+ expect(getCacheControl("/_utilities/tabletop/images/tool.webp")).toBe(LONG_LIVED_ASSET_CACHE);
7
+ expect(getCacheControl("/_utilities/tabletop/styles/tool.css")).toBe(LONG_LIVED_ASSET_CACHE);
8
+ expect(getCacheControl("/en/utilities/categories/tabletop/tool/manifest.json")).toBe(LONG_LIVED_ASSET_CACHE);
9
+ });
10
+
11
+ it("keeps sitemaps refreshable", () => {
12
+ expect(getCacheControl("/_utilities/en/tabletop/sitemap.xml")).toBe(SITEMAP_CACHE);
13
+ });
14
+ });
package/src/worker.ts CHANGED
@@ -2,11 +2,12 @@ interface UtilityMfeEnvironment {
2
2
  ASSETS: { fetch(request: Request): Promise<Response> };
3
3
  }
4
4
 
5
- const LONG_LIVED_ASSET_CACHE = "public, max-age=31536000, immutable";
6
- const SITEMAP_CACHE = "public, max-age=3600, s-maxage=3600, must-revalidate";
5
+ export const LONG_LIVED_ASSET_CACHE = "public, max-age=31536000, immutable";
6
+ export const SITEMAP_CACHE = "public, max-age=3600, s-maxage=3600, must-revalidate";
7
7
 
8
- const getCacheControl = (pathname: string): string | undefined => {
8
+ export const getCacheControl = (pathname: string): string | undefined => {
9
9
  if (pathname.endsWith("/sitemap.xml")) return SITEMAP_CACHE;
10
+ if (pathname.endsWith("/manifest.json")) return LONG_LIVED_ASSET_CACHE;
10
11
  if (pathname.startsWith("/_utilities/")) {
11
12
  return LONG_LIVED_ASSET_CACHE;
12
13
  }