@seoblog/next 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/dist/index.d.ts +29 -0
- package/dist/index.js +35 -0
- package/package.json +26 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface RequestInit {
|
|
3
|
+
next?: {
|
|
4
|
+
revalidate?: number | false;
|
|
5
|
+
tags?: string[];
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export interface BlogPost {
|
|
10
|
+
id: string;
|
|
11
|
+
title: string;
|
|
12
|
+
slug: string;
|
|
13
|
+
metaTitle: string;
|
|
14
|
+
metaDescription: string;
|
|
15
|
+
excerpt: string;
|
|
16
|
+
tags: string[];
|
|
17
|
+
contentMd: string;
|
|
18
|
+
coverImageUrl: string | null;
|
|
19
|
+
publishedAt: string;
|
|
20
|
+
}
|
|
21
|
+
export interface SdkOptions {
|
|
22
|
+
apiKey: string;
|
|
23
|
+
/** Defaults to https://app.seoblog.ai — override for self-hosting or local dev */
|
|
24
|
+
apiUrl?: string;
|
|
25
|
+
/** ISR revalidation interval in seconds. Defaults to 3600. Pass 0 for no-store. */
|
|
26
|
+
revalidate?: number;
|
|
27
|
+
}
|
|
28
|
+
export declare function getPosts(options: SdkOptions): Promise<BlogPost[]>;
|
|
29
|
+
export declare function getPost(slug: string, options: SdkOptions): Promise<BlogPost | null>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const DEFAULT_API_URL = "https://app.seoblog.ai";
|
|
2
|
+
function buildHeaders(apiKey) {
|
|
3
|
+
return { Authorization: `Bearer ${apiKey}` };
|
|
4
|
+
}
|
|
5
|
+
function buildCache(revalidate) {
|
|
6
|
+
if (revalidate === 0)
|
|
7
|
+
return { revalidate: 0 };
|
|
8
|
+
return { revalidate };
|
|
9
|
+
}
|
|
10
|
+
export async function getPosts(options) {
|
|
11
|
+
const { apiKey, apiUrl = DEFAULT_API_URL, revalidate = 3600 } = options;
|
|
12
|
+
const res = await fetch(`${apiUrl}/api/v1/posts`, {
|
|
13
|
+
headers: buildHeaders(apiKey),
|
|
14
|
+
next: buildCache(revalidate),
|
|
15
|
+
});
|
|
16
|
+
if (!res.ok) {
|
|
17
|
+
throw new Error(`[seoblog] Failed to fetch posts: ${res.status}`);
|
|
18
|
+
}
|
|
19
|
+
const data = (await res.json());
|
|
20
|
+
return data.posts;
|
|
21
|
+
}
|
|
22
|
+
export async function getPost(slug, options) {
|
|
23
|
+
const { apiKey, apiUrl = DEFAULT_API_URL, revalidate = 3600 } = options;
|
|
24
|
+
const res = await fetch(`${apiUrl}/api/v1/posts/${encodeURIComponent(slug)}`, {
|
|
25
|
+
headers: buildHeaders(apiKey),
|
|
26
|
+
next: buildCache(revalidate),
|
|
27
|
+
});
|
|
28
|
+
if (res.status === 404)
|
|
29
|
+
return null;
|
|
30
|
+
if (!res.ok) {
|
|
31
|
+
throw new Error(`[seoblog] Failed to fetch post: ${res.status}`);
|
|
32
|
+
}
|
|
33
|
+
const data = (await res.json());
|
|
34
|
+
return data.post;
|
|
35
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@seoblog/next",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Fetch AI-generated blog posts from your SEO Blog dashboard into your Next.js site.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": ["dist"],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"dev": "tsc --watch"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"typescript": "^5.9.3"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"next": ">=14.0.0"
|
|
25
|
+
}
|
|
26
|
+
}
|