@uptrademedia/site-kit 1.2.5 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-TJUON7TH.mjs → chunk-24HSWZ42.mjs} +44 -22
- package/dist/chunk-24HSWZ42.mjs.map +1 -0
- package/dist/chunk-3VHHDNLH.mjs +1 -0
- package/dist/chunk-3WMD3TE6.js +1 -0
- package/dist/chunk-5TTUNB63.js +1 -0
- package/dist/chunk-7557OTHW.js +62 -0
- package/dist/chunk-7557OTHW.js.map +1 -0
- package/dist/chunk-FR6DV5QX.js +1 -0
- package/dist/chunk-G7RSD56P.js +1 -0
- package/dist/chunk-GCJXQ4AG.mjs +59 -0
- package/dist/chunk-GCJXQ4AG.mjs.map +1 -0
- package/dist/chunk-GHSZWROI.js +1 -0
- package/dist/chunk-IARDGI5N.mjs +1 -0
- package/dist/chunk-KUGMH4ZF.js +1 -0
- package/dist/chunk-LBHEVL6U.js +1 -0
- package/dist/chunk-UJQ73OS6.js +1 -0
- package/dist/{chunk-V7QPQBFG.js → chunk-WJD3MZGY.js} +44 -22
- package/dist/chunk-WJD3MZGY.js.map +1 -0
- package/dist/commerce/index.js +1 -0
- package/dist/commerce/index.mjs +1 -0
- package/dist/forms/index.d.mts +1 -1
- package/dist/forms/index.d.ts +1 -1
- package/dist/forms/index.js +31 -9
- package/dist/forms/index.js.map +1 -1
- package/dist/forms/index.mjs +31 -9
- package/dist/forms/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/redirects/index.d.mts +15 -9
- package/dist/redirects/index.d.ts +15 -9
- package/dist/redirects/index.js +6 -5
- package/dist/redirects/index.mjs +2 -1
- package/dist/robots/index.d.mts +12 -20
- package/dist/robots/index.d.ts +12 -20
- package/dist/robots/index.js +37 -19
- package/dist/robots/index.js.map +1 -1
- package/dist/robots/index.mjs +37 -19
- package/dist/robots/index.mjs.map +1 -1
- package/dist/site-config/index.d.mts +24 -0
- package/dist/site-config/index.d.ts +24 -0
- package/dist/site-config/index.js +17 -0
- package/dist/site-config/index.js.map +1 -0
- package/dist/site-config/index.mjs +4 -0
- package/dist/site-config/index.mjs.map +1 -0
- package/dist/sitemap/index.d.mts +2 -2
- package/dist/sitemap/index.d.ts +2 -2
- package/dist/sitemap/index.js +8 -1
- package/dist/sitemap/index.js.map +1 -1
- package/dist/sitemap/index.mjs +8 -1
- package/dist/sitemap/index.mjs.map +1 -1
- package/dist/{types-BYSB7zNY.d.mts → types-mqEAmRhJ.d.mts} +3 -0
- package/dist/{types-BYSB7zNY.d.ts → types-mqEAmRhJ.d.ts} +3 -0
- package/package.json +6 -1
- package/dist/chunk-TJUON7TH.mjs.map +0 -1
- package/dist/chunk-V7QPQBFG.js.map +0 -1
|
@@ -3,23 +3,24 @@ import { NextRequest, NextResponse } from 'next/server';
|
|
|
3
3
|
/**
|
|
4
4
|
* Managed Redirects - Next.js Middleware Helper
|
|
5
5
|
*
|
|
6
|
-
* Fetches redirect rules from
|
|
7
|
-
*
|
|
6
|
+
* Fetches redirect rules from Portal and applies them.
|
|
7
|
+
* Supports API key only (domain resolved from Portal) or domain-based lookup.
|
|
8
8
|
*
|
|
9
|
-
* Usage in middleware.ts:
|
|
9
|
+
* Usage in middleware.ts (API key only):
|
|
10
10
|
*
|
|
11
11
|
* import { handleManagedRedirects } from '@uptrade/site-kit/redirects'
|
|
12
12
|
*
|
|
13
13
|
* export async function middleware(request: NextRequest) {
|
|
14
14
|
* const redirect = await handleManagedRedirects(request, {
|
|
15
|
-
*
|
|
16
|
-
* portalApiUrl: process.env.
|
|
15
|
+
* apiKey: process.env.NEXT_PUBLIC_UPTRADE_API_KEY,
|
|
16
|
+
* portalApiUrl: process.env.NEXT_PUBLIC_UPTRADE_API_URL,
|
|
17
17
|
* })
|
|
18
|
-
*
|
|
19
18
|
* if (redirect) return redirect
|
|
20
|
-
*
|
|
21
19
|
* return NextResponse.next()
|
|
22
20
|
* }
|
|
21
|
+
*
|
|
22
|
+
* Or with domain (legacy):
|
|
23
|
+
* const redirect = await handleManagedRedirects(request, { domain: 'example.com' })
|
|
23
24
|
*/
|
|
24
25
|
|
|
25
26
|
interface RedirectRule {
|
|
@@ -29,12 +30,17 @@ interface RedirectRule {
|
|
|
29
30
|
is_enabled: boolean;
|
|
30
31
|
}
|
|
31
32
|
interface RedirectConfig {
|
|
32
|
-
|
|
33
|
+
/** Domain to fetch redirects for (optional when apiKey is set) */
|
|
34
|
+
domain?: string;
|
|
35
|
+
/** Project API key; when set, redirects are fetched by key (no domain needed) */
|
|
36
|
+
apiKey?: string;
|
|
33
37
|
portalApiUrl?: string;
|
|
34
38
|
cacheSeconds?: number;
|
|
35
39
|
}
|
|
36
40
|
/**
|
|
37
|
-
* Fetch redirect rules from Portal API
|
|
41
|
+
* Fetch redirect rules from Portal API.
|
|
42
|
+
* When apiKey is set (or from env), uses key-based endpoint (no domain required).
|
|
43
|
+
* Otherwise uses domain query (or domain from getSiteConfig when only env API key is set).
|
|
38
44
|
*/
|
|
39
45
|
declare function fetchRedirectRules(config: RedirectConfig): Promise<RedirectRule[]>;
|
|
40
46
|
/**
|
|
@@ -3,23 +3,24 @@ import { NextRequest, NextResponse } from 'next/server';
|
|
|
3
3
|
/**
|
|
4
4
|
* Managed Redirects - Next.js Middleware Helper
|
|
5
5
|
*
|
|
6
|
-
* Fetches redirect rules from
|
|
7
|
-
*
|
|
6
|
+
* Fetches redirect rules from Portal and applies them.
|
|
7
|
+
* Supports API key only (domain resolved from Portal) or domain-based lookup.
|
|
8
8
|
*
|
|
9
|
-
* Usage in middleware.ts:
|
|
9
|
+
* Usage in middleware.ts (API key only):
|
|
10
10
|
*
|
|
11
11
|
* import { handleManagedRedirects } from '@uptrade/site-kit/redirects'
|
|
12
12
|
*
|
|
13
13
|
* export async function middleware(request: NextRequest) {
|
|
14
14
|
* const redirect = await handleManagedRedirects(request, {
|
|
15
|
-
*
|
|
16
|
-
* portalApiUrl: process.env.
|
|
15
|
+
* apiKey: process.env.NEXT_PUBLIC_UPTRADE_API_KEY,
|
|
16
|
+
* portalApiUrl: process.env.NEXT_PUBLIC_UPTRADE_API_URL,
|
|
17
17
|
* })
|
|
18
|
-
*
|
|
19
18
|
* if (redirect) return redirect
|
|
20
|
-
*
|
|
21
19
|
* return NextResponse.next()
|
|
22
20
|
* }
|
|
21
|
+
*
|
|
22
|
+
* Or with domain (legacy):
|
|
23
|
+
* const redirect = await handleManagedRedirects(request, { domain: 'example.com' })
|
|
23
24
|
*/
|
|
24
25
|
|
|
25
26
|
interface RedirectRule {
|
|
@@ -29,12 +30,17 @@ interface RedirectRule {
|
|
|
29
30
|
is_enabled: boolean;
|
|
30
31
|
}
|
|
31
32
|
interface RedirectConfig {
|
|
32
|
-
|
|
33
|
+
/** Domain to fetch redirects for (optional when apiKey is set) */
|
|
34
|
+
domain?: string;
|
|
35
|
+
/** Project API key; when set, redirects are fetched by key (no domain needed) */
|
|
36
|
+
apiKey?: string;
|
|
33
37
|
portalApiUrl?: string;
|
|
34
38
|
cacheSeconds?: number;
|
|
35
39
|
}
|
|
36
40
|
/**
|
|
37
|
-
* Fetch redirect rules from Portal API
|
|
41
|
+
* Fetch redirect rules from Portal API.
|
|
42
|
+
* When apiKey is set (or from env), uses key-based endpoint (no domain required).
|
|
43
|
+
* Otherwise uses domain query (or domain from getSiteConfig when only env API key is set).
|
|
38
44
|
*/
|
|
39
45
|
declare function fetchRedirectRules(config: RedirectConfig): Promise<RedirectRule[]>;
|
|
40
46
|
/**
|
package/dist/redirects/index.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkWJD3MZGY_js = require('../chunk-WJD3MZGY.js');
|
|
4
|
+
require('../chunk-7557OTHW.js');
|
|
4
5
|
require('../chunk-ZSMWDLMK.js');
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
Object.defineProperty(exports, "clearRedirectCache", {
|
|
9
10
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
11
|
+
get: function () { return chunkWJD3MZGY_js.clearRedirectCache; }
|
|
11
12
|
});
|
|
12
13
|
Object.defineProperty(exports, "fetchRedirectRules", {
|
|
13
14
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
15
|
+
get: function () { return chunkWJD3MZGY_js.fetchRedirectRules; }
|
|
15
16
|
});
|
|
16
17
|
Object.defineProperty(exports, "generateNextRedirects", {
|
|
17
18
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
19
|
+
get: function () { return chunkWJD3MZGY_js.generateNextRedirects; }
|
|
19
20
|
});
|
|
20
21
|
Object.defineProperty(exports, "handleManagedRedirects", {
|
|
21
22
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
23
|
+
get: function () { return chunkWJD3MZGY_js.handleManagedRedirects; }
|
|
23
24
|
});
|
|
24
25
|
//# sourceMappingURL=index.js.map
|
|
25
26
|
//# sourceMappingURL=index.js.map
|
package/dist/redirects/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { clearRedirectCache, fetchRedirectRules, generateNextRedirects, handleManagedRedirects } from '../chunk-
|
|
1
|
+
export { clearRedirectCache, fetchRedirectRules, generateNextRedirects, handleManagedRedirects } from '../chunk-24HSWZ42.mjs';
|
|
2
|
+
import '../chunk-GCJXQ4AG.mjs';
|
|
2
3
|
import '../chunk-4XPGGLVP.mjs';
|
|
3
4
|
//# sourceMappingURL=index.mjs.map
|
|
4
5
|
//# sourceMappingURL=index.mjs.map
|
package/dist/robots/index.d.mts
CHANGED
|
@@ -2,34 +2,26 @@
|
|
|
2
2
|
* @uptrade/site-kit/robots - robots.txt Generator
|
|
3
3
|
*
|
|
4
4
|
* Generates robots.txt with Sitemap directive.
|
|
5
|
-
*
|
|
5
|
+
* baseUrl can be omitted when apiKey is set (resolved from Portal project-info).
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
*
|
|
9
|
-
* // app/robots.ts (Next.js MetadataRoute)
|
|
8
|
+
* // app/robots.txt/route.ts (API key only)
|
|
10
9
|
* import { createRobots } from '@uptrademedia/site-kit/robots'
|
|
11
|
-
*
|
|
12
|
-
* export default function robots() {
|
|
13
|
-
* return createRobots({
|
|
14
|
-
* baseUrl: 'https://example.com',
|
|
15
|
-
* })()
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
10
|
+
* export const GET = createRobots({ apiKey: process.env.NEXT_PUBLIC_UPTRADE_API_KEY })
|
|
18
11
|
*
|
|
19
12
|
* @example
|
|
20
|
-
*
|
|
21
|
-
* // app/robots.txt/route.ts
|
|
22
|
-
* import { createRobots } from '@uptrademedia/site-kit/robots'
|
|
23
|
-
*
|
|
13
|
+
* // With explicit baseUrl
|
|
24
14
|
* export const GET = createRobots({
|
|
25
15
|
* baseUrl: process.env.NEXT_PUBLIC_SITE_URL || 'https://example.com',
|
|
26
|
-
* disallow: ['/admin'
|
|
16
|
+
* disallow: ['/admin'],
|
|
27
17
|
* })
|
|
28
|
-
* ```
|
|
29
18
|
*/
|
|
30
19
|
interface RobotsConfig {
|
|
31
|
-
/** Base URL of the site (
|
|
32
|
-
baseUrl
|
|
20
|
+
/** Base URL of the site (optional when apiKey is set; then resolved from Portal) */
|
|
21
|
+
baseUrl?: string;
|
|
22
|
+
/** Project API key; when set and baseUrl is not, baseUrl is resolved from Portal */
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
apiUrl?: string;
|
|
33
25
|
/** Path to sitemap (default: /sitemap.xml) */
|
|
34
26
|
sitemapPath?: string;
|
|
35
27
|
/** Pre-built robots content from Portal (overrides default when provided) */
|
|
@@ -38,8 +30,8 @@ interface RobotsConfig {
|
|
|
38
30
|
disallow?: string[];
|
|
39
31
|
}
|
|
40
32
|
/**
|
|
41
|
-
* Create a robots.txt handler that returns a Response
|
|
42
|
-
* Use as GET handler for app/robots.txt/route.ts
|
|
33
|
+
* Create a robots.txt handler that returns a Response or Promise<Response>.
|
|
34
|
+
* Use as GET handler for app/robots.txt/route.ts. When baseUrl is omitted, pass apiKey to resolve from Portal.
|
|
43
35
|
*/
|
|
44
36
|
declare function createRobots(config: RobotsConfig): () => Response | Promise<Response>;
|
|
45
37
|
|
package/dist/robots/index.d.ts
CHANGED
|
@@ -2,34 +2,26 @@
|
|
|
2
2
|
* @uptrade/site-kit/robots - robots.txt Generator
|
|
3
3
|
*
|
|
4
4
|
* Generates robots.txt with Sitemap directive.
|
|
5
|
-
*
|
|
5
|
+
* baseUrl can be omitted when apiKey is set (resolved from Portal project-info).
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
*
|
|
9
|
-
* // app/robots.ts (Next.js MetadataRoute)
|
|
8
|
+
* // app/robots.txt/route.ts (API key only)
|
|
10
9
|
* import { createRobots } from '@uptrademedia/site-kit/robots'
|
|
11
|
-
*
|
|
12
|
-
* export default function robots() {
|
|
13
|
-
* return createRobots({
|
|
14
|
-
* baseUrl: 'https://example.com',
|
|
15
|
-
* })()
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
10
|
+
* export const GET = createRobots({ apiKey: process.env.NEXT_PUBLIC_UPTRADE_API_KEY })
|
|
18
11
|
*
|
|
19
12
|
* @example
|
|
20
|
-
*
|
|
21
|
-
* // app/robots.txt/route.ts
|
|
22
|
-
* import { createRobots } from '@uptrademedia/site-kit/robots'
|
|
23
|
-
*
|
|
13
|
+
* // With explicit baseUrl
|
|
24
14
|
* export const GET = createRobots({
|
|
25
15
|
* baseUrl: process.env.NEXT_PUBLIC_SITE_URL || 'https://example.com',
|
|
26
|
-
* disallow: ['/admin'
|
|
16
|
+
* disallow: ['/admin'],
|
|
27
17
|
* })
|
|
28
|
-
* ```
|
|
29
18
|
*/
|
|
30
19
|
interface RobotsConfig {
|
|
31
|
-
/** Base URL of the site (
|
|
32
|
-
baseUrl
|
|
20
|
+
/** Base URL of the site (optional when apiKey is set; then resolved from Portal) */
|
|
21
|
+
baseUrl?: string;
|
|
22
|
+
/** Project API key; when set and baseUrl is not, baseUrl is resolved from Portal */
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
apiUrl?: string;
|
|
33
25
|
/** Path to sitemap (default: /sitemap.xml) */
|
|
34
26
|
sitemapPath?: string;
|
|
35
27
|
/** Pre-built robots content from Portal (overrides default when provided) */
|
|
@@ -38,8 +30,8 @@ interface RobotsConfig {
|
|
|
38
30
|
disallow?: string[];
|
|
39
31
|
}
|
|
40
32
|
/**
|
|
41
|
-
* Create a robots.txt handler that returns a Response
|
|
42
|
-
* Use as GET handler for app/robots.txt/route.ts
|
|
33
|
+
* Create a robots.txt handler that returns a Response or Promise<Response>.
|
|
34
|
+
* Use as GET handler for app/robots.txt/route.ts. When baseUrl is omitted, pass apiKey to resolve from Portal.
|
|
43
35
|
*/
|
|
44
36
|
declare function createRobots(config: RobotsConfig): () => Response | Promise<Response>;
|
|
45
37
|
|
package/dist/robots/index.js
CHANGED
|
@@ -1,30 +1,48 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunk7557OTHW_js = require('../chunk-7557OTHW.js');
|
|
3
4
|
require('../chunk-ZSMWDLMK.js');
|
|
4
5
|
|
|
5
6
|
// src/robots/index.ts
|
|
7
|
+
function buildRobotsResponse(baseUrl, config) {
|
|
8
|
+
const lines = [];
|
|
9
|
+
if (config.managedRobots?.trim()) {
|
|
10
|
+
lines.push(config.managedRobots.trim());
|
|
11
|
+
} else {
|
|
12
|
+
lines.push("User-agent: *");
|
|
13
|
+
lines.push("Allow: /");
|
|
14
|
+
for (const p of config.disallow ?? []) {
|
|
15
|
+
lines.push(`Disallow: ${p}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const base = baseUrl.replace(/\/$/, "");
|
|
19
|
+
const sitemapPath = config.sitemapPath ?? "/sitemap.xml";
|
|
20
|
+
const sitemapUrl = `${base}${sitemapPath.startsWith("/") ? "" : "/"}${sitemapPath}`;
|
|
21
|
+
lines.push(`Sitemap: ${sitemapUrl}`);
|
|
22
|
+
return new Response(lines.join("\n"), {
|
|
23
|
+
status: 200,
|
|
24
|
+
headers: {
|
|
25
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
26
|
+
"Cache-Control": "public, max-age=86400, s-maxage=86400"
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
6
30
|
function createRobots(config) {
|
|
7
31
|
return function robots() {
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
32
|
+
const baseUrl = config.baseUrl;
|
|
33
|
+
if (baseUrl) {
|
|
34
|
+
return buildRobotsResponse(baseUrl, config);
|
|
35
|
+
}
|
|
36
|
+
const apiKey = config.apiKey ?? (typeof process !== "undefined" && process.env && (process.env.NEXT_PUBLIC_UPTRADE_API_KEY || process.env.UPTRADE_API_KEY));
|
|
37
|
+
if (!apiKey) {
|
|
38
|
+
return new Response("User-agent: *\nDisallow: /", {
|
|
39
|
+
status: 200,
|
|
40
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
|
41
|
+
});
|
|
17
42
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
lines.push(`Sitemap: ${sitemapUrl}`);
|
|
22
|
-
return new Response(lines.join("\n"), {
|
|
23
|
-
status: 200,
|
|
24
|
-
headers: {
|
|
25
|
-
"Content-Type": "text/plain; charset=utf-8",
|
|
26
|
-
"Cache-Control": "public, max-age=86400, s-maxage=86400"
|
|
27
|
-
}
|
|
43
|
+
return chunk7557OTHW_js.getSiteConfig({ apiKey, apiUrl: config.apiUrl }).then((site) => {
|
|
44
|
+
const url = site?.site_url ?? "https://example.com";
|
|
45
|
+
return buildRobotsResponse(url, config);
|
|
28
46
|
});
|
|
29
47
|
};
|
|
30
48
|
}
|
package/dist/robots/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/robots/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/robots/index.ts"],"names":["getSiteConfig"],"mappings":";;;;;;AAmCA,SAAS,mBAAA,CAAoB,SAAiB,MAAA,EAAgC;AAC5E,EAAA,MAAM,QAAkB,EAAC;AAEzB,EAAA,IAAI,MAAA,CAAO,aAAA,EAAe,IAAA,EAAK,EAAG;AAChC,IAAA,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,aAAA,CAAc,IAAA,EAAM,CAAA;AAAA,EACxC,CAAA,MAAO;AACL,IAAA,KAAA,CAAM,KAAK,eAAe,CAAA;AAC1B,IAAA,KAAA,CAAM,KAAK,UAAU,CAAA;AACrB,IAAA,KAAA,MAAW,CAAA,IAAK,MAAA,CAAO,QAAA,IAAY,EAAC,EAAG;AACrC,MAAA,KAAA,CAAM,IAAA,CAAK,CAAA,UAAA,EAAa,CAAC,CAAA,CAAE,CAAA;AAAA,IAC7B;AAAA,EACF;AAEA,EAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACtC,EAAA,MAAM,WAAA,GAAc,OAAO,WAAA,IAAe,cAAA;AAC1C,EAAA,MAAM,UAAA,GAAa,CAAA,EAAG,IAAI,CAAA,EAAG,WAAA,CAAY,UAAA,CAAW,GAAG,CAAA,GAAI,EAAA,GAAK,GAAG,CAAA,EAAG,WAAW,CAAA,CAAA;AACjF,EAAA,KAAA,CAAM,IAAA,CAAK,CAAA,SAAA,EAAY,UAAU,CAAA,CAAE,CAAA;AAEnC,EAAA,OAAO,IAAI,QAAA,CAAS,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA,EAAG;AAAA,IACpC,MAAA,EAAQ,GAAA;AAAA,IACR,OAAA,EAAS;AAAA,MACP,cAAA,EAAgB,2BAAA;AAAA,MAChB,eAAA,EAAiB;AAAA;AACnB,GACD,CAAA;AACH;AAMO,SAAS,aAAa,MAAA,EAA0D;AACrF,EAAA,OAAO,SAAS,MAAA,GAAuC;AACrD,IAAA,MAAM,UAAU,MAAA,CAAO,OAAA;AACvB,IAAA,IAAI,OAAA,EAAS;AACX,MAAA,OAAO,mBAAA,CAAoB,SAAS,MAAM,CAAA;AAAA,IAC5C;AACA,IAAA,MAAM,MAAA,GAAS,MAAA,CAAO,MAAA,KAAW,OAAO,OAAA,KAAY,WAAA,IAAe,OAAA,CAAQ,GAAA,KAAQ,OAAA,CAAQ,GAAA,CAAI,2BAAA,IAA+B,OAAA,CAAQ,GAAA,CAAI,eAAA,CAAA,CAAA;AAC1I,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,OAAO,IAAI,SAAS,4BAAA,EAA8B;AAAA,QAChD,MAAA,EAAQ,GAAA;AAAA,QACR,OAAA,EAAS,EAAE,cAAA,EAAgB,2BAAA;AAA4B,OACxD,CAAA;AAAA,IACH;AACA,IAAA,OAAOA,8BAAA,CAAc,EAAE,MAAA,EAAQ,MAAA,EAAQ,MAAA,CAAO,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAC,IAAA,KAAS;AACrE,MAAA,MAAM,GAAA,GAAM,MAAM,QAAA,IAAY,qBAAA;AAC9B,MAAA,OAAO,mBAAA,CAAoB,KAAK,MAAM,CAAA;AAAA,IACxC,CAAC,CAAA;AAAA,EACH,CAAA;AACF","file":"index.js","sourcesContent":["/**\n * @uptrade/site-kit/robots - robots.txt Generator\n *\n * Generates robots.txt with Sitemap directive.\n * baseUrl can be omitted when apiKey is set (resolved from Portal project-info).\n *\n * @example\n * // app/robots.txt/route.ts (API key only)\n * import { createRobots } from '@uptrademedia/site-kit/robots'\n * export const GET = createRobots({ apiKey: process.env.NEXT_PUBLIC_UPTRADE_API_KEY })\n *\n * @example\n * // With explicit baseUrl\n * export const GET = createRobots({\n * baseUrl: process.env.NEXT_PUBLIC_SITE_URL || 'https://example.com',\n * disallow: ['/admin'],\n * })\n */\n\nimport { getSiteConfig } from '../site-config'\n\nexport interface RobotsConfig {\n /** Base URL of the site (optional when apiKey is set; then resolved from Portal) */\n baseUrl?: string\n /** Project API key; when set and baseUrl is not, baseUrl is resolved from Portal */\n apiKey?: string\n apiUrl?: string\n /** Path to sitemap (default: /sitemap.xml) */\n sitemapPath?: string\n /** Pre-built robots content from Portal (overrides default when provided) */\n managedRobots?: string | null\n /** Paths to disallow (e.g. ['/admin', '/api']) */\n disallow?: string[]\n}\n\nfunction buildRobotsResponse(baseUrl: string, config: RobotsConfig): Response {\n const lines: string[] = []\n\n if (config.managedRobots?.trim()) {\n lines.push(config.managedRobots.trim())\n } else {\n lines.push('User-agent: *')\n lines.push('Allow: /')\n for (const p of config.disallow ?? []) {\n lines.push(`Disallow: ${p}`)\n }\n }\n\n const base = baseUrl.replace(/\\/$/, '')\n const sitemapPath = config.sitemapPath ?? '/sitemap.xml'\n const sitemapUrl = `${base}${sitemapPath.startsWith('/') ? '' : '/'}${sitemapPath}`\n lines.push(`Sitemap: ${sitemapUrl}`)\n\n return new Response(lines.join('\\n'), {\n status: 200,\n headers: {\n 'Content-Type': 'text/plain; charset=utf-8',\n 'Cache-Control': 'public, max-age=86400, s-maxage=86400',\n },\n })\n}\n\n/**\n * Create a robots.txt handler that returns a Response or Promise<Response>.\n * Use as GET handler for app/robots.txt/route.ts. When baseUrl is omitted, pass apiKey to resolve from Portal.\n */\nexport function createRobots(config: RobotsConfig): () => Response | Promise<Response> {\n return function robots(): Response | Promise<Response> {\n const baseUrl = config.baseUrl\n if (baseUrl) {\n return buildRobotsResponse(baseUrl, config)\n }\n const apiKey = config.apiKey ?? (typeof process !== 'undefined' && process.env && (process.env.NEXT_PUBLIC_UPTRADE_API_KEY || process.env.UPTRADE_API_KEY))\n if (!apiKey) {\n return new Response('User-agent: *\\nDisallow: /', {\n status: 200,\n headers: { 'Content-Type': 'text/plain; charset=utf-8' },\n })\n }\n return getSiteConfig({ apiKey, apiUrl: config.apiUrl }).then((site) => {\n const url = site?.site_url ?? 'https://example.com'\n return buildRobotsResponse(url, config)\n })\n }\n}\n"]}
|
package/dist/robots/index.mjs
CHANGED
|
@@ -1,28 +1,46 @@
|
|
|
1
|
+
import { getSiteConfig } from '../chunk-GCJXQ4AG.mjs';
|
|
1
2
|
import '../chunk-4XPGGLVP.mjs';
|
|
2
3
|
|
|
3
4
|
// src/robots/index.ts
|
|
5
|
+
function buildRobotsResponse(baseUrl, config) {
|
|
6
|
+
const lines = [];
|
|
7
|
+
if (config.managedRobots?.trim()) {
|
|
8
|
+
lines.push(config.managedRobots.trim());
|
|
9
|
+
} else {
|
|
10
|
+
lines.push("User-agent: *");
|
|
11
|
+
lines.push("Allow: /");
|
|
12
|
+
for (const p of config.disallow ?? []) {
|
|
13
|
+
lines.push(`Disallow: ${p}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const base = baseUrl.replace(/\/$/, "");
|
|
17
|
+
const sitemapPath = config.sitemapPath ?? "/sitemap.xml";
|
|
18
|
+
const sitemapUrl = `${base}${sitemapPath.startsWith("/") ? "" : "/"}${sitemapPath}`;
|
|
19
|
+
lines.push(`Sitemap: ${sitemapUrl}`);
|
|
20
|
+
return new Response(lines.join("\n"), {
|
|
21
|
+
status: 200,
|
|
22
|
+
headers: {
|
|
23
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
24
|
+
"Cache-Control": "public, max-age=86400, s-maxage=86400"
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
4
28
|
function createRobots(config) {
|
|
5
29
|
return function robots() {
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
30
|
+
const baseUrl = config.baseUrl;
|
|
31
|
+
if (baseUrl) {
|
|
32
|
+
return buildRobotsResponse(baseUrl, config);
|
|
33
|
+
}
|
|
34
|
+
const apiKey = config.apiKey ?? (typeof process !== "undefined" && process.env && (process.env.NEXT_PUBLIC_UPTRADE_API_KEY || process.env.UPTRADE_API_KEY));
|
|
35
|
+
if (!apiKey) {
|
|
36
|
+
return new Response("User-agent: *\nDisallow: /", {
|
|
37
|
+
status: 200,
|
|
38
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
|
39
|
+
});
|
|
15
40
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
lines.push(`Sitemap: ${sitemapUrl}`);
|
|
20
|
-
return new Response(lines.join("\n"), {
|
|
21
|
-
status: 200,
|
|
22
|
-
headers: {
|
|
23
|
-
"Content-Type": "text/plain; charset=utf-8",
|
|
24
|
-
"Cache-Control": "public, max-age=86400, s-maxage=86400"
|
|
25
|
-
}
|
|
41
|
+
return getSiteConfig({ apiKey, apiUrl: config.apiUrl }).then((site) => {
|
|
42
|
+
const url = site?.site_url ?? "https://example.com";
|
|
43
|
+
return buildRobotsResponse(url, config);
|
|
26
44
|
});
|
|
27
45
|
};
|
|
28
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/robots/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/robots/index.ts"],"names":[],"mappings":";;;;AAmCA,SAAS,mBAAA,CAAoB,SAAiB,MAAA,EAAgC;AAC5E,EAAA,MAAM,QAAkB,EAAC;AAEzB,EAAA,IAAI,MAAA,CAAO,aAAA,EAAe,IAAA,EAAK,EAAG;AAChC,IAAA,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,aAAA,CAAc,IAAA,EAAM,CAAA;AAAA,EACxC,CAAA,MAAO;AACL,IAAA,KAAA,CAAM,KAAK,eAAe,CAAA;AAC1B,IAAA,KAAA,CAAM,KAAK,UAAU,CAAA;AACrB,IAAA,KAAA,MAAW,CAAA,IAAK,MAAA,CAAO,QAAA,IAAY,EAAC,EAAG;AACrC,MAAA,KAAA,CAAM,IAAA,CAAK,CAAA,UAAA,EAAa,CAAC,CAAA,CAAE,CAAA;AAAA,IAC7B;AAAA,EACF;AAEA,EAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACtC,EAAA,MAAM,WAAA,GAAc,OAAO,WAAA,IAAe,cAAA;AAC1C,EAAA,MAAM,UAAA,GAAa,CAAA,EAAG,IAAI,CAAA,EAAG,WAAA,CAAY,UAAA,CAAW,GAAG,CAAA,GAAI,EAAA,GAAK,GAAG,CAAA,EAAG,WAAW,CAAA,CAAA;AACjF,EAAA,KAAA,CAAM,IAAA,CAAK,CAAA,SAAA,EAAY,UAAU,CAAA,CAAE,CAAA;AAEnC,EAAA,OAAO,IAAI,QAAA,CAAS,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA,EAAG;AAAA,IACpC,MAAA,EAAQ,GAAA;AAAA,IACR,OAAA,EAAS;AAAA,MACP,cAAA,EAAgB,2BAAA;AAAA,MAChB,eAAA,EAAiB;AAAA;AACnB,GACD,CAAA;AACH;AAMO,SAAS,aAAa,MAAA,EAA0D;AACrF,EAAA,OAAO,SAAS,MAAA,GAAuC;AACrD,IAAA,MAAM,UAAU,MAAA,CAAO,OAAA;AACvB,IAAA,IAAI,OAAA,EAAS;AACX,MAAA,OAAO,mBAAA,CAAoB,SAAS,MAAM,CAAA;AAAA,IAC5C;AACA,IAAA,MAAM,MAAA,GAAS,MAAA,CAAO,MAAA,KAAW,OAAO,OAAA,KAAY,WAAA,IAAe,OAAA,CAAQ,GAAA,KAAQ,OAAA,CAAQ,GAAA,CAAI,2BAAA,IAA+B,OAAA,CAAQ,GAAA,CAAI,eAAA,CAAA,CAAA;AAC1I,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,OAAO,IAAI,SAAS,4BAAA,EAA8B;AAAA,QAChD,MAAA,EAAQ,GAAA;AAAA,QACR,OAAA,EAAS,EAAE,cAAA,EAAgB,2BAAA;AAA4B,OACxD,CAAA;AAAA,IACH;AACA,IAAA,OAAO,aAAA,CAAc,EAAE,MAAA,EAAQ,MAAA,EAAQ,MAAA,CAAO,QAAQ,CAAA,CAAE,IAAA,CAAK,CAAC,IAAA,KAAS;AACrE,MAAA,MAAM,GAAA,GAAM,MAAM,QAAA,IAAY,qBAAA;AAC9B,MAAA,OAAO,mBAAA,CAAoB,KAAK,MAAM,CAAA;AAAA,IACxC,CAAC,CAAA;AAAA,EACH,CAAA;AACF","file":"index.mjs","sourcesContent":["/**\n * @uptrade/site-kit/robots - robots.txt Generator\n *\n * Generates robots.txt with Sitemap directive.\n * baseUrl can be omitted when apiKey is set (resolved from Portal project-info).\n *\n * @example\n * // app/robots.txt/route.ts (API key only)\n * import { createRobots } from '@uptrademedia/site-kit/robots'\n * export const GET = createRobots({ apiKey: process.env.NEXT_PUBLIC_UPTRADE_API_KEY })\n *\n * @example\n * // With explicit baseUrl\n * export const GET = createRobots({\n * baseUrl: process.env.NEXT_PUBLIC_SITE_URL || 'https://example.com',\n * disallow: ['/admin'],\n * })\n */\n\nimport { getSiteConfig } from '../site-config'\n\nexport interface RobotsConfig {\n /** Base URL of the site (optional when apiKey is set; then resolved from Portal) */\n baseUrl?: string\n /** Project API key; when set and baseUrl is not, baseUrl is resolved from Portal */\n apiKey?: string\n apiUrl?: string\n /** Path to sitemap (default: /sitemap.xml) */\n sitemapPath?: string\n /** Pre-built robots content from Portal (overrides default when provided) */\n managedRobots?: string | null\n /** Paths to disallow (e.g. ['/admin', '/api']) */\n disallow?: string[]\n}\n\nfunction buildRobotsResponse(baseUrl: string, config: RobotsConfig): Response {\n const lines: string[] = []\n\n if (config.managedRobots?.trim()) {\n lines.push(config.managedRobots.trim())\n } else {\n lines.push('User-agent: *')\n lines.push('Allow: /')\n for (const p of config.disallow ?? []) {\n lines.push(`Disallow: ${p}`)\n }\n }\n\n const base = baseUrl.replace(/\\/$/, '')\n const sitemapPath = config.sitemapPath ?? '/sitemap.xml'\n const sitemapUrl = `${base}${sitemapPath.startsWith('/') ? '' : '/'}${sitemapPath}`\n lines.push(`Sitemap: ${sitemapUrl}`)\n\n return new Response(lines.join('\\n'), {\n status: 200,\n headers: {\n 'Content-Type': 'text/plain; charset=utf-8',\n 'Cache-Control': 'public, max-age=86400, s-maxage=86400',\n },\n })\n}\n\n/**\n * Create a robots.txt handler that returns a Response or Promise<Response>.\n * Use as GET handler for app/robots.txt/route.ts. When baseUrl is omitted, pass apiKey to resolve from Portal.\n */\nexport function createRobots(config: RobotsConfig): () => Response | Promise<Response> {\n return function robots(): Response | Promise<Response> {\n const baseUrl = config.baseUrl\n if (baseUrl) {\n return buildRobotsResponse(baseUrl, config)\n }\n const apiKey = config.apiKey ?? (typeof process !== 'undefined' && process.env && (process.env.NEXT_PUBLIC_UPTRADE_API_KEY || process.env.UPTRADE_API_KEY))\n if (!apiKey) {\n return new Response('User-agent: *\\nDisallow: /', {\n status: 200,\n headers: { 'Content-Type': 'text/plain; charset=utf-8' },\n })\n }\n return getSiteConfig({ apiKey, apiUrl: config.apiUrl }).then((site) => {\n const url = site?.site_url ?? 'https://example.com'\n return buildRobotsResponse(url, config)\n })\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Site config from Portal (project-info) by API key.
|
|
3
|
+
* Resolves site_url and domain so consumers only need NEXT_PUBLIC_UPTRADE_API_KEY.
|
|
4
|
+
*/
|
|
5
|
+
interface SiteConfig {
|
|
6
|
+
site_url: string;
|
|
7
|
+
domain: string;
|
|
8
|
+
}
|
|
9
|
+
interface GetSiteConfigOptions {
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
apiUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Fetch site_url and domain from Portal project-info for the given API key.
|
|
15
|
+
* Uses in-memory cache (TTL 10 min) keyed by apiKey.
|
|
16
|
+
* Safe for Edge (middleware) and Node (route handlers).
|
|
17
|
+
*/
|
|
18
|
+
declare function getSiteConfig(options?: GetSiteConfigOptions): Promise<SiteConfig | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Clear in-memory site config cache (e.g. for tests).
|
|
21
|
+
*/
|
|
22
|
+
declare function clearSiteConfigCache(): void;
|
|
23
|
+
|
|
24
|
+
export { type GetSiteConfigOptions, type SiteConfig, clearSiteConfigCache, getSiteConfig };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Site config from Portal (project-info) by API key.
|
|
3
|
+
* Resolves site_url and domain so consumers only need NEXT_PUBLIC_UPTRADE_API_KEY.
|
|
4
|
+
*/
|
|
5
|
+
interface SiteConfig {
|
|
6
|
+
site_url: string;
|
|
7
|
+
domain: string;
|
|
8
|
+
}
|
|
9
|
+
interface GetSiteConfigOptions {
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
apiUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Fetch site_url and domain from Portal project-info for the given API key.
|
|
15
|
+
* Uses in-memory cache (TTL 10 min) keyed by apiKey.
|
|
16
|
+
* Safe for Edge (middleware) and Node (route handlers).
|
|
17
|
+
*/
|
|
18
|
+
declare function getSiteConfig(options?: GetSiteConfigOptions): Promise<SiteConfig | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Clear in-memory site config cache (e.g. for tests).
|
|
21
|
+
*/
|
|
22
|
+
declare function clearSiteConfigCache(): void;
|
|
23
|
+
|
|
24
|
+
export { type GetSiteConfigOptions, type SiteConfig, clearSiteConfigCache, getSiteConfig };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk7557OTHW_js = require('../chunk-7557OTHW.js');
|
|
4
|
+
require('../chunk-ZSMWDLMK.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "clearSiteConfigCache", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunk7557OTHW_js.clearSiteConfigCache; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "getSiteConfig", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunk7557OTHW_js.getSiteConfig; }
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.mjs"}
|
package/dist/sitemap/index.d.mts
CHANGED
|
@@ -29,8 +29,8 @@ interface SitemapEntry {
|
|
|
29
29
|
priority?: number;
|
|
30
30
|
}
|
|
31
31
|
interface SitemapConfig {
|
|
32
|
-
/** Base URL for the site (
|
|
33
|
-
baseUrl
|
|
32
|
+
/** Base URL for the site (optional when apiKey is set; then resolved from Portal project-info) */
|
|
33
|
+
baseUrl?: string;
|
|
34
34
|
/** Glob patterns to exclude (e.g., ['/admin/*', '/api/*']) */
|
|
35
35
|
exclude?: string[];
|
|
36
36
|
/** Default priority for pages */
|
package/dist/sitemap/index.d.ts
CHANGED
|
@@ -29,8 +29,8 @@ interface SitemapEntry {
|
|
|
29
29
|
priority?: number;
|
|
30
30
|
}
|
|
31
31
|
interface SitemapConfig {
|
|
32
|
-
/** Base URL for the site (
|
|
33
|
-
baseUrl
|
|
32
|
+
/** Base URL for the site (optional when apiKey is set; then resolved from Portal project-info) */
|
|
33
|
+
baseUrl?: string;
|
|
34
34
|
/** Glob patterns to exclude (e.g., ['/admin/*', '/api/*']) */
|
|
35
35
|
exclude?: string[];
|
|
36
36
|
/** Default priority for pages */
|
package/dist/sitemap/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkICHCPLRB_js = require('../chunk-ICHCPLRB.js');
|
|
4
|
+
var chunk7557OTHW_js = require('../chunk-7557OTHW.js');
|
|
4
5
|
require('../chunk-ZSMWDLMK.js');
|
|
5
6
|
var fs = require('fs');
|
|
6
7
|
var path = require('path');
|
|
@@ -143,7 +144,13 @@ async function syncSitemapToPortal(entries, apiUrl, apiKey, options) {
|
|
|
143
144
|
}
|
|
144
145
|
function createSitemap(config) {
|
|
145
146
|
return async () => {
|
|
146
|
-
const {
|
|
147
|
+
const { exclude = [], defaultChangeFrequency = "weekly" } = config;
|
|
148
|
+
let baseUrl = config.baseUrl;
|
|
149
|
+
if (!baseUrl) {
|
|
150
|
+
const apiKey = config.apiKey ?? process.env.UPTRADE_API_KEY ?? process.env.NEXT_PUBLIC_UPTRADE_API_KEY;
|
|
151
|
+
const site = await chunk7557OTHW_js.getSiteConfig({ apiKey, apiUrl: config.apiUrl });
|
|
152
|
+
baseUrl = site?.site_url ?? process.env.NEXT_PUBLIC_SITE_URL ?? "https://example.com";
|
|
153
|
+
}
|
|
147
154
|
const normalizedBaseUrl = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
148
155
|
const allExclusions = [
|
|
149
156
|
"/api/*",
|