@simpleapps-com/augur-server 2026.11.5 → 2026.11.6

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.
Files changed (75) hide show
  1. package/EXPORTS.md +26 -1
  2. package/README.md +21 -2
  3. package/dist/actions/action-rules.d.ts +99 -0
  4. package/dist/actions/action-rules.d.ts.map +1 -0
  5. package/dist/actions/agr-site.d.ts +7 -15
  6. package/dist/actions/agr-site.d.ts.map +1 -1
  7. package/dist/actions/commerce.d.ts.map +1 -1
  8. package/dist/actions/customers.d.ts +12 -15
  9. package/dist/actions/customers.d.ts.map +1 -1
  10. package/dist/actions/favorites.d.ts +9 -12
  11. package/dist/actions/favorites.d.ts.map +1 -1
  12. package/dist/actions/gregorovich.d.ts +7 -15
  13. package/dist/actions/gregorovich.d.ts.map +1 -1
  14. package/dist/actions/items.d.ts +8 -20
  15. package/dist/actions/items.d.ts.map +1 -1
  16. package/dist/actions/joomla.d.ts +8 -14
  17. package/dist/actions/joomla.d.ts.map +1 -1
  18. package/dist/actions/legacy.d.ts +10 -20
  19. package/dist/actions/legacy.d.ts.map +1 -1
  20. package/dist/actions/orders.d.ts +7 -14
  21. package/dist/actions/orders.d.ts.map +1 -1
  22. package/dist/actions/read-specs.d.ts +119 -0
  23. package/dist/actions/read-specs.d.ts.map +1 -0
  24. package/dist/actions/site.d.ts.map +1 -1
  25. package/dist/actions/vmi.d.ts +10 -16
  26. package/dist/actions/vmi.d.ts.map +1 -1
  27. package/dist/actions/wishlists.d.ts +11 -13
  28. package/dist/actions/wishlists.d.ts.map +1 -1
  29. package/dist/api.js +3 -2
  30. package/dist/api.js.map +1 -1
  31. package/dist/auth.js +3 -2
  32. package/dist/cache/redis-client.d.ts.map +1 -1
  33. package/dist/cache/redis-rules.d.ts +21 -0
  34. package/dist/cache/redis-rules.d.ts.map +1 -0
  35. package/dist/cache/spec-read.d.ts +39 -0
  36. package/dist/cache/spec-read.d.ts.map +1 -0
  37. package/dist/cache/with-cache.d.ts +2 -2
  38. package/dist/cache/with-cache.d.ts.map +1 -1
  39. package/dist/{chunk-FIM6LDMD.js → chunk-2RAKVFB5.js} +2 -2
  40. package/dist/{chunk-KSGH4DXD.js → chunk-4JPJQHT6.js} +2 -2
  41. package/dist/chunk-JIYVQWXK.js +10 -0
  42. package/dist/chunk-JIYVQWXK.js.map +1 -0
  43. package/dist/{chunk-U54IM6FL.js → chunk-SFXO74RC.js} +874 -719
  44. package/dist/chunk-SFXO74RC.js.map +1 -0
  45. package/dist/chunk-V76GZZF3.js +66 -0
  46. package/dist/chunk-V76GZZF3.js.map +1 -0
  47. package/dist/{chunk-6GPKXGPG.js → chunk-Z53NEFEQ.js} +8 -16
  48. package/dist/chunk-Z53NEFEQ.js.map +1 -0
  49. package/dist/hooks.js +3 -2
  50. package/dist/hooks.js.map +1 -1
  51. package/dist/index.js +4 -2
  52. package/dist/index.js.map +1 -1
  53. package/dist/query-action.js +3 -2
  54. package/dist/read-rules.d.ts +45 -0
  55. package/dist/read-rules.d.ts.map +1 -0
  56. package/dist/server-site-registry.d.ts.map +1 -1
  57. package/dist/server-site.d.ts.map +1 -1
  58. package/dist/site.js +24 -14
  59. package/dist/site.js.map +1 -1
  60. package/dist/sitemap-rules.d.ts +154 -0
  61. package/dist/sitemap-rules.d.ts.map +1 -0
  62. package/dist/sitemap.d.ts +80 -0
  63. package/dist/sitemap.d.ts.map +1 -0
  64. package/dist/sitemap.js +242 -0
  65. package/dist/sitemap.js.map +1 -0
  66. package/dist/testing.js +4 -2
  67. package/dist/testing.js.map +1 -1
  68. package/dist/utils/read-all-pages.d.ts +17 -0
  69. package/dist/utils/read-all-pages.d.ts.map +1 -0
  70. package/llms.txt +44 -1
  71. package/package.json +8 -4
  72. package/dist/chunk-6GPKXGPG.js.map +0 -1
  73. package/dist/chunk-U54IM6FL.js.map +0 -1
  74. /package/dist/{chunk-FIM6LDMD.js.map → chunk-2RAKVFB5.js.map} +0 -0
  75. /package/dist/{chunk-KSGH4DXD.js.map → chunk-4JPJQHT6.js.map} +0 -0
package/dist/site.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server-site.ts"],"sourcesContent":["import { hours } from \"@simpleapps-com/augur-utils\";\nimport { createSiteActions } from \"./actions/site\";\nimport type { SiteActionsConfig, SiteActions } from \"./actions/site\";\nimport { createAuthConfig } from \"./auth\";\nimport type { AugurAuthCallbacks, AugurAuthClient } from \"./auth\";\nimport type { NextAuthConfig } from \"next-auth\";\nimport { registerSiteActions } from \"./server-site-registry\";\nimport {\n registerSdkClient,\n registerSdkCallWrapper,\n registerAuthSecret,\n registerClientFactory,\n registerCrossSite,\n registerScopedCacheWrapper,\n} from \"./sdk-client-store\";\nimport { withRawSdkCache } from \"./cache/with-cache\";\nimport { crossSiteOf, ttlFor } from \"./rules\";\nimport { getCacheTier } from \"@simpleapps-com/augur-core\";\n\n/** Auth options forwarded to NextAuth when creating a server site. */\nexport interface ServerSiteAuthConfig {\n secret?: string;\n maxAge?: number;\n callbacks?: Partial<AugurAuthCallbacks>;\n debug?: boolean;\n /**\n * Cross-site sessions (the augur-support pattern: an augur_info client, and the target\n * `siteId` passed to `signIn`). Only when true does sign-in keep the target siteId and does\n * `queryAction` read the session cookie to use a client scoped to that site. Default off: a\n * site that does not set it never reads cookies in `queryAction`, so its pages can render\n * statically (atlas#105). A multi-tenant site MUST set it.\n */\n crossSite?: boolean;\n}\n\n/** Configuration for {@link createServerSite}, combining action config and auth. */\nexport interface ServerSiteConfig extends SiteActionsConfig {\n auth?: ServerSiteAuthConfig;\n}\n\n/** The object returned by {@link createServerSite}. */\nexport interface ServerSite<TApi extends object> {\n client: TApi;\n actions: SiteActions;\n auth: NextAuthConfig | undefined;\n}\n\n/**\n * Register what queryAction and sign-in need from `auth`: the secret (`auth.secret`, else\n * `AUTH_SECRET`) and the cross-site opt-in, the one source both read (atlas#105).\n */\nfunction registerSessionAuth(auth: ServerSiteAuthConfig | undefined): void {\n const authSecret = auth?.secret ?? process.env[\"AUTH_SECRET\"];\n if (authSecret) {\n registerAuthSecret(authSecret);\n }\n registerCrossSite(crossSiteOf(auth?.crossSite));\n}\n\n/**\n * Create a server-side site instance that bundles the SDK client, server\n * actions, and (optional) NextAuth configuration.\n *\n * @example\n * ```ts\n * import { AugurAPI } from \"@simpleapps-com/augur-api\";\n * import { createServerSite } from \"@simpleapps-com/augur-server/site\";\n *\n * const api = new AugurAPI({ siteId: process.env.AUGUR_SITE_ID!, bearerToken: process.env.AUGUR_JWT! });\n * export const site = createServerSite(api, {\n * defaultCustomerId: \"12345\",\n * auth: { secret: process.env.AUTH_SECRET },\n * });\n * ```\n */\nexport function createServerSite<TApi extends object>(\n client: TApi,\n config: ServerSiteConfig = {},\n): ServerSite<TApi> {\n const actions = createSiteActions(client, config);\n registerSiteActions(actions);\n registerSdkClient(client);\n\n // Register a cache wrapper that captures the site's Redis config.\n // queryAction uses this to wrap read methods in Redis caching without\n // importing the cache directly (which would pull ioredis into the client\n // bundle via tsup code splitting). The SDK's raw result is cached, in its\n // own key space (withRawSdkCache, #98); queryAction unwraps after the read.\n const { cachePrefix = \"\", redisTtl = hours(1), longRedisTtl = hours(8) } = config;\n registerSdkCallWrapper((methodPath, sdkCall, ...keyArgs) => {\n // An hour of staleTime or more: the long TTL; any other: the standard; 0: no caching.\n const ttl = ttlFor(getCacheTier(methodPath).staleTime, redisTtl, longRedisTtl);\n if (ttl === null) return sdkCall();\n return withRawSdkCache(cachePrefix, ttl, methodPath, sdkCall, ...keyArgs);\n });\n\n // Register scoped cache wrapper for per-request session credentials.\n // queryAction uses this to wrap scoped client calls with Redis caching\n // using the targetSiteId as the cache prefix.\n registerScopedCacheWrapper((prefix, methodPath, sdkCall, ...keyArgs) => {\n const ttl = ttlFor(getCacheTier(methodPath).staleTime, redisTtl, longRedisTtl);\n if (ttl === null) return sdkCall();\n return withRawSdkCache(prefix, ttl, methodPath, sdkCall, ...keyArgs);\n });\n\n // Register client factory for creating scoped SDK clients with\n // per-request credentials. Uses the same constructor + base config\n // (baseUrl, timeout, retries) but different siteId/bearerToken.\n const baseConfig = (client as Record<string, unknown>)[\"config\"] as\n Record<string, unknown> | undefined;\n if (baseConfig) {\n const Ctor = client.constructor as new (cfg: Record<string, unknown>) => object;\n registerClientFactory((siteId: string, bearerToken: string) => {\n return new Ctor({ ...baseConfig, siteId, bearerToken });\n });\n }\n\n registerSessionAuth(config.auth);\n\n const auth = config.auth\n ? createAuthConfig({\n augurClient: client as unknown as AugurAuthClient,\n defaultCustomerId: config.defaultCustomerId,\n defaultContactId: config.defaultContactId,\n ...config.auth,\n })\n : undefined;\n\n return { client, actions, auth };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AAiBtB,SAAS,oBAAoB;AAkC7B,SAAS,oBAAoB,MAA8C;AACzE,QAAM,aAAa,MAAM,UAAU,QAAQ,IAAI,aAAa;AAC5D,MAAI,YAAY;AACd,uBAAmB,UAAU;AAAA,EAC/B;AACA,oBAAkB,YAAY,MAAM,SAAS,CAAC;AAChD;AAkBO,SAAS,iBACd,QACA,SAA2B,CAAC,GACV;AAClB,QAAM,UAAU,kBAAkB,QAAQ,MAAM;AAChD,sBAAoB,OAAO;AAC3B,oBAAkB,MAAM;AAOxB,QAAM,EAAE,cAAc,IAAI,WAAW,MAAM,CAAC,GAAG,eAAe,MAAM,CAAC,EAAE,IAAI;AAC3E,yBAAuB,CAAC,YAAY,YAAY,YAAY;AAE1D,UAAM,MAAM,OAAO,aAAa,UAAU,EAAE,WAAW,UAAU,YAAY;AAC7E,QAAI,QAAQ,KAAM,QAAO,QAAQ;AACjC,WAAO,gBAAgB,aAAa,KAAK,YAAY,SAAS,GAAG,OAAO;AAAA,EAC1E,CAAC;AAKD,6BAA2B,CAAC,QAAQ,YAAY,YAAY,YAAY;AACtE,UAAM,MAAM,OAAO,aAAa,UAAU,EAAE,WAAW,UAAU,YAAY;AAC7E,QAAI,QAAQ,KAAM,QAAO,QAAQ;AACjC,WAAO,gBAAgB,QAAQ,KAAK,YAAY,SAAS,GAAG,OAAO;AAAA,EACrE,CAAC;AAKD,QAAM,aAAc,OAAmC,QAAQ;AAE/D,MAAI,YAAY;AACd,UAAM,OAAO,OAAO;AACpB,0BAAsB,CAAC,QAAgB,gBAAwB;AAC7D,aAAO,IAAI,KAAK,EAAE,GAAG,YAAY,QAAQ,YAAY,CAAC;AAAA,IACxD,CAAC;AAAA,EACH;AAEA,sBAAoB,OAAO,IAAI;AAE/B,QAAM,OAAO,OAAO,OAChB,iBAAiB;AAAA,IACf,aAAa;AAAA,IACb,mBAAmB,OAAO;AAAA,IAC1B,kBAAkB,OAAO;AAAA,IACzB,GAAG,OAAO;AAAA,EACZ,CAAC,IACD;AAEJ,SAAO,EAAE,QAAQ,SAAS,KAAK;AACjC;","names":[]}
1
+ {"version":3,"sources":["../src/server-site.ts"],"sourcesContent":["import { hours } from \"@simpleapps-com/augur-utils\";\nimport { createSiteActions } from \"./actions/site\";\nimport type { SiteActionsConfig, SiteActions } from \"./actions/site\";\nimport { createAuthConfig } from \"./auth\";\nimport type { AugurAuthCallbacks, AugurAuthClient } from \"./auth\";\nimport type { NextAuthConfig } from \"next-auth\";\nimport { registerSiteActions } from \"./server-site-registry\";\nimport {\n registerSdkClient,\n registerSdkCallWrapper,\n registerAuthSecret,\n registerClientFactory,\n registerCrossSite,\n registerScopedCacheWrapper,\n} from \"./sdk-client-store\";\nimport { withRawSdkCache } from \"./cache/with-cache\";\nimport { crossSiteOf } from \"./rules\";\nimport { serverTtlOf } from \"./read-rules\";\nimport { getCacheTier, isP21Path } from \"@simpleapps-com/augur-core\";\n\n/** Auth options forwarded to NextAuth when creating a server site. */\nexport interface ServerSiteAuthConfig {\n secret?: string;\n maxAge?: number;\n callbacks?: Partial<AugurAuthCallbacks>;\n debug?: boolean;\n /**\n * Cross-site sessions (the augur-support pattern: an augur_info client, and the target\n * `siteId` passed to `signIn`). Only when true does sign-in keep the target siteId and does\n * `queryAction` read the session cookie to use a client scoped to that site. Default off: a\n * site that does not set it never reads cookies in `queryAction`, so its pages can render\n * statically (atlas#105). A multi-tenant site MUST set it.\n */\n crossSite?: boolean;\n}\n\n/** Configuration for {@link createServerSite}, combining action config and auth. */\nexport interface ServerSiteConfig extends SiteActionsConfig {\n auth?: ServerSiteAuthConfig;\n}\n\n/** The object returned by {@link createServerSite}. */\nexport interface ServerSite<TApi extends object> {\n client: TApi;\n actions: SiteActions;\n auth: NextAuthConfig | undefined;\n}\n\n/**\n * Register what queryAction and sign-in need from `auth`: the secret (`auth.secret`, else\n * `AUTH_SECRET`) and the cross-site opt-in, the one source both read (atlas#105).\n */\nfunction registerSessionAuth(auth: ServerSiteAuthConfig | undefined): void {\n const authSecret = auth?.secret ?? process.env[\"AUTH_SECRET\"];\n if (authSecret) {\n registerAuthSecret(authSecret);\n }\n registerCrossSite(crossSiteOf(auth?.crossSite));\n}\n\n/**\n * Create a server-side site instance that bundles the SDK client, server\n * actions, and (optional) NextAuth configuration.\n *\n * @example\n * ```ts\n * import { AugurAPI } from \"@simpleapps-com/augur-api\";\n * import { createServerSite } from \"@simpleapps-com/augur-server/site\";\n *\n * const api = new AugurAPI({ siteId: process.env.AUGUR_SITE_ID!, bearerToken: process.env.AUGUR_JWT! });\n * export const site = createServerSite(api, {\n * defaultCustomerId: \"12345\",\n * auth: { secret: process.env.AUTH_SECRET },\n * });\n * ```\n */\nexport function createServerSite<TApi extends object>(\n client: TApi,\n config: ServerSiteConfig = {},\n): ServerSite<TApi> {\n const actions = createSiteActions(client, config);\n registerSiteActions(actions);\n registerSdkClient(client);\n\n // Register a cache wrapper that captures the site's Redis config.\n // queryAction uses this to wrap read methods in Redis caching without\n // importing the cache directly (which would pull ioredis into the client\n // bundle via tsup code splitting). The SDK's raw result is cached, in its\n // own key space (withRawSdkCache, #98); queryAction unwraps after the read.\n const { cachePrefix = \"\", redisTtl = hours(1), longRedisTtl = hours(8) } = config;\n // No Redis TTL on the tier (no-cache, user): no caching; else an hour of staleTime or more,\n // the long TTL; any other, the standard (proved serverTtlOf, atlas#102).\n const cachedRaw = <T>(\n prefix: string,\n methodPath: string,\n sdkCall: () => Promise<T>,\n keyArgs: unknown[],\n ): Promise<T> => {\n const tier = getCacheTier(methodPath);\n const ttl = serverTtlOf(\n tier.redisTtl !== undefined,\n isP21Path(methodPath),\n tier.staleTime,\n redisTtl,\n longRedisTtl,\n );\n if (ttl === null) return sdkCall();\n return withRawSdkCache(prefix, ttl, methodPath, sdkCall, ...keyArgs);\n };\n registerSdkCallWrapper((methodPath, sdkCall, ...keyArgs) =>\n cachedRaw(cachePrefix, methodPath, sdkCall, keyArgs),\n );\n\n // Register scoped cache wrapper for per-request session credentials.\n // queryAction uses this to wrap scoped client calls with Redis caching\n // using the targetSiteId as the cache prefix.\n registerScopedCacheWrapper((prefix, methodPath, sdkCall, ...keyArgs) =>\n cachedRaw(prefix, methodPath, sdkCall, keyArgs),\n );\n\n // Register client factory for creating scoped SDK clients with\n // per-request credentials. Uses the same constructor + base config\n // (baseUrl, timeout, retries) but different siteId/bearerToken.\n const baseConfig = (client as Record<string, unknown>)[\"config\"] as\n Record<string, unknown> | undefined;\n if (baseConfig) {\n const Ctor = client.constructor as new (cfg: Record<string, unknown>) => object;\n registerClientFactory((siteId: string, bearerToken: string) => {\n return new Ctor({ ...baseConfig, siteId, bearerToken });\n });\n }\n\n registerSessionAuth(config.auth);\n\n const auth = config.auth\n ? createAuthConfig({\n augurClient: client as unknown as AugurAuthClient,\n defaultCustomerId: config.defaultCustomerId,\n defaultContactId: config.defaultContactId,\n ...config.auth,\n })\n : undefined;\n\n return { client, actions, auth };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AAkBtB,SAAS,cAAc,iBAAiB;AAkCxC,SAAS,oBAAoB,MAA8C;AACzE,QAAM,aAAa,MAAM,UAAU,QAAQ,IAAI,aAAa;AAC5D,MAAI,YAAY;AACd,uBAAmB,UAAU;AAAA,EAC/B;AACA,oBAAkB,YAAY,MAAM,SAAS,CAAC;AAChD;AAkBO,SAAS,iBACd,QACA,SAA2B,CAAC,GACV;AAClB,QAAM,UAAU,kBAAkB,QAAQ,MAAM;AAChD,sBAAoB,OAAO;AAC3B,oBAAkB,MAAM;AAOxB,QAAM,EAAE,cAAc,IAAI,WAAW,MAAM,CAAC,GAAG,eAAe,MAAM,CAAC,EAAE,IAAI;AAG3E,QAAM,YAAY,CAChB,QACA,YACA,SACA,YACe;AACf,UAAM,OAAO,aAAa,UAAU;AACpC,UAAM,MAAM;AAAA,MACV,KAAK,aAAa;AAAA,MAClB,UAAU,UAAU;AAAA,MACpB,KAAK;AAAA,MACL;AAAA,MACA;AAAA,IACF;AACA,QAAI,QAAQ,KAAM,QAAO,QAAQ;AACjC,WAAO,gBAAgB,QAAQ,KAAK,YAAY,SAAS,GAAG,OAAO;AAAA,EACrE;AACA;AAAA,IAAuB,CAAC,YAAY,YAAY,YAC9C,UAAU,aAAa,YAAY,SAAS,OAAO;AAAA,EACrD;AAKA;AAAA,IAA2B,CAAC,QAAQ,YAAY,YAAY,YAC1D,UAAU,QAAQ,YAAY,SAAS,OAAO;AAAA,EAChD;AAKA,QAAM,aAAc,OAAmC,QAAQ;AAE/D,MAAI,YAAY;AACd,UAAM,OAAO,OAAO;AACpB,0BAAsB,CAAC,QAAgB,gBAAwB;AAC7D,aAAO,IAAI,KAAK,EAAE,GAAG,YAAY,QAAQ,YAAY,CAAC;AAAA,IACxD,CAAC;AAAA,EACH;AAEA,sBAAoB,OAAO,IAAI;AAE/B,QAAM,OAAO,OAAO,OAChB,iBAAiB;AAAA,IACf,aAAa;AAAA,IACb,mBAAmB,OAAO;AAAA,IAC1B,kBAAkB,OAAO;AAAA,IACzB,GAAG,OAAO;AAAA,EACZ,CAAC,IACD;AAEJ,SAAO,EAAE,QAAQ,SAAS,KAAK;AACjC;","names":[]}
@@ -0,0 +1,154 @@
1
+ /** One item for a `<urlset>`: its page URL and, when known, its last change ("" leaves it out). */
2
+ export interface SitemapRow {
3
+ loc: string;
4
+ lastmod: string;
5
+ }
6
+ /** What a sitemap request comes to: served, not a sitemap (404), or Augur failed (503). */
7
+ export type SitemapOutcome = "ok" | "not-found" | "unavailable";
8
+ /**
9
+ * The SDK's `total` as a count: itself when a whole number ≥ 0, else 0 (no item sitemaps rather
10
+ * than a guess).
11
+ *
12
+ * @ensures exactly the model's UsableTotal
13
+ */
14
+ export declare function usableTotal(isWhole: boolean, n: number): number;
15
+ /**
16
+ * How many 5,000-item sitemaps cover `total` items (the endpoint fixes a page at 5,000).
17
+ *
18
+ * @requires total ≥ 0
19
+ * @ensures result = ⌈total / 5000⌉ — exactly the model's ItemSitemapCount
20
+ */
21
+ export declare function itemSitemapCount(total: number): number;
22
+ /**
23
+ * The page a request names (the rewrite's bare `:page`): its value when it is a canonical
24
+ * natural number, else 0, "not a page" (`0`, `01`, `1e3`, ` 1`, `-1` and text never name one).
25
+ *
26
+ * @ensures result = canonicalNatValue(page) for canonical text, else 0 — exactly the model's
27
+ * ItemSitemapPage (the test is spelled out: canonicalNatValue's contract names
28
+ * isCanonicalNat, which this file must call to resolve, models/LSC-GAPS.md)
29
+ */
30
+ export declare function parseItemSitemapPage(page: string): number;
31
+ /**
32
+ * An item page's outcome: not a page, or an empty page past the first, is "not-found"; a failed
33
+ * fetch is "unavailable"; anything else is served. `rows` counts what the endpoint returned,
34
+ * before the scope filter.
35
+ *
36
+ * @ensures exactly the model's ItemOutcome
37
+ */
38
+ export declare function itemSitemapOutcome(page: number, fetched: boolean, rows: number): SitemapOutcome;
39
+ /**
40
+ * The item index's outcome: served when the count was read, else "unavailable" (a 200 with no
41
+ * sitemaps would tell a crawler the site has none).
42
+ *
43
+ * @ensures exactly the model's IndexOutcome
44
+ */
45
+ export declare function sitemapIndexOutcome(fetched: boolean): SitemapOutcome;
46
+ /**
47
+ * The HTTP status of an outcome.
48
+ *
49
+ * @ensures exactly the model's StatusOf
50
+ */
51
+ export declare function sitemapStatus(o: SitemapOutcome): number;
52
+ /**
53
+ * An outcome's `Cache-Control`: a served sitemap for a day at the CDN and an hour in browsers
54
+ * (rebuilt at most daily); a 404 or a 503 never.
55
+ *
56
+ * @ensures exactly the model's CacheControlOf
57
+ */
58
+ export declare function sitemapCacheControl(o: SitemapOutcome): string;
59
+ /**
60
+ * An outcome's `Retry-After` in seconds: an hour for a 503, else "" (no header).
61
+ *
62
+ * @ensures exactly the model's RetryAfterOf
63
+ */
64
+ export declare function sitemapRetryAfter(o: SitemapOutcome): string;
65
+ /**
66
+ * Whether a request's page is worth asking Augur for: only a page (≥ 1); "not a page" is
67
+ * answered without a call.
68
+ *
69
+ * @ensures exactly the model's FetchesPage
70
+ */
71
+ export declare function fetchesPage(page: number): boolean;
72
+ /**
73
+ * A response's body: the XML when served, else a short plain-text reason.
74
+ *
75
+ * @ensures exactly the model's BodyOf
76
+ */
77
+ export declare function sitemapBody(o: SitemapOutcome, xml: string): string;
78
+ /** One response header. */
79
+ export interface SitemapHeader {
80
+ name: string;
81
+ value: string;
82
+ }
83
+ /**
84
+ * A response's headers: its type, its cache rule, and `Retry-After` on a 503 only.
85
+ *
86
+ * @ensures exactly the model's HeadersOf
87
+ */
88
+ export declare function sitemapHeaders(o: SitemapOutcome): SitemapHeader[];
89
+ /**
90
+ * The items' folder as a path, with one leading and one trailing "/" ("items" → "/items/").
91
+ *
92
+ * @ensures exactly the model's SitemapBase
93
+ */
94
+ export declare function sitemapBase(base: string): string;
95
+ /**
96
+ * The folder every item sitemap, and every item it lists, sits in: the site's origin with no
97
+ * trailing "/", then the base.
98
+ *
99
+ * @ensures result = rStripCode(siteUrl, "/") + sitemapBase(base) — exactly the model's ItemsPrefix
100
+ */
101
+ export declare function itemsPrefix(siteUrl: string, base: string): string;
102
+ /**
103
+ * Item sitemap n's URL: `{siteUrl}{base}sitemap-{n}.xml`.
104
+ *
105
+ * @ensures exactly the model's ItemSitemapUrl
106
+ */
107
+ export declare function itemSitemapUrl(siteUrl: string, base: string, n: number): string;
108
+ /**
109
+ * Whether a link is under the items' folder (the location rule); an empty link never is.
110
+ *
111
+ * @ensures exactly the model's InScope
112
+ */
113
+ export declare function inScope(prefix: string, loc: string): boolean;
114
+ /**
115
+ * The item index: a `<sitemapindex>` of `{base}sitemap-1.xml` … `{base}sitemap-{count}.xml`.
116
+ *
117
+ * @ensures exactly the model's ItemIndex
118
+ */
119
+ export declare function buildSitemapIndexXml(siteUrl: string, base: string, count: number): string;
120
+ /**
121
+ * An item page: a `<urlset>` of the rows under the items' folder, in order.
122
+ *
123
+ * @ensures exactly the model's ItemUrlset
124
+ */
125
+ export declare function buildUrlsetXml(rows: SitemapRow[], siteUrl: string, base: string): string;
126
+ /**
127
+ * The Next.js rewrite `source` for the page files, `{base}sitemap-:page.xml`, with every
128
+ * character Next reads as pattern syntax (`( ) { } [ ] | \ ^ . : * + - ? $`) escaped by a "\".
129
+ *
130
+ * @ensures exactly the model's RewriteSource
131
+ */
132
+ export declare function rewriteSource(base: string): string;
133
+ /**
134
+ * The rewrite's destination, the page handler's route `{base}sitemap.xml/:page`
135
+ * (`app/<base>/sitemap.xml/[page]/route.ts`).
136
+ *
137
+ * @ensures exactly the model's RewriteDestination
138
+ */
139
+ export declare function rewriteDestination(base: string): string;
140
+ /**
141
+ * Whether a path is one of the item sitemaps (the index or a page file), which a site's proxy
142
+ * MUST pass through before any item-URL redirect (the proxy runs before rewrites).
143
+ *
144
+ * @ensures exactly the model's IsSitemapPath
145
+ */
146
+ export declare function isSitemapPath(pathname: string, base: string): boolean;
147
+ /**
148
+ * robots.txt's sitemaps: the site's own root `/sitemap.xml` and the item index. Two lines, since
149
+ * the specs name no index inside an index.
150
+ *
151
+ * @ensures exactly the model's RobotsSitemaps
152
+ */
153
+ export declare function robotsSitemaps(siteUrl: string, base: string): string[];
154
+ //# sourceMappingURL=sitemap-rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sitemap-rules.d.ts","sourceRoot":"","sources":["../src/sitemap-rules.ts"],"names":[],"mappings":"AA2B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cAAc,GAAG,aAAa,EAAE,CAUjE;AAID;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKhD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIjE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAM/E;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAI5D;AAsBD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAMzF;AAuBD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAMxF;AAID;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA2BlD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIvD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAIrE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAMtE"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Item sitemaps for a Next.js site, built at request time from the Augur SDK's
3
+ * `googMc.sitemaps.items.list` (atlas#101), so the number of files follows the catalog without a
4
+ * deploy, whatever its size.
5
+ *
6
+ * Layout: the item index at `{base}sitemap.xml` and page n (5,000 items) at
7
+ * `{base}sitemap-{n}.xml`, in the items' own folder (`base`, default "/items/"), so by the
8
+ * sitemap protocol's location rule they may list the item pages there. The site's root
9
+ * `/sitemap.xml` stays its own; robots.txt names both (`robotsSitemaps`).
10
+ *
11
+ * Every decision is a proved rule in `sitemap-rules.ts`; this file only awaits the SDK and maps
12
+ * the rules' answers to a Response.
13
+ */
14
+ import type { AugurAPI } from "@simpleapps-com/augur-api";
15
+ export { buildSitemapIndexXml, buildUrlsetXml, inScope, isSitemapPath, itemSitemapCount, itemSitemapUrl, parseItemSitemapPage, robotsSitemaps, sitemapBase, type SitemapOutcome, type SitemapRow, } from "./sitemap-rules";
16
+ /** The items' folder when a site names none. */
17
+ export declare const DEFAULT_SITEMAP_BASE = "/items/";
18
+ /**
19
+ * How long one Augur call may take, in milliseconds: crawlers wait longer than page visitors, and
20
+ * a call past it is a 503 the crawler retries.
21
+ */
22
+ export declare const DEFAULT_SITEMAP_DEADLINE = 10000;
23
+ /** What the handlers need of a server site: its SDK client (`createServerSite`'s result fits). */
24
+ export interface SitemapSite {
25
+ client: Pick<AugurAPI, "withRequest" | "googMc">;
26
+ }
27
+ /** Where the site lives and where its item sitemaps sit. */
28
+ export interface SitemapOptions {
29
+ /** The site's origin, e.g. "https://www.example.com" (a trailing "/" is dropped). */
30
+ siteUrl: string;
31
+ /** The items' folder, matching the item links Augur returns; default "/items/". */
32
+ base?: string;
33
+ /** Milliseconds one Augur call may take; default 10,000. */
34
+ deadline?: number;
35
+ }
36
+ /** A Next.js rewrite, as `next.config` `rewrites()` takes it. */
37
+ export interface SitemapRewrite {
38
+ source: string;
39
+ destination: string;
40
+ }
41
+ /**
42
+ * The item index's Route Handler, for `app/items/sitemap.xml/route.ts` (or the folder `base`
43
+ * names): a `<sitemapindex>` of every item page file, or a 503 when Augur can't be read.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * export const dynamic = "force-dynamic";
48
+ * export const GET = createSitemapIndexHandler(site, { siteUrl: "https://www.example.com" });
49
+ * ```
50
+ */
51
+ export declare function createSitemapIndexHandler(site: SitemapSite, options: SitemapOptions): () => Promise<Response>;
52
+ /**
53
+ * An item page's Route Handler, for `app/items/sitemap.xml/[page]/route.ts`, which
54
+ * `sitemapRewrite` maps `{base}sitemap-{n}.xml` onto: a `<urlset>` of page n's items under
55
+ * `base`, a 404 for no such page, or a 503 when Augur can't be read.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * export const dynamic = "force-dynamic";
60
+ * export const GET = createItemSitemapHandler(site, { siteUrl: "https://www.example.com" });
61
+ * ```
62
+ */
63
+ export declare function createItemSitemapHandler(site: SitemapSite, options: SitemapOptions): (_request: Request, context: {
64
+ params: Promise<{
65
+ page: string;
66
+ }>;
67
+ }) => Promise<Response>;
68
+ /**
69
+ * The Next.js rewrite from `{base}sitemap-{n}.xml` to the item page handler's route; spread it
70
+ * into `next.config`'s `rewrites()`.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * async rewrites() {
75
+ * return [sitemapRewrite()];
76
+ * }
77
+ * ```
78
+ */
79
+ export declare function sitemapRewrite(base?: string): SitemapRewrite;
80
+ //# sourceMappingURL=sitemap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sitemap.d.ts","sourceRoot":"","sources":["../src/sitemap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAmB1D,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,OAAO,EACP,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,KAAK,cAAc,EACnB,KAAK,UAAU,GAChB,MAAM,iBAAiB,CAAC;AAEzB,gDAAgD;AAChD,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAE/C,kGAAkG;AAClG,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,aAAa,GAAG,QAAQ,CAAC,CAAC;CAClD;AAED,4DAA4D;AAC5D,MAAM,WAAW,cAAc;IAC7B,qFAAqF;IACrF,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,iEAAiE;AACjE,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AA2CD;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,SAEjE,OAAO,CAAC,QAAQ,CAAC,CAQnC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,IAG/E,UAAU,OAAO,EACjB,SAAS;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,KAC7C,OAAO,CAAC,QAAQ,CAAC,CAMrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,IAAI,GAAE,MAA6B,GAAG,cAAc,CAElF"}
@@ -0,0 +1,242 @@
1
+ import {
2
+ decimal
3
+ } from "./chunk-JIYVQWXK.js";
4
+ import {
5
+ canonicalNatValue,
6
+ endsWith,
7
+ isCanonicalNat,
8
+ lineFeed,
9
+ rStripCode,
10
+ startsWithAt
11
+ } from "./chunk-V76GZZF3.js";
12
+
13
+ // ../utils/src/replace.ts
14
+ function codeIndex(codes, c, i) {
15
+ if (i === codes.length) return -1;
16
+ return codes[i] === c ? i : codeIndex(codes, c, i + 1);
17
+ }
18
+ function substitutedText(s, codes, texts) {
19
+ if (s.length === 0) return "";
20
+ const k = codeIndex(codes, s.charCodeAt(0), 0);
21
+ const head = k >= 0 && k < texts.length ? texts[k] : s.slice(0, 1);
22
+ return head + substitutedText(s.slice(1), codes, texts);
23
+ }
24
+
25
+ // ../utils/src/xml.ts
26
+ function xmlEntity(c) {
27
+ if (c === 38) return "&amp;";
28
+ if (c === 60) return "&lt;";
29
+ if (c === 62) return "&gt;";
30
+ if (c === 34) return "&quot;";
31
+ if (c === 39) return "&apos;";
32
+ return "";
33
+ }
34
+ function xmlEscaped(s) {
35
+ if (s.length === 0) return "";
36
+ const entity = xmlEntity(s.charCodeAt(0));
37
+ return (entity === "" ? s.slice(0, 1) : entity) + xmlEscaped(s.slice(1));
38
+ }
39
+
40
+ // ../utils/src/sitemap.ts
41
+ function urlsetHead() {
42
+ return '<?xml version="1.0" encoding="UTF-8"?>' + lineFeed() + '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' + lineFeed();
43
+ }
44
+ function urlsetTail() {
45
+ return "</urlset>" + lineFeed();
46
+ }
47
+ function sitemapIndexHead() {
48
+ return '<?xml version="1.0" encoding="UTF-8"?>' + lineFeed() + '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' + lineFeed();
49
+ }
50
+ function sitemapIndexTail() {
51
+ return "</sitemapindex>" + lineFeed();
52
+ }
53
+ function urlBlock(loc, lastmod) {
54
+ const date = lastmod === "" ? "" : " <lastmod>" + xmlEscaped(lastmod) + "</lastmod>" + lineFeed();
55
+ return " <url>" + lineFeed() + " <loc>" + xmlEscaped(loc) + "</loc>" + lineFeed() + date + " </url>" + lineFeed();
56
+ }
57
+ function sitemapBlock(loc) {
58
+ return " <sitemap>" + lineFeed() + " <loc>" + xmlEscaped(loc) + "</loc>" + lineFeed() + " </sitemap>" + lineFeed();
59
+ }
60
+
61
+ // src/sitemap-rules.ts
62
+ function usableTotal(isWhole, n) {
63
+ return isWhole && n >= 0 ? n : 0;
64
+ }
65
+ function itemSitemapCount(total) {
66
+ return Math.floor((total + 4999) / 5e3);
67
+ }
68
+ function parseItemSitemapPage(page) {
69
+ return isCanonicalNat(page) ? canonicalNatValue(page) : 0;
70
+ }
71
+ function itemSitemapOutcome(page, fetched, rows) {
72
+ if (page === 0) return "not-found";
73
+ if (!fetched) return "unavailable";
74
+ if (rows === 0 && page > 1) return "not-found";
75
+ return "ok";
76
+ }
77
+ function sitemapIndexOutcome(fetched) {
78
+ return fetched ? "ok" : "unavailable";
79
+ }
80
+ function sitemapStatus(o) {
81
+ if (o === "ok") return 200;
82
+ return o === "not-found" ? 404 : 503;
83
+ }
84
+ function sitemapCacheControl(o) {
85
+ return o === "ok" ? "public, max-age=3600, s-maxage=86400" : "no-store";
86
+ }
87
+ function sitemapRetryAfter(o) {
88
+ return o === "unavailable" ? "3600" : "";
89
+ }
90
+ function fetchesPage(page) {
91
+ return page >= 1;
92
+ }
93
+ function sitemapBody(o, xml) {
94
+ if (o === "ok") return xml;
95
+ return o === "not-found" ? "Not Found" : "Sitemap temporarily unavailable";
96
+ }
97
+ function sitemapHeaders(o) {
98
+ const type = {
99
+ name: "Content-Type",
100
+ value: o === "ok" ? "application/xml; charset=utf-8" : "text/plain; charset=utf-8"
101
+ };
102
+ const cache = { name: "Cache-Control", value: sitemapCacheControl(o) };
103
+ const retry = { name: "Retry-After", value: sitemapRetryAfter(o) };
104
+ return o === "unavailable" ? [type, cache, retry] : [type, cache];
105
+ }
106
+ function sitemapBase(base) {
107
+ const lead = base.length > 0 && base.charCodeAt(0) === 47 ? base : "/" + base;
108
+ return lead.charCodeAt(lead.length - 1) === 47 ? lead : lead + "/";
109
+ }
110
+ function itemsPrefix(siteUrl, base) {
111
+ return rStripCode(siteUrl, 47) + sitemapBase(base);
112
+ }
113
+ function itemSitemapUrl(siteUrl, base, n) {
114
+ return itemsPrefix(siteUrl, base) + "sitemap-" + decimal(n) + ".xml";
115
+ }
116
+ function inScope(prefix, loc) {
117
+ return startsWithAt(loc, prefix, 0);
118
+ }
119
+ function indexBlocksRange(siteUrl, base, lo, hi) {
120
+ if (hi - lo === 0) return "";
121
+ if (hi - lo === 1) return sitemapBlock(itemSitemapUrl(siteUrl, base, lo + 1));
122
+ const mid = lo + Math.floor((hi - lo) / 2);
123
+ return indexBlocksRange(siteUrl, base, lo, mid) + indexBlocksRange(siteUrl, base, mid, hi);
124
+ }
125
+ function buildSitemapIndexXml(siteUrl, base, count) {
126
+ return sitemapIndexHead() + indexBlocksRange(siteUrl, base, 0, count) + sitemapIndexTail();
127
+ }
128
+ function urlBlocksRange(rows, prefix, lo, hi) {
129
+ if (hi - lo === 0) return "";
130
+ if (hi - lo === 1) {
131
+ const row = rows[lo];
132
+ return inScope(prefix, row.loc) ? urlBlock(row.loc, row.lastmod) : "";
133
+ }
134
+ const mid = lo + Math.floor((hi - lo) / 2);
135
+ return urlBlocksRange(rows, prefix, lo, mid) + urlBlocksRange(rows, prefix, mid, hi);
136
+ }
137
+ function buildUrlsetXml(rows, siteUrl, base) {
138
+ return urlsetHead() + urlBlocksRange(rows, itemsPrefix(siteUrl, base), 0, rows.length) + urlsetTail();
139
+ }
140
+ function rewriteSource(base) {
141
+ return substitutedText(
142
+ sitemapBase(base),
143
+ [40, 41, 123, 125, 91, 93, 124, 92, 94, 46, 58, 42, 43, 45, 63, 36],
144
+ [
145
+ "\\(",
146
+ "\\)",
147
+ "\\{",
148
+ "\\}",
149
+ "\\[",
150
+ "\\]",
151
+ "\\|",
152
+ "\\\\",
153
+ "\\^",
154
+ "\\.",
155
+ "\\:",
156
+ "\\*",
157
+ "\\+",
158
+ "\\-",
159
+ "\\?",
160
+ "\\$"
161
+ ]
162
+ ) + "sitemap\\-:page\\.xml";
163
+ }
164
+ function rewriteDestination(base) {
165
+ return sitemapBase(base) + "sitemap.xml/:page";
166
+ }
167
+ function isSitemapPath(pathname, base) {
168
+ return startsWithAt(pathname, sitemapBase(base) + "sitemap", 0) && endsWith(pathname, ".xml");
169
+ }
170
+ function robotsSitemaps(siteUrl, base) {
171
+ return [rStripCode(siteUrl, 47) + "/sitemap.xml", itemsPrefix(siteUrl, base) + "sitemap.xml"];
172
+ }
173
+
174
+ // src/sitemap.ts
175
+ var DEFAULT_SITEMAP_BASE = "/items/";
176
+ var DEFAULT_SITEMAP_DEADLINE = 1e4;
177
+ var EDGE_CACHE_HOURS = 1;
178
+ function respond(outcome, xml) {
179
+ const headers = new Headers(
180
+ sitemapHeaders(outcome).map((h) => [h.name, h.value])
181
+ );
182
+ return new Response(sitemapBody(outcome, xml), { status: sitemapStatus(outcome), headers });
183
+ }
184
+ async function readTotal(site, deadline) {
185
+ try {
186
+ const response = await site.client.withRequest({ deadline }).googMc.sitemaps.items.list({ limit: 1, edgeCache: EDGE_CACHE_HOURS });
187
+ return usableTotal(Number.isInteger(response.total), response.total);
188
+ } catch {
189
+ return void 0;
190
+ }
191
+ }
192
+ async function readPage(site, page, deadline) {
193
+ try {
194
+ const response = await site.client.withRequest({ deadline }).googMc.sitemaps.items.list({ page, edgeCache: EDGE_CACHE_HOURS });
195
+ return (response.data ?? []).map((row) => ({
196
+ loc: row.link ?? "",
197
+ lastmod: row.lastModified ?? ""
198
+ }));
199
+ } catch {
200
+ return void 0;
201
+ }
202
+ }
203
+ function createSitemapIndexHandler(site, options) {
204
+ const { siteUrl, base = DEFAULT_SITEMAP_BASE, deadline = DEFAULT_SITEMAP_DEADLINE } = options;
205
+ return async () => {
206
+ const total = await readTotal(site, deadline);
207
+ const count = itemSitemapCount(total ?? 0);
208
+ return respond(
209
+ sitemapIndexOutcome(total !== void 0),
210
+ buildSitemapIndexXml(siteUrl, base, count)
211
+ );
212
+ };
213
+ }
214
+ function createItemSitemapHandler(site, options) {
215
+ const { siteUrl, base = DEFAULT_SITEMAP_BASE, deadline = DEFAULT_SITEMAP_DEADLINE } = options;
216
+ return async (_request, context) => {
217
+ const page = parseItemSitemapPage((await context.params).page);
218
+ const rows = fetchesPage(page) ? await readPage(site, page, deadline) : [];
219
+ const outcome = itemSitemapOutcome(page, rows !== void 0, rows?.length ?? 0);
220
+ return respond(outcome, buildUrlsetXml(rows ?? [], siteUrl, base));
221
+ };
222
+ }
223
+ function sitemapRewrite(base = DEFAULT_SITEMAP_BASE) {
224
+ return { source: rewriteSource(base), destination: rewriteDestination(base) };
225
+ }
226
+ export {
227
+ DEFAULT_SITEMAP_BASE,
228
+ DEFAULT_SITEMAP_DEADLINE,
229
+ buildSitemapIndexXml,
230
+ buildUrlsetXml,
231
+ createItemSitemapHandler,
232
+ createSitemapIndexHandler,
233
+ inScope,
234
+ isSitemapPath,
235
+ itemSitemapCount,
236
+ itemSitemapUrl,
237
+ parseItemSitemapPage,
238
+ robotsSitemaps,
239
+ sitemapBase,
240
+ sitemapRewrite
241
+ };
242
+ //# sourceMappingURL=sitemap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../utils/src/replace.ts","../../utils/src/xml.ts","../../utils/src/sitemap.ts","../src/sitemap-rules.ts","../src/sitemap.ts"],"sourcesContent":["//@ backend dafny\nimport { codeAt, indexOfFrom } from \"./strings\";\n\n/* Whole-string rewrites, verified with LemmaScript → Dafny (model: models/Utils.dfy \"text\n replacement\"; link: models/links/utils-replace.dfy). Each has a recursive spec (for\n proofs and tests) and a loop proved to build exactly it (for callers: its depth doesn't\n grow with the input). The `\\result === spec(s)` clause of each loop is a hand `ensures`\n in replace.dfy, as utils `escapeHtml`'s is: lsc would put it in every importer's axiom,\n where this file's own spec isn't emitted. */\n\n// --- One substitution rule (model `Utils.Substituted`, 2026-11-03): each code unit found in a\n// table is replaced by its text, every other kept. replaceCode, pointerToken, escapeHtml and\n// the generator's look-alike fold are this rule, each with its own table.\n\n/**\n * The first index ≥ `i` holding `c` in `codes`, or -1.\n *\n * @ensures result = -1 ∨ (i ≤ result < |codes| ∧ codes[result] = c) — the model's CodeIndex\n */\nexport function codeIndex(codes: number[], c: number, i: number): number {\n //@ verify\n //@ type i nat\n //@ requires i <= codes.length\n //@ decreases codes.length - i\n //@ ensures \\result === -1 || (i <= \\result && \\result < codes.length && codes[\\result] === c)\n // `===`, not `>=`: past the end codes[i] is undefined, never c, so `>=` vs `>` is equivalent\n if (i === codes.length) return -1;\n return (codes[i] as number) === c ? i : codeIndex(codes, c, i + 1);\n}\n\n/** `s` with each code unit in `codes` replaced by its text, recursively: the spec `substitute` builds. */\nexport function substitutedText(s: string, codes: number[], texts: string[]): string {\n //@ verify\n //@ decreases s.length\n //@ ensures s.length === 0 ==> \\result === \"\"\n //@ ensures codes.length === 0 ==> \\result === s\n if (s.length === 0) return \"\";\n const k = codeIndex(codes, s.charCodeAt(0), 0);\n const head = k >= 0 && k < texts.length ? (texts[k] as string) : s.slice(0, 1);\n return head + substitutedText(s.slice(1), codes, texts);\n}\n\n/**\n * `s` with each code unit in `codes` replaced by the text at its first index there, every\n * other kept. A loop, so its depth doesn't grow with the input.\n *\n * @ensures result = substitutedText(s, codes, texts) — the model's Substituted (a hand\n * ensures in replace.dfy: importers can't resolve substitutedText)\n * @ensures |s| = 0 ⟹ result = \"\" ∧ |codes| = 0 ⟹ result = s — no table, no change\n */\nexport function substitute(s: string, codes: number[], texts: string[]): string {\n //@ verify\n //@ ensures s.length === 0 ==> \\result === \"\"\n //@ ensures codes.length === 0 ==> \\result === s\n let out = \"\";\n // `!==`, not `<`: one step past the end reads NaN and adds \"\", so `<=` would be equivalent\n for (let i = 0; i !== s.length; i++) {\n //@ invariant 0 <= i && i <= s.length\n //@ invariant out + substitutedText(s.slice(i), codes, texts) === substitutedText(s, codes, texts)\n //@ decreases s.length - i\n const k = codeIndex(codes, s.charCodeAt(i), 0);\n out = k >= 0 && k < texts.length ? out + (texts[k] as string) : out + s.slice(i, i + 1);\n }\n return out;\n}\n\n/**\n * `s` with every `from` code unit replaced by `to`, recursively: the one-entry table.\n *\n * @ensures no `from` survives when `to` holds none — exactly the model's ReplaceCode in the link\n */\nexport function replacedCode(s: string, from: number, to: string): string {\n //@ verify\n //@ ensures forall(j: nat, j < to.length ==> to.charCodeAt(j) !== from) ==> forall(k: nat, k < \\result.length ==> \\result.charCodeAt(k) !== from)\n return substitutedText(s, [from], [to]);\n}\n\n/**\n * `s` with every `from` code unit replaced by `to` (`replaceAll` of one character).\n *\n * @ensures no `from` survives when `to` holds none (ReplaceCodeRemoves) — = replacedCode(s,\n * from, to), the model's ReplaceCode, as a hand ensures in replace.dfy\n */\nexport function replaceCode(s: string, from: number, to: string): string {\n //@ verify\n //@ ensures forall(j: nat, j < to.length ==> to.charCodeAt(j) !== from) ==> forall(k: nat, k < \\result.length ==> \\result.charCodeAt(k) !== from)\n return substitute(s, [from], [to]);\n}\n\n/**\n * `s` with its first `find` replaced by `put`; no match leaves it: JS `s.replace(find, put)` for\n * a string `find`, when `put` holds no `$` (JS reads `$&`, `$1` there as a pattern).\n *\n * @ensures exactly the model's ReplaceFirst\n */\nexport function replaceFirst(s: string, find: string, put: string): string {\n //@ verify\n //@ ensures \\result === (indexOfFrom(s, find, 0) < 0 ? s : s.slice(0, indexOfFrom(s, find, 0)) + put + s.slice(indexOfFrom(s, find, 0) + find.length))\n const i = indexOfFrom(s, find, 0);\n if (i < 0) return s;\n return s.slice(0, i) + put + s.slice(i + find.length);\n}\n\n/**\n * `s` with every `find` replaced by `put`, left to right without overlaps: JS\n * `s.split(find).join(put)` for a non-empty `find` (tests pin the two). Recursive, with no\n * loop twin: its callers fill short templates (the SDK's registry paths), so the depth stays\n * small; a long-input caller would need one.\n *\n * @requires |find| > 0 — split(\"\") splits into characters, a different rule\n * @ensures text shorter than `find` is unchanged, and so is any text when `put` = `find` —\n * exactly the model's ReplaceText in the link\n */\nexport function replaceText(s: string, find: string, put: string): string {\n //@ verify\n //@ requires find.length > 0\n //@ decreases s.length\n //@ ensures s.length < find.length ==> \\result === s\n //@ ensures put === find ==> \\result === s\n if (s.length < find.length) return s;\n if (s.slice(0, find.length) === find) {\n return put + replaceText(s.slice(find.length), find, put);\n }\n return s.slice(0, 1) + replaceText(s.slice(1), find, put);\n}\n\n/**\n * A JSON Pointer token of `s`, recursively: `~` → `~0`, `/` → `~1`.\n *\n * @ensures never holds \"/\" — exactly the model's PointerToken in the link\n */\nexport function pointerTokenOf(s: string): string {\n //@ verify\n //@ ensures forall(k: nat, k < \\result.length ==> \\result.charCodeAt(k) !== 47)\n return substitutedText(s, [126, 47], [\"~0\", \"~1\"]);\n}\n\n/**\n * `s` as a JSON Pointer reference token (RFC 6901 §3): `~` as `~0`, `/` as `~1`.\n *\n * @ensures never holds \"/\" (PointerTokenHasNoSlash) — = pointerTokenOf(s), the model's\n * PointerToken, as a hand ensures in replace.dfy\n */\nexport function pointerToken(s: string): string {\n //@ verify\n //@ ensures forall(k: nat, k < \\result.length ==> \\result.charCodeAt(k) !== 47)\n return substitute(s, [126, 47], [\"~0\", \"~1\"]);\n}\n\n/**\n * The escape of `s`, recursively: each `&` `<` `>` `\"` `'` as its entity.\n *\n * @ensures no `<` `>` `\"` `'` in result — exactly the model's EscapeHtml in the link\n */\nexport function escapedText(s: string): string {\n //@ verify\n //@ ensures forall(k: nat, k < \\result.length ==> (\\result.charCodeAt(k) !== 60 && \\result.charCodeAt(k) !== 62 && \\result.charCodeAt(k) !== 34 && \\result.charCodeAt(k) !== 39))\n return substitutedText(s, [38, 60, 62, 34, 39], [\"&amp;\", \"&lt;\", \"&gt;\", \"&quot;\", \"&#39;\"]);\n}\n\n/**\n * Escape text for an HTML body or a double-quoted attribute.\n *\n * @ensures result = escapedText(value) — exactly the model's EscapeHtml (a hand ensures in\n * replace.dfy, since importers can't see escapedText)\n * @ensures ∀ k < |result|. result[k] ∉ {\"<\", \">\", \"\\\"\", \"'\"} — nothing in the output can\n * open a tag or close the attribute; \"&\" appears only as the start of an entity\n */\nexport function escapeHtml(value: string): string {\n //@ verify\n //@ ensures forall(k: nat, k < \\result.length ==> (\\result.charCodeAt(k) !== 60 && \\result.charCodeAt(k) !== 62 && \\result.charCodeAt(k) !== 34 && \\result.charCodeAt(k) !== 39))\n return substitute(value, [38, 60, 62, 34, 39], [\"&amp;\", \"&lt;\", \"&gt;\", \"&quot;\", \"&#39;\"]);\n}\n\n/**\n * The code units a JSON string escapes: `\"`, `\\`, then the control characters with short\n * escapes (\\b \\t \\n \\f \\r), then the other code units below 0x20.\n *\n * @ensures exactly the model's JsonCodes\n */\nexport function jsonCodes(): number[] {\n //@ verify\n //@ ensures \\result === [34, 92, 8, 9, 10, 12, 13, 0, 1, 2, 3, 4, 5, 6, 7, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]\n return [\n 34, 92, 8, 9, 10, 12, 13, 0, 1, 2, 3, 4, 5, 6, 7, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,\n 24, 25, 26, 27, 28, 29, 30, 31,\n ];\n}\n\n/**\n * Each `jsonCodes` entry's escape (ECMA-262 QuoteJSONString; lowercase hex, as JSON.stringify).\n *\n * @ensures exactly the model's JsonTexts\n */\nexport function jsonTexts(): string[] {\n //@ verify\n //@ ensures \\result === [\"\\\\\\\"\", \"\\\\\\\\\", \"\\\\b\", \"\\\\t\", \"\\\\n\", \"\\\\f\", \"\\\\r\", \"\\\\u0000\", \"\\\\u0001\", \"\\\\u0002\", \"\\\\u0003\", \"\\\\u0004\", \"\\\\u0005\", \"\\\\u0006\", \"\\\\u0007\", \"\\\\u000b\", \"\\\\u000e\", \"\\\\u000f\", \"\\\\u0010\", \"\\\\u0011\", \"\\\\u0012\", \"\\\\u0013\", \"\\\\u0014\", \"\\\\u0015\", \"\\\\u0016\", \"\\\\u0017\", \"\\\\u0018\", \"\\\\u0019\", \"\\\\u001a\", \"\\\\u001b\", \"\\\\u001c\", \"\\\\u001d\", \"\\\\u001e\", \"\\\\u001f\"]\n return [\n '\\\\\"',\n \"\\\\\\\\\",\n \"\\\\b\",\n \"\\\\t\",\n \"\\\\n\",\n \"\\\\f\",\n \"\\\\r\",\n \"\\\\u0000\",\n \"\\\\u0001\",\n \"\\\\u0002\",\n \"\\\\u0003\",\n \"\\\\u0004\",\n \"\\\\u0005\",\n \"\\\\u0006\",\n \"\\\\u0007\",\n \"\\\\u000b\",\n \"\\\\u000e\",\n \"\\\\u000f\",\n \"\\\\u0010\",\n \"\\\\u0011\",\n \"\\\\u0012\",\n \"\\\\u0013\",\n \"\\\\u0014\",\n \"\\\\u0015\",\n \"\\\\u0016\",\n \"\\\\u0017\",\n \"\\\\u0018\",\n \"\\\\u0019\",\n \"\\\\u001a\",\n \"\\\\u001b\",\n \"\\\\u001c\",\n \"\\\\u001d\",\n \"\\\\u001e\",\n \"\\\\u001f\",\n ];\n}\n\n/**\n * A string as JSON text, as `JSON.stringify(s)` writes it for well-formed text: quoted, `\"`\n * and `\\` backslashed, control characters escaped. A lone surrogate is kept as it is\n * (JSON.stringify writes `\\udxxx`); callers pass well-formed text. Built by the `substitute`\n * loop, so its depth doesn't grow with the text (an FAQ answer can be long; Fable review\n * 2026-11-06); importers still see a function (its contract as an axiom), so their premise\n * `jsonString(s) == Utils.JsonString(s)` stands.\n *\n * @ensures result = `\"` + substitutedText(s, jsonCodes(), jsonTexts()) + `\"` — a hand ensures in\n * replace.dfy; the model's JsonString (proved in links/utils-replace.dfy)\n * @ensures result starts and ends with `\"`\n */\nexport function jsonString(s: string): string {\n //@ verify\n //@ ensures \\result.length >= 2 && \\result.charCodeAt(0) === 34 && \\result.charCodeAt(\\result.length - 1) === 34\n return '\"' + substitute(s, jsonCodes(), jsonTexts()) + '\"';\n}\n\n/**\n * `s` with every `*` `/` pair written `* /`, recursively: the spec `commentSafe` builds.\n *\n * @ensures no \"*\" \"/\" pair in result — exactly the model's CommentSafe in the link\n */\nexport function commentSafeOf(s: string): string {\n //@ verify\n //@ decreases s.length\n //@ ensures forall(k: nat, k + 1 < \\result.length ==> !(\\result.charCodeAt(k) === 42 && \\result.charCodeAt(k + 1) === 47))\n if (s.length === 0) return \"\";\n if (codeAt(s, 0) === 42 && codeAt(s, 1) === 47) {\n return \"* /\" + commentSafeOf(s.slice(2));\n }\n return s.slice(0, 1) + commentSafeOf(s.slice(1));\n}\n\n/**\n * Text safe inside a `/* … *\\/` comment: every `*` `/` pair written `* /`.\n *\n * @ensures no \"*\" \"/\" pair in result: nothing can close the comment — = commentSafeOf(s), the\n * model's CommentSafe, as a hand ensures in replace.dfy\n */\nexport function commentSafe(s: string): string {\n //@ verify\n //@ ensures forall(k: nat, k + 1 < \\result.length ==> !(\\result.charCodeAt(k) === 42 && \\result.charCodeAt(k + 1) === 47))\n let out = \"\";\n let i = 0;\n while (i !== s.length) {\n //@ invariant 0 <= i && i <= s.length\n //@ invariant out + commentSafeOf(s.slice(i)) === commentSafeOf(s)\n //@ decreases s.length - i\n if (codeAt(s, i) === 42 && codeAt(s, i + 1) === 47) {\n out = out + \"* /\";\n i = i + 2;\n } else {\n out = out + s.slice(i, i + 1);\n i = i + 1;\n }\n }\n return out;\n}\n","//@ backend dafny\n\n/* XML text escaping, verified with LemmaScript → Dafny (model: models/Sitemap.dfy XmlEscape;\n link: models/links/utils-xml.dfy). The sitemap protocol's list, exactly (sitemaps.org\n \"Entity escaping\", atlas#101): `&` `'` `\"` `>` `<` as `&amp;` `&apos;` `&quot;` `&gt;` `&lt;`.\n Recursive, so proved text builders (utils `sitemap`) can call it inside an expression; its\n depth is the text's length (a URL, at most 2,048 characters by the protocol). */\n\n/**\n * The entity the sitemap protocol writes for code unit `c`, or \"\" when `c` is written as itself.\n *\n * @ensures exactly the model's XmlEntity\n */\nexport function xmlEntity(c: number): string {\n //@ verify\n //@ ensures \\result === (c === 38 ? \"&amp;\" : c === 60 ? \"&lt;\" : c === 62 ? \"&gt;\" : c === 34 ? \"&quot;\" : c === 39 ? \"&apos;\" : \"\")\n if (c === 38) return \"&amp;\";\n if (c === 60) return \"&lt;\";\n if (c === 62) return \"&gt;\";\n if (c === 34) return \"&quot;\";\n if (c === 39) return \"&apos;\";\n return \"\";\n}\n\n/**\n * `s` escaped for XML text or a quoted attribute: each of `&` `<` `>` `\"` `'` as its entity,\n * every other code unit kept.\n *\n * @ensures ∀ k < |result|. result[k] ∉ {\"<\", \">\", \"\\\"\", \"'\"} — nothing can end an element or a\n * quoted value; exactly the model's XmlEscape in the link (a recursive contract can't be\n * imported, models/LSC-GAPS.md)\n */\nexport function xmlEscaped(s: string): string {\n //@ verify\n //@ decreases s.length\n //@ ensures forall(k: nat, k < \\result.length ==> (\\result.charCodeAt(k) !== 60 && \\result.charCodeAt(k) !== 62 && \\result.charCodeAt(k) !== 34 && \\result.charCodeAt(k) !== 39))\n if (s.length === 0) return \"\";\n const entity = xmlEntity(s.charCodeAt(0));\n return (entity === \"\" ? s.slice(0, 1) : entity) + xmlEscaped(s.slice(1));\n}\n","//@ backend dafny\nimport { lineFeed } from \"./strings\";\nimport { xmlEscaped } from \"./xml\";\n\n/* The sitemap protocol's XML (sitemaps.org; atlas#101), built once for every site, verified with\n LemmaScript → Dafny (model: models/Sitemap.dfy; link: models/links/utils-sitemap.dfy). A\n caller writes a head, its blocks and the tail: a `<urlset>` of `urlBlock`s, or a\n `<sitemapindex>` of `sitemapBlock`s. Each element sits on its own line, indented two spaces per\n level (owner 2026-11-10: \"properly formatted\"), and each value is escaped with `xmlEscaped`.\n\n The contracts here are true but not exact: an exact one names `xmlEscaped` or `lineFeed`, which\n an importer that doesn't call them itself can't resolve (models/LSC-GAPS.md). The link proves\n each function is the model's, and importers' links take that as a premise. */\n\n/**\n * A `<urlset>` file's opening: the XML declaration, then the root element.\n *\n * @ensures starts with the XML declaration — exactly the model's UrlsetHead in the link\n */\nexport function urlsetHead(): string {\n //@ verify\n //@ ensures \\result.length > 38 && \\result.slice(0, 38) === '<?xml version=\"1.0\" encoding=\"UTF-8\"?>'\n return (\n '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +\n lineFeed() +\n '<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">' +\n lineFeed()\n );\n}\n\n/**\n * A `<urlset>` file's closing tag and final line feed.\n *\n * @ensures |result| = 10 ∧ starts with \"</urlset>\" — exactly the model's UrlsetTail in the link\n */\nexport function urlsetTail(): string {\n //@ verify\n //@ ensures \\result.length === 10 && \\result.slice(0, 9) === \"</urlset>\"\n return \"</urlset>\" + lineFeed();\n}\n\n/**\n * A `<sitemapindex>` file's opening: the XML declaration, then the root element.\n *\n * @ensures starts with the XML declaration — exactly the model's IndexHead in the link\n */\nexport function sitemapIndexHead(): string {\n //@ verify\n //@ ensures \\result.length > 38 && \\result.slice(0, 38) === '<?xml version=\"1.0\" encoding=\"UTF-8\"?>'\n return (\n '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +\n lineFeed() +\n '<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">' +\n lineFeed()\n );\n}\n\n/**\n * A `<sitemapindex>` file's closing tag and final line feed.\n *\n * @ensures |result| = 16 ∧ starts with \"</sitemapindex>\" — exactly the model's IndexTail in the link\n */\nexport function sitemapIndexTail(): string {\n //@ verify\n //@ ensures \\result.length === 16 && \\result.slice(0, 15) === \"</sitemapindex>\"\n return \"</sitemapindex>\" + lineFeed();\n}\n\n/**\n * One page of a `<urlset>`: its `<loc>`, and its `<lastmod>` only when known (\"\" leaves it out),\n * each escaped and on its own line.\n *\n * @ensures starts with \" <url>\" — exactly the model's UrlBlock in the link\n */\nexport function urlBlock(loc: string, lastmod: string): string {\n //@ verify\n //@ ensures \\result.length > 7 && \\result.slice(0, 7) === \" <url>\"\n const date =\n lastmod === \"\" ? \"\" : \" <lastmod>\" + xmlEscaped(lastmod) + \"</lastmod>\" + lineFeed();\n return (\n \" <url>\" +\n lineFeed() +\n \" <loc>\" +\n xmlEscaped(loc) +\n \"</loc>\" +\n lineFeed() +\n date +\n \" </url>\" +\n lineFeed()\n );\n}\n\n/**\n * One child sitemap of a `<sitemapindex>`: its `<loc>`, escaped, on its own line.\n *\n * @ensures starts with \" <sitemap>\" — exactly the model's SitemapBlock in the link\n */\nexport function sitemapBlock(loc: string): string {\n //@ verify\n //@ ensures \\result.length > 11 && \\result.slice(0, 11) === \" <sitemap>\"\n return (\n \" <sitemap>\" +\n lineFeed() +\n \" <loc>\" +\n xmlEscaped(loc) +\n \"</loc>\" +\n lineFeed() +\n \" </sitemap>\" +\n lineFeed()\n );\n}\n","//@ backend dafny\nimport { decimal } from \"@atlas/foundation/decimal\";\nimport { substitutedText } from \"@atlas/utils/replace\";\nimport {\n sitemapBlock,\n sitemapIndexHead,\n sitemapIndexTail,\n urlBlock,\n urlsetHead,\n urlsetTail,\n} from \"@atlas/utils/sitemap\";\nimport {\n canonicalNatValue,\n endsWith,\n isCanonicalNat,\n rStripCode,\n startsWithAt,\n} from \"@atlas/utils/strings\";\n\n/* The item sitemaps' decisions (atlas#101), verified with LemmaScript → Dafny and linked to\n models/AugurServerSitemap.dfy (models/links/augur-server-sitemap-rules.dfy). `sitemap.ts` only\n awaits the SDK and maps these answers to a Response.\n\n Layout (owner 2026-11-10): the item index at `{base}sitemap.xml` and page n at\n `{base}sitemap-{n}.xml`, all in the items' own folder `base` (default \"/items/\"), so by the\n sitemap protocol's location rule they may list the item pages there. */\n\n/** One item for a `<urlset>`: its page URL and, when known, its last change (\"\" leaves it out). */\nexport interface SitemapRow {\n loc: string;\n lastmod: string;\n}\n\n/** What a sitemap request comes to: served, not a sitemap (404), or Augur failed (503). */\nexport type SitemapOutcome = \"ok\" | \"not-found\" | \"unavailable\";\n\n// ---------------------------------------------------------------- pages\n\n/**\n * The SDK's `total` as a count: itself when a whole number ≥ 0, else 0 (no item sitemaps rather\n * than a guess).\n *\n * @ensures exactly the model's UsableTotal\n */\nexport function usableTotal(isWhole: boolean, n: number): number {\n //@ verify\n //@ ensures \\result === (isWhole && n >= 0 ? n : 0)\n return isWhole && n >= 0 ? n : 0;\n}\n\n/**\n * How many 5,000-item sitemaps cover `total` items (the endpoint fixes a page at 5,000).\n *\n * @requires total ≥ 0\n * @ensures result = ⌈total / 5000⌉ — exactly the model's ItemSitemapCount\n */\nexport function itemSitemapCount(total: number): number {\n //@ verify\n //@ type total nat\n //@ requires total >= 0\n //@ ensures \\result === Math.floor((total + 4999) / 5000)\n return Math.floor((total + 4999) / 5000);\n}\n\n/**\n * The page a request names (the rewrite's bare `:page`): its value when it is a canonical\n * natural number, else 0, \"not a page\" (`0`, `01`, `1e3`, ` 1`, `-1` and text never name one).\n *\n * @ensures result = canonicalNatValue(page) for canonical text, else 0 — exactly the model's\n * ItemSitemapPage (the test is spelled out: canonicalNatValue's contract names\n * isCanonicalNat, which this file must call to resolve, models/LSC-GAPS.md)\n */\nexport function parseItemSitemapPage(page: string): number {\n //@ verify\n //@ ensures \\result === (isCanonicalNat(page) ? canonicalNatValue(page) : 0)\n return isCanonicalNat(page) ? canonicalNatValue(page) : 0;\n}\n\n// ---------------------------------------------------------------- outcomes\n\n/**\n * An item page's outcome: not a page, or an empty page past the first, is \"not-found\"; a failed\n * fetch is \"unavailable\"; anything else is served. `rows` counts what the endpoint returned,\n * before the scope filter.\n *\n * @ensures exactly the model's ItemOutcome\n */\nexport function itemSitemapOutcome(page: number, fetched: boolean, rows: number): SitemapOutcome {\n //@ verify\n //@ ensures page === 0 ==> \\result === \"not-found\"\n //@ ensures page !== 0 && !fetched ==> \\result === \"unavailable\"\n //@ ensures page !== 0 && fetched && rows === 0 && page > 1 ==> \\result === \"not-found\"\n //@ ensures page !== 0 && fetched && !(rows === 0 && page > 1) ==> \\result === \"ok\"\n if (page === 0) return \"not-found\";\n if (!fetched) return \"unavailable\";\n if (rows === 0 && page > 1) return \"not-found\";\n return \"ok\";\n}\n\n/**\n * The item index's outcome: served when the count was read, else \"unavailable\" (a 200 with no\n * sitemaps would tell a crawler the site has none).\n *\n * @ensures exactly the model's IndexOutcome\n */\nexport function sitemapIndexOutcome(fetched: boolean): SitemapOutcome {\n //@ verify\n //@ ensures \\result === (fetched ? \"ok\" : \"unavailable\")\n return fetched ? \"ok\" : \"unavailable\";\n}\n\n/**\n * The HTTP status of an outcome.\n *\n * @ensures exactly the model's StatusOf\n */\nexport function sitemapStatus(o: SitemapOutcome): number {\n //@ verify\n //@ ensures \\result === (o === \"ok\" ? 200 : o === \"not-found\" ? 404 : 503)\n if (o === \"ok\") return 200;\n return o === \"not-found\" ? 404 : 503;\n}\n\n/**\n * An outcome's `Cache-Control`: a served sitemap for a day at the CDN and an hour in browsers\n * (rebuilt at most daily); a 404 or a 503 never.\n *\n * @ensures exactly the model's CacheControlOf\n */\nexport function sitemapCacheControl(o: SitemapOutcome): string {\n //@ verify\n //@ ensures \\result === (o === \"ok\" ? \"public, max-age=3600, s-maxage=86400\" : \"no-store\")\n return o === \"ok\" ? \"public, max-age=3600, s-maxage=86400\" : \"no-store\";\n}\n\n/**\n * An outcome's `Retry-After` in seconds: an hour for a 503, else \"\" (no header).\n *\n * @ensures exactly the model's RetryAfterOf\n */\nexport function sitemapRetryAfter(o: SitemapOutcome): string {\n //@ verify\n //@ ensures \\result === (o === \"unavailable\" ? \"3600\" : \"\")\n return o === \"unavailable\" ? \"3600\" : \"\";\n}\n\n/**\n * Whether a request's page is worth asking Augur for: only a page (≥ 1); \"not a page\" is\n * answered without a call.\n *\n * @ensures exactly the model's FetchesPage\n */\nexport function fetchesPage(page: number): boolean {\n //@ verify\n //@ ensures \\result === (page >= 1)\n return page >= 1;\n}\n\n/**\n * A response's body: the XML when served, else a short plain-text reason.\n *\n * @ensures exactly the model's BodyOf\n */\nexport function sitemapBody(o: SitemapOutcome, xml: string): string {\n //@ verify\n //@ ensures \\result === (o === \"ok\" ? xml : o === \"not-found\" ? \"Not Found\" : \"Sitemap temporarily unavailable\")\n if (o === \"ok\") return xml;\n return o === \"not-found\" ? \"Not Found\" : \"Sitemap temporarily unavailable\";\n}\n\n/** One response header. */\nexport interface SitemapHeader {\n name: string;\n value: string;\n}\n\n/**\n * A response's headers: its type, its cache rule, and `Retry-After` on a 503 only.\n *\n * @ensures exactly the model's HeadersOf\n */\nexport function sitemapHeaders(o: SitemapOutcome): SitemapHeader[] {\n //@ verify\n //@ ensures \\result.length === (o === \"unavailable\" ? 3 : 2)\n const type: SitemapHeader = {\n name: \"Content-Type\",\n value: o === \"ok\" ? \"application/xml; charset=utf-8\" : \"text/plain; charset=utf-8\",\n };\n const cache: SitemapHeader = { name: \"Cache-Control\", value: sitemapCacheControl(o) };\n const retry: SitemapHeader = { name: \"Retry-After\", value: sitemapRetryAfter(o) };\n return o === \"unavailable\" ? [type, cache, retry] : [type, cache];\n}\n\n// ---------------------------------------------------------------- URLs\n\n/**\n * The items' folder as a path, with one leading and one trailing \"/\" (\"items\" → \"/items/\").\n *\n * @ensures exactly the model's SitemapBase\n */\nexport function sitemapBase(base: string): string {\n //@ verify\n //@ ensures \\result.length >= 1 && \\result.charCodeAt(0) === 47 && \\result.charCodeAt(\\result.length - 1) === 47\n const lead = base.length > 0 && base.charCodeAt(0) === 47 ? base : \"/\" + base;\n return lead.charCodeAt(lead.length - 1) === 47 ? lead : lead + \"/\";\n}\n\n/**\n * The folder every item sitemap, and every item it lists, sits in: the site's origin with no\n * trailing \"/\", then the base.\n *\n * @ensures result = rStripCode(siteUrl, \"/\") + sitemapBase(base) — exactly the model's ItemsPrefix\n */\nexport function itemsPrefix(siteUrl: string, base: string): string {\n //@ verify\n //@ ensures \\result === rStripCode(siteUrl, 47) + sitemapBase(base)\n return rStripCode(siteUrl, 47) + sitemapBase(base);\n}\n\n/**\n * Item sitemap n's URL: `{siteUrl}{base}sitemap-{n}.xml`.\n *\n * @ensures exactly the model's ItemSitemapUrl\n */\nexport function itemSitemapUrl(siteUrl: string, base: string, n: number): string {\n //@ verify\n //@ type n nat\n //@ requires n >= 0\n //@ ensures \\result === itemsPrefix(siteUrl, base) + \"sitemap-\" + decimal(n) + \".xml\"\n return itemsPrefix(siteUrl, base) + \"sitemap-\" + decimal(n) + \".xml\";\n}\n\n/**\n * Whether a link is under the items' folder (the location rule); an empty link never is.\n *\n * @ensures exactly the model's InScope\n */\nexport function inScope(prefix: string, loc: string): boolean {\n //@ verify\n //@ ensures \\result <==> (prefix.length <= loc.length && loc.slice(0, prefix.length) === prefix)\n return startsWithAt(loc, prefix, 0);\n}\n\n// ---------------------------------------------------------------- the two files\n\n/**\n * The index's `<sitemap>` blocks for pages lo+1 … hi, built by halves (depth log n).\n *\n * @ensures nothing for an empty range — exactly the model's blocks of ItemSitemapUrlsFrom in the link\n */\nfunction indexBlocksRange(siteUrl: string, base: string, lo: number, hi: number): string {\n //@ verify\n //@ type lo nat\n //@ type hi nat\n //@ requires 0 <= lo && lo <= hi\n //@ decreases hi - lo\n //@ ensures lo === hi ==> \\result === \"\"\n if (hi - lo === 0) return \"\";\n if (hi - lo === 1) return sitemapBlock(itemSitemapUrl(siteUrl, base, lo + 1));\n const mid = lo + Math.floor((hi - lo) / 2);\n return indexBlocksRange(siteUrl, base, lo, mid) + indexBlocksRange(siteUrl, base, mid, hi);\n}\n\n/**\n * The item index: a `<sitemapindex>` of `{base}sitemap-1.xml` … `{base}sitemap-{count}.xml`.\n *\n * @ensures exactly the model's ItemIndex\n */\nexport function buildSitemapIndexXml(siteUrl: string, base: string, count: number): string {\n //@ verify\n //@ type count nat\n //@ requires count >= 0\n //@ ensures \\result === sitemapIndexHead() + indexBlocksRange(siteUrl, base, 0, count) + sitemapIndexTail()\n return sitemapIndexHead() + indexBlocksRange(siteUrl, base, 0, count) + sitemapIndexTail();\n}\n\n/**\n * The `<url>` blocks for rows[lo..hi) under `prefix`, others left out, built by halves.\n *\n * @ensures nothing for an empty range — exactly the model's blocks of ScopedEntries in the link\n */\nfunction urlBlocksRange(rows: SitemapRow[], prefix: string, lo: number, hi: number): string {\n //@ verify\n //@ type lo nat\n //@ type hi nat\n //@ requires 0 <= lo && lo <= hi && hi <= rows.length\n //@ decreases hi - lo\n //@ ensures lo === hi ==> \\result === \"\"\n if (hi - lo === 0) return \"\";\n if (hi - lo === 1) {\n const row = rows[lo] as SitemapRow;\n return inScope(prefix, row.loc) ? urlBlock(row.loc, row.lastmod) : \"\";\n }\n const mid = lo + Math.floor((hi - lo) / 2);\n return urlBlocksRange(rows, prefix, lo, mid) + urlBlocksRange(rows, prefix, mid, hi);\n}\n\n/**\n * An item page: a `<urlset>` of the rows under the items' folder, in order.\n *\n * @ensures exactly the model's ItemUrlset\n */\nexport function buildUrlsetXml(rows: SitemapRow[], siteUrl: string, base: string): string {\n //@ verify\n //@ ensures \\result === urlsetHead() + urlBlocksRange(rows, itemsPrefix(siteUrl, base), 0, rows.length) + urlsetTail()\n return (\n urlsetHead() + urlBlocksRange(rows, itemsPrefix(siteUrl, base), 0, rows.length) + urlsetTail()\n );\n}\n\n// ---------------------------------------------------------------- Next.js and robots.txt\n\n/**\n * The Next.js rewrite `source` for the page files, `{base}sitemap-:page.xml`, with every\n * character Next reads as pattern syntax (`( ) { } [ ] | \\ ^ . : * + - ? $`) escaped by a \"\\\".\n *\n * @ensures exactly the model's RewriteSource\n */\nexport function rewriteSource(base: string): string {\n //@ verify\n //@ ensures \\result === substitutedText(sitemapBase(base), [40, 41, 123, 125, 91, 93, 124, 92, 94, 46, 58, 42, 43, 45, 63, 36], [\"\\\\(\", \"\\\\)\", \"\\\\{\", \"\\\\}\", \"\\\\[\", \"\\\\]\", \"\\\\|\", \"\\\\\\\\\", \"\\\\^\", \"\\\\.\", \"\\\\:\", \"\\\\*\", \"\\\\+\", \"\\\\-\", \"\\\\?\", \"\\\\$\"]) + \"sitemap\\\\-:page\\\\.xml\"\n return (\n substitutedText(\n sitemapBase(base),\n [40, 41, 123, 125, 91, 93, 124, 92, 94, 46, 58, 42, 43, 45, 63, 36],\n [\n \"\\\\(\",\n \"\\\\)\",\n \"\\\\{\",\n \"\\\\}\",\n \"\\\\[\",\n \"\\\\]\",\n \"\\\\|\",\n \"\\\\\\\\\",\n \"\\\\^\",\n \"\\\\.\",\n \"\\\\:\",\n \"\\\\*\",\n \"\\\\+\",\n \"\\\\-\",\n \"\\\\?\",\n \"\\\\$\",\n ],\n ) + \"sitemap\\\\-:page\\\\.xml\"\n );\n}\n\n/**\n * The rewrite's destination, the page handler's route `{base}sitemap.xml/:page`\n * (`app/<base>/sitemap.xml/[page]/route.ts`).\n *\n * @ensures exactly the model's RewriteDestination\n */\nexport function rewriteDestination(base: string): string {\n //@ verify\n //@ ensures \\result === sitemapBase(base) + \"sitemap.xml/:page\"\n return sitemapBase(base) + \"sitemap.xml/:page\";\n}\n\n/**\n * Whether a path is one of the item sitemaps (the index or a page file), which a site's proxy\n * MUST pass through before any item-URL redirect (the proxy runs before rewrites).\n *\n * @ensures exactly the model's IsSitemapPath\n */\nexport function isSitemapPath(pathname: string, base: string): boolean {\n //@ verify\n //@ ensures \\result === (startsWithAt(pathname, sitemapBase(base) + \"sitemap\", 0) && endsWith(pathname, \".xml\"))\n return startsWithAt(pathname, sitemapBase(base) + \"sitemap\", 0) && endsWith(pathname, \".xml\");\n}\n\n/**\n * robots.txt's sitemaps: the site's own root `/sitemap.xml` and the item index. Two lines, since\n * the specs name no index inside an index.\n *\n * @ensures exactly the model's RobotsSitemaps\n */\nexport function robotsSitemaps(siteUrl: string, base: string): string[] {\n //@ verify\n //@ ensures \\result.length === 2\n //@ ensures \\result[0] === rStripCode(siteUrl, 47) + \"/sitemap.xml\"\n //@ ensures \\result[1] === itemsPrefix(siteUrl, base) + \"sitemap.xml\"\n return [rStripCode(siteUrl, 47) + \"/sitemap.xml\", itemsPrefix(siteUrl, base) + \"sitemap.xml\"];\n}\n","/**\n * Item sitemaps for a Next.js site, built at request time from the Augur SDK's\n * `googMc.sitemaps.items.list` (atlas#101), so the number of files follows the catalog without a\n * deploy, whatever its size.\n *\n * Layout: the item index at `{base}sitemap.xml` and page n (5,000 items) at\n * `{base}sitemap-{n}.xml`, in the items' own folder (`base`, default \"/items/\"), so by the\n * sitemap protocol's location rule they may list the item pages there. The site's root\n * `/sitemap.xml` stays its own; robots.txt names both (`robotsSitemaps`).\n *\n * Every decision is a proved rule in `sitemap-rules.ts`; this file only awaits the SDK and maps\n * the rules' answers to a Response.\n */\n\nimport type { AugurAPI } from \"@simpleapps-com/augur-api\";\nimport {\n buildSitemapIndexXml,\n buildUrlsetXml,\n fetchesPage,\n itemSitemapCount,\n itemSitemapOutcome,\n parseItemSitemapPage,\n rewriteDestination,\n rewriteSource,\n sitemapBody,\n sitemapHeaders,\n sitemapIndexOutcome,\n sitemapStatus,\n usableTotal,\n type SitemapOutcome,\n type SitemapRow,\n} from \"./sitemap-rules\";\n\nexport {\n buildSitemapIndexXml,\n buildUrlsetXml,\n inScope,\n isSitemapPath,\n itemSitemapCount,\n itemSitemapUrl,\n parseItemSitemapPage,\n robotsSitemaps,\n sitemapBase,\n type SitemapOutcome,\n type SitemapRow,\n} from \"./sitemap-rules\";\n\n/** The items' folder when a site names none. */\nexport const DEFAULT_SITEMAP_BASE = \"/items/\";\n\n/**\n * How long one Augur call may take, in milliseconds: crawlers wait longer than page visitors, and\n * a call past it is a 503 the crawler retries.\n */\nexport const DEFAULT_SITEMAP_DEADLINE = 10_000;\n\n/** What the handlers need of a server site: its SDK client (`createServerSite`'s result fits). */\nexport interface SitemapSite {\n client: Pick<AugurAPI, \"withRequest\" | \"googMc\">;\n}\n\n/** Where the site lives and where its item sitemaps sit. */\nexport interface SitemapOptions {\n /** The site's origin, e.g. \"https://www.example.com\" (a trailing \"/\" is dropped). */\n siteUrl: string;\n /** The items' folder, matching the item links Augur returns; default \"/items/\". */\n base?: string;\n /** Milliseconds one Augur call may take; default 10,000. */\n deadline?: number;\n}\n\n/** A Next.js rewrite, as `next.config` `rewrites()` takes it. */\nexport interface SitemapRewrite {\n source: string;\n destination: string;\n}\n\n/** The Augur edge cache the reads ask for, in hours: a day's sitemap stays close to the catalog. */\nconst EDGE_CACHE_HOURS = 1;\n\nfunction respond(outcome: SitemapOutcome, xml: string): Response {\n const headers = new Headers(\n sitemapHeaders(outcome).map((h): [string, string] => [h.name, h.value]),\n );\n return new Response(sitemapBody(outcome, xml), { status: sitemapStatus(outcome), headers });\n}\n\n/** The catalog's total from a one-row read, or undefined when Augur failed. */\nasync function readTotal(site: SitemapSite, deadline: number): Promise<number | undefined> {\n try {\n const response = await site.client\n .withRequest({ deadline })\n .googMc.sitemaps.items.list({ limit: 1, edgeCache: EDGE_CACHE_HOURS });\n return usableTotal(Number.isInteger(response.total), response.total);\n } catch {\n return undefined;\n }\n}\n\n/** One page's rows, as the rules take them, or undefined when Augur failed. */\nasync function readPage(\n site: SitemapSite,\n page: number,\n deadline: number,\n): Promise<SitemapRow[] | undefined> {\n try {\n const response = await site.client\n .withRequest({ deadline })\n .googMc.sitemaps.items.list({ page, edgeCache: EDGE_CACHE_HOURS });\n return (response.data ?? []).map((row) => ({\n loc: row.link ?? \"\",\n lastmod: row.lastModified ?? \"\",\n }));\n } catch {\n return undefined;\n }\n}\n\n/**\n * The item index's Route Handler, for `app/items/sitemap.xml/route.ts` (or the folder `base`\n * names): a `<sitemapindex>` of every item page file, or a 503 when Augur can't be read.\n *\n * @example\n * ```ts\n * export const dynamic = \"force-dynamic\";\n * export const GET = createSitemapIndexHandler(site, { siteUrl: \"https://www.example.com\" });\n * ```\n */\nexport function createSitemapIndexHandler(site: SitemapSite, options: SitemapOptions) {\n const { siteUrl, base = DEFAULT_SITEMAP_BASE, deadline = DEFAULT_SITEMAP_DEADLINE } = options;\n return async (): Promise<Response> => {\n const total = await readTotal(site, deadline);\n const count = itemSitemapCount(total ?? 0);\n return respond(\n sitemapIndexOutcome(total !== undefined),\n buildSitemapIndexXml(siteUrl, base, count),\n );\n };\n}\n\n/**\n * An item page's Route Handler, for `app/items/sitemap.xml/[page]/route.ts`, which\n * `sitemapRewrite` maps `{base}sitemap-{n}.xml` onto: a `<urlset>` of page n's items under\n * `base`, a 404 for no such page, or a 503 when Augur can't be read.\n *\n * @example\n * ```ts\n * export const dynamic = \"force-dynamic\";\n * export const GET = createItemSitemapHandler(site, { siteUrl: \"https://www.example.com\" });\n * ```\n */\nexport function createItemSitemapHandler(site: SitemapSite, options: SitemapOptions) {\n const { siteUrl, base = DEFAULT_SITEMAP_BASE, deadline = DEFAULT_SITEMAP_DEADLINE } = options;\n return async (\n _request: Request,\n context: { params: Promise<{ page: string }> },\n ): Promise<Response> => {\n const page = parseItemSitemapPage((await context.params).page);\n const rows = fetchesPage(page) ? await readPage(site, page, deadline) : [];\n const outcome = itemSitemapOutcome(page, rows !== undefined, rows?.length ?? 0);\n return respond(outcome, buildUrlsetXml(rows ?? [], siteUrl, base));\n };\n}\n\n/**\n * The Next.js rewrite from `{base}sitemap-{n}.xml` to the item page handler's route; spread it\n * into `next.config`'s `rewrites()`.\n *\n * @example\n * ```ts\n * async rewrites() {\n * return [sitemapRewrite()];\n * }\n * ```\n */\nexport function sitemapRewrite(base: string = DEFAULT_SITEMAP_BASE): SitemapRewrite {\n return { source: rewriteSource(base), destination: rewriteDestination(base) };\n}\n"],"mappings":";;;;;;;;;;;;;AAmBO,SAAS,UAAU,OAAiB,GAAW,GAAmB;AAOvE,MAAI,MAAM,MAAM,OAAQ,QAAO;AAC/B,SAAQ,MAAM,CAAC,MAAiB,IAAI,IAAI,UAAU,OAAO,GAAG,IAAI,CAAC;AACnE;AAGO,SAAS,gBAAgB,GAAW,OAAiB,OAAyB;AAKnF,MAAI,EAAE,WAAW,EAAG,QAAO;AAC3B,QAAM,IAAI,UAAU,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC;AAC7C,QAAM,OAAO,KAAK,KAAK,IAAI,MAAM,SAAU,MAAM,CAAC,IAAe,EAAE,MAAM,GAAG,CAAC;AAC7E,SAAO,OAAO,gBAAgB,EAAE,MAAM,CAAC,GAAG,OAAO,KAAK;AACxD;;;AC3BO,SAAS,UAAU,GAAmB;AAG3C,MAAI,MAAM,GAAI,QAAO;AACrB,MAAI,MAAM,GAAI,QAAO;AACrB,MAAI,MAAM,GAAI,QAAO;AACrB,MAAI,MAAM,GAAI,QAAO;AACrB,MAAI,MAAM,GAAI,QAAO;AACrB,SAAO;AACT;AAUO,SAAS,WAAW,GAAmB;AAI5C,MAAI,EAAE,WAAW,EAAG,QAAO;AAC3B,QAAM,SAAS,UAAU,EAAE,WAAW,CAAC,CAAC;AACxC,UAAQ,WAAW,KAAK,EAAE,MAAM,GAAG,CAA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