@gb-npm/cms-worker-cf 0.1.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/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @gb-npm/cms-worker-cf
2
+
3
+ Cloudflare Worker adapters for [`@gb-npm/cms-sdk`](../cms-sdk). Thin response builders that turn CMS client calls into `Response` objects suitable for a Worker `fetch` handler.
4
+
5
+ ## Provided helpers
6
+
7
+ - `redirectMiddleware(cms, pathname, { baseUrl })` — resolves a path against `cms.redirects` and returns a `301 Response` (or `null` for no match).
8
+ - `sitemapHandler(cms)` — returns the CMS-generated `sitemap.xml` as `application/xml`.
9
+ - `robotsHandler(cms, { baseUrl, sitemapPath?, disallow? })` — returns `robots.txt` as `text/plain`, with an absolute `Sitemap:` line.
10
+ - `feedHandler(cms)` — returns the CMS-generated RSS feed as `application/rss+xml`.
11
+
12
+ See the [parent README](../../README.md) for the full SDK overview.
package/dist/index.cjs ADDED
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ feedHandler: () => feedHandler,
24
+ redirectMiddleware: () => redirectMiddleware,
25
+ robotsHandler: () => robotsHandler,
26
+ sitemapHandler: () => sitemapHandler
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/feedHandler.ts
31
+ async function feedHandler(cms) {
32
+ const xml = await cms.feed.toRssXml();
33
+ return new Response(xml, {
34
+ status: 200,
35
+ headers: {
36
+ "content-type": "application/rss+xml; charset=utf-8",
37
+ "cache-control": "public, max-age=600"
38
+ }
39
+ });
40
+ }
41
+
42
+ // src/redirectMiddleware.ts
43
+ async function redirectMiddleware(cms, pathname, opts) {
44
+ const hit = await cms.redirects.resolve(pathname);
45
+ if (!hit.matched) return null;
46
+ const target = new URL(hit.to, opts.baseUrl).toString();
47
+ return new Response(null, {
48
+ status: 301,
49
+ headers: { Location: target }
50
+ });
51
+ }
52
+
53
+ // src/robotsHandler.ts
54
+ function robotsHandler(cms, opts) {
55
+ const sitemapUrl = new URL(opts.sitemapPath ?? "/sitemap.xml", opts.baseUrl).toString();
56
+ const txt = cms.robots.toTxt({
57
+ baseUrl: opts.baseUrl,
58
+ sitemapUrl,
59
+ disallow: opts.disallow
60
+ });
61
+ return new Response(txt, {
62
+ status: 200,
63
+ headers: {
64
+ "content-type": "text/plain; charset=utf-8",
65
+ "cache-control": "public, max-age=3600"
66
+ }
67
+ });
68
+ }
69
+
70
+ // src/sitemapHandler.ts
71
+ async function sitemapHandler(cms) {
72
+ const xml = await cms.sitemap.toXml();
73
+ return new Response(xml, {
74
+ status: 200,
75
+ headers: {
76
+ "content-type": "application/xml; charset=utf-8",
77
+ "cache-control": "public, max-age=600"
78
+ }
79
+ });
80
+ }
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ feedHandler,
84
+ redirectMiddleware,
85
+ robotsHandler,
86
+ sitemapHandler
87
+ });
88
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/feedHandler.ts","../src/redirectMiddleware.ts","../src/robotsHandler.ts","../src/sitemapHandler.ts"],"sourcesContent":["export { feedHandler } from './feedHandler'\nexport { redirectMiddleware } from './redirectMiddleware'\nexport type { RedirectMiddlewareOpts } from './redirectMiddleware'\nexport { robotsHandler } from './robotsHandler'\nexport type { RobotsHandlerOpts } from './robotsHandler'\nexport { sitemapHandler } from './sitemapHandler'\n","type FeedLike = { toRssXml(): Promise<string> }\ntype CmsLike = { feed: FeedLike }\n\nexport async function feedHandler(cms: CmsLike): Promise<Response> {\n const xml = await cms.feed.toRssXml()\n return new Response(xml, {\n status: 200,\n headers: {\n 'content-type': 'application/rss+xml; charset=utf-8',\n 'cache-control': 'public, max-age=600'\n }\n })\n}\n","type RedirectsResource = {\n resolve(pathname: string): Promise<{ matched: true; to: string; status: 301 } | { matched: false }>\n}\n\ntype CmsClientLike = {\n redirects: RedirectsResource\n}\n\nexport type RedirectMiddlewareOpts = {\n baseUrl: string\n}\n\nexport async function redirectMiddleware(\n cms: CmsClientLike,\n pathname: string,\n opts: RedirectMiddlewareOpts\n): Promise<Response | null> {\n const hit = await cms.redirects.resolve(pathname)\n if (!hit.matched) return null\n const target = new URL(hit.to, opts.baseUrl).toString()\n return new Response(null, {\n status: 301,\n headers: { Location: target }\n })\n}\n","type RobotsLike = {\n toTxt(opts: {\n baseUrl: string\n sitemapUrl: string\n disallow?: string[]\n userAgent?: string\n }): string\n}\ntype CmsLike = { robots: RobotsLike }\n\nexport type RobotsHandlerOpts = {\n baseUrl: string\n sitemapPath?: string\n disallow?: string[]\n}\n\nexport function robotsHandler(cms: CmsLike, opts: RobotsHandlerOpts): Response {\n const sitemapUrl = new URL(opts.sitemapPath ?? '/sitemap.xml', opts.baseUrl).toString()\n const txt = cms.robots.toTxt({\n baseUrl: opts.baseUrl,\n sitemapUrl,\n disallow: opts.disallow\n })\n return new Response(txt, {\n status: 200,\n headers: {\n 'content-type': 'text/plain; charset=utf-8',\n 'cache-control': 'public, max-age=3600'\n }\n })\n}\n","type SitemapLike = { toXml(): Promise<string> }\ntype CmsLike = { sitemap: SitemapLike }\n\nexport async function sitemapHandler(cms: CmsLike): Promise<Response> {\n const xml = await cms.sitemap.toXml()\n return new Response(xml, {\n status: 200,\n headers: {\n 'content-type': 'application/xml; charset=utf-8',\n 'cache-control': 'public, max-age=600'\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,eAAsB,YAAY,KAAiC;AACjE,QAAM,MAAM,MAAM,IAAI,KAAK,SAAS;AACpC,SAAO,IAAI,SAAS,KAAK;AAAA,IACvB,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;;;ACAA,eAAsB,mBACpB,KACA,UACA,MAC0B;AAC1B,QAAM,MAAM,MAAM,IAAI,UAAU,QAAQ,QAAQ;AAChD,MAAI,CAAC,IAAI,QAAS,QAAO;AACzB,QAAM,SAAS,IAAI,IAAI,IAAI,IAAI,KAAK,OAAO,EAAE,SAAS;AACtD,SAAO,IAAI,SAAS,MAAM;AAAA,IACxB,QAAQ;AAAA,IACR,SAAS,EAAE,UAAU,OAAO;AAAA,EAC9B,CAAC;AACH;;;ACRO,SAAS,cAAc,KAAc,MAAmC;AAC7E,QAAM,aAAa,IAAI,IAAI,KAAK,eAAe,gBAAgB,KAAK,OAAO,EAAE,SAAS;AACtF,QAAM,MAAM,IAAI,OAAO,MAAM;AAAA,IAC3B,SAAS,KAAK;AAAA,IACd;AAAA,IACA,UAAU,KAAK;AAAA,EACjB,CAAC;AACD,SAAO,IAAI,SAAS,KAAK;AAAA,IACvB,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;;;AC3BA,eAAsB,eAAe,KAAiC;AACpE,QAAM,MAAM,MAAM,IAAI,QAAQ,MAAM;AACpC,SAAO,IAAI,SAAS,KAAK;AAAA,IACvB,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,52 @@
1
+ type FeedLike = {
2
+ toRssXml(): Promise<string>;
3
+ };
4
+ type CmsLike$2 = {
5
+ feed: FeedLike;
6
+ };
7
+ declare function feedHandler(cms: CmsLike$2): Promise<Response>;
8
+
9
+ type RedirectsResource = {
10
+ resolve(pathname: string): Promise<{
11
+ matched: true;
12
+ to: string;
13
+ status: 301;
14
+ } | {
15
+ matched: false;
16
+ }>;
17
+ };
18
+ type CmsClientLike = {
19
+ redirects: RedirectsResource;
20
+ };
21
+ type RedirectMiddlewareOpts = {
22
+ baseUrl: string;
23
+ };
24
+ declare function redirectMiddleware(cms: CmsClientLike, pathname: string, opts: RedirectMiddlewareOpts): Promise<Response | null>;
25
+
26
+ type RobotsLike = {
27
+ toTxt(opts: {
28
+ baseUrl: string;
29
+ sitemapUrl: string;
30
+ disallow?: string[];
31
+ userAgent?: string;
32
+ }): string;
33
+ };
34
+ type CmsLike$1 = {
35
+ robots: RobotsLike;
36
+ };
37
+ type RobotsHandlerOpts = {
38
+ baseUrl: string;
39
+ sitemapPath?: string;
40
+ disallow?: string[];
41
+ };
42
+ declare function robotsHandler(cms: CmsLike$1, opts: RobotsHandlerOpts): Response;
43
+
44
+ type SitemapLike = {
45
+ toXml(): Promise<string>;
46
+ };
47
+ type CmsLike = {
48
+ sitemap: SitemapLike;
49
+ };
50
+ declare function sitemapHandler(cms: CmsLike): Promise<Response>;
51
+
52
+ export { type RedirectMiddlewareOpts, type RobotsHandlerOpts, feedHandler, redirectMiddleware, robotsHandler, sitemapHandler };
@@ -0,0 +1,52 @@
1
+ type FeedLike = {
2
+ toRssXml(): Promise<string>;
3
+ };
4
+ type CmsLike$2 = {
5
+ feed: FeedLike;
6
+ };
7
+ declare function feedHandler(cms: CmsLike$2): Promise<Response>;
8
+
9
+ type RedirectsResource = {
10
+ resolve(pathname: string): Promise<{
11
+ matched: true;
12
+ to: string;
13
+ status: 301;
14
+ } | {
15
+ matched: false;
16
+ }>;
17
+ };
18
+ type CmsClientLike = {
19
+ redirects: RedirectsResource;
20
+ };
21
+ type RedirectMiddlewareOpts = {
22
+ baseUrl: string;
23
+ };
24
+ declare function redirectMiddleware(cms: CmsClientLike, pathname: string, opts: RedirectMiddlewareOpts): Promise<Response | null>;
25
+
26
+ type RobotsLike = {
27
+ toTxt(opts: {
28
+ baseUrl: string;
29
+ sitemapUrl: string;
30
+ disallow?: string[];
31
+ userAgent?: string;
32
+ }): string;
33
+ };
34
+ type CmsLike$1 = {
35
+ robots: RobotsLike;
36
+ };
37
+ type RobotsHandlerOpts = {
38
+ baseUrl: string;
39
+ sitemapPath?: string;
40
+ disallow?: string[];
41
+ };
42
+ declare function robotsHandler(cms: CmsLike$1, opts: RobotsHandlerOpts): Response;
43
+
44
+ type SitemapLike = {
45
+ toXml(): Promise<string>;
46
+ };
47
+ type CmsLike = {
48
+ sitemap: SitemapLike;
49
+ };
50
+ declare function sitemapHandler(cms: CmsLike): Promise<Response>;
51
+
52
+ export { type RedirectMiddlewareOpts, type RobotsHandlerOpts, feedHandler, redirectMiddleware, robotsHandler, sitemapHandler };
package/dist/index.js ADDED
@@ -0,0 +1,58 @@
1
+ // src/feedHandler.ts
2
+ async function feedHandler(cms) {
3
+ const xml = await cms.feed.toRssXml();
4
+ return new Response(xml, {
5
+ status: 200,
6
+ headers: {
7
+ "content-type": "application/rss+xml; charset=utf-8",
8
+ "cache-control": "public, max-age=600"
9
+ }
10
+ });
11
+ }
12
+
13
+ // src/redirectMiddleware.ts
14
+ async function redirectMiddleware(cms, pathname, opts) {
15
+ const hit = await cms.redirects.resolve(pathname);
16
+ if (!hit.matched) return null;
17
+ const target = new URL(hit.to, opts.baseUrl).toString();
18
+ return new Response(null, {
19
+ status: 301,
20
+ headers: { Location: target }
21
+ });
22
+ }
23
+
24
+ // src/robotsHandler.ts
25
+ function robotsHandler(cms, opts) {
26
+ const sitemapUrl = new URL(opts.sitemapPath ?? "/sitemap.xml", opts.baseUrl).toString();
27
+ const txt = cms.robots.toTxt({
28
+ baseUrl: opts.baseUrl,
29
+ sitemapUrl,
30
+ disallow: opts.disallow
31
+ });
32
+ return new Response(txt, {
33
+ status: 200,
34
+ headers: {
35
+ "content-type": "text/plain; charset=utf-8",
36
+ "cache-control": "public, max-age=3600"
37
+ }
38
+ });
39
+ }
40
+
41
+ // src/sitemapHandler.ts
42
+ async function sitemapHandler(cms) {
43
+ const xml = await cms.sitemap.toXml();
44
+ return new Response(xml, {
45
+ status: 200,
46
+ headers: {
47
+ "content-type": "application/xml; charset=utf-8",
48
+ "cache-control": "public, max-age=600"
49
+ }
50
+ });
51
+ }
52
+ export {
53
+ feedHandler,
54
+ redirectMiddleware,
55
+ robotsHandler,
56
+ sitemapHandler
57
+ };
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/feedHandler.ts","../src/redirectMiddleware.ts","../src/robotsHandler.ts","../src/sitemapHandler.ts"],"sourcesContent":["type FeedLike = { toRssXml(): Promise<string> }\ntype CmsLike = { feed: FeedLike }\n\nexport async function feedHandler(cms: CmsLike): Promise<Response> {\n const xml = await cms.feed.toRssXml()\n return new Response(xml, {\n status: 200,\n headers: {\n 'content-type': 'application/rss+xml; charset=utf-8',\n 'cache-control': 'public, max-age=600'\n }\n })\n}\n","type RedirectsResource = {\n resolve(pathname: string): Promise<{ matched: true; to: string; status: 301 } | { matched: false }>\n}\n\ntype CmsClientLike = {\n redirects: RedirectsResource\n}\n\nexport type RedirectMiddlewareOpts = {\n baseUrl: string\n}\n\nexport async function redirectMiddleware(\n cms: CmsClientLike,\n pathname: string,\n opts: RedirectMiddlewareOpts\n): Promise<Response | null> {\n const hit = await cms.redirects.resolve(pathname)\n if (!hit.matched) return null\n const target = new URL(hit.to, opts.baseUrl).toString()\n return new Response(null, {\n status: 301,\n headers: { Location: target }\n })\n}\n","type RobotsLike = {\n toTxt(opts: {\n baseUrl: string\n sitemapUrl: string\n disallow?: string[]\n userAgent?: string\n }): string\n}\ntype CmsLike = { robots: RobotsLike }\n\nexport type RobotsHandlerOpts = {\n baseUrl: string\n sitemapPath?: string\n disallow?: string[]\n}\n\nexport function robotsHandler(cms: CmsLike, opts: RobotsHandlerOpts): Response {\n const sitemapUrl = new URL(opts.sitemapPath ?? '/sitemap.xml', opts.baseUrl).toString()\n const txt = cms.robots.toTxt({\n baseUrl: opts.baseUrl,\n sitemapUrl,\n disallow: opts.disallow\n })\n return new Response(txt, {\n status: 200,\n headers: {\n 'content-type': 'text/plain; charset=utf-8',\n 'cache-control': 'public, max-age=3600'\n }\n })\n}\n","type SitemapLike = { toXml(): Promise<string> }\ntype CmsLike = { sitemap: SitemapLike }\n\nexport async function sitemapHandler(cms: CmsLike): Promise<Response> {\n const xml = await cms.sitemap.toXml()\n return new Response(xml, {\n status: 200,\n headers: {\n 'content-type': 'application/xml; charset=utf-8',\n 'cache-control': 'public, max-age=600'\n }\n })\n}\n"],"mappings":";AAGA,eAAsB,YAAY,KAAiC;AACjE,QAAM,MAAM,MAAM,IAAI,KAAK,SAAS;AACpC,SAAO,IAAI,SAAS,KAAK;AAAA,IACvB,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;;;ACAA,eAAsB,mBACpB,KACA,UACA,MAC0B;AAC1B,QAAM,MAAM,MAAM,IAAI,UAAU,QAAQ,QAAQ;AAChD,MAAI,CAAC,IAAI,QAAS,QAAO;AACzB,QAAM,SAAS,IAAI,IAAI,IAAI,IAAI,KAAK,OAAO,EAAE,SAAS;AACtD,SAAO,IAAI,SAAS,MAAM;AAAA,IACxB,QAAQ;AAAA,IACR,SAAS,EAAE,UAAU,OAAO;AAAA,EAC9B,CAAC;AACH;;;ACRO,SAAS,cAAc,KAAc,MAAmC;AAC7E,QAAM,aAAa,IAAI,IAAI,KAAK,eAAe,gBAAgB,KAAK,OAAO,EAAE,SAAS;AACtF,QAAM,MAAM,IAAI,OAAO,MAAM;AAAA,IAC3B,SAAS,KAAK;AAAA,IACd;AAAA,IACA,UAAU,KAAK;AAAA,EACjB,CAAC;AACD,SAAO,IAAI,SAAS,KAAK;AAAA,IACvB,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;;;AC3BA,eAAsB,eAAe,KAAiC;AACpE,QAAM,MAAM,MAAM,IAAI,QAAQ,MAAM;AACpC,SAAO,IAAI,SAAS,KAAK;AAAA,IACvB,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@gb-npm/cms-worker-cf",
3
+ "version": "0.1.0",
4
+ "description": "Cloudflare Worker adapters for @gb-npm/cms-sdk — sitemap.xml, robots.txt, RSS, and redirect middleware",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "dependencies": {
21
+ "@gb-npm/cms-sdk": "^0.1.0"
22
+ },
23
+ "devDependencies": {
24
+ "@cloudflare/workers-types": "^4.20240712.0",
25
+ "tsup": "^8.3.0",
26
+ "typescript": "^5.6.0",
27
+ "vitest": "^3.0.0"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "build": "tsup",
34
+ "typecheck": "tsc --noEmit",
35
+ "test": "vitest run"
36
+ }
37
+ }