Comparing version 1.2.0 to 1.3.0
import { Blog } from '../types'; | ||
export declare class BlogClient { | ||
private _key; | ||
private _axios; | ||
constructor(key: string); | ||
@@ -5,0 +6,0 @@ private _decompressIndex; |
@@ -16,4 +16,5 @@ "use strict"; | ||
exports.BlogClient = void 0; | ||
const axios_1 = __importDefault(require("axios")); | ||
const slugify_1 = __importDefault(require("slugify")); | ||
const transliteration_1 = __importDefault(require("transliteration")); | ||
const transliteration_1 = require("transliteration"); | ||
class BlogClient { | ||
@@ -24,2 +25,5 @@ constructor(key) { | ||
this._key = key; | ||
this._axios = axios_1.default.create({ | ||
baseURL: 'https://cdn.seobotai.com', | ||
}); | ||
} | ||
@@ -39,3 +43,3 @@ _decompressIndex(short) { | ||
title: short.c.t, | ||
slug: short.c.s || (0, slugify_1.default)(transliteration_1.default.transliterate(short.c.t), { lower: true, strict: true }), | ||
slug: short.c.s || (0, slugify_1.default)((0, transliteration_1.transliterate)(short.c.t), { lower: true, strict: true }), | ||
} | ||
@@ -45,3 +49,3 @@ : null, | ||
title: i.t, | ||
slug: i.s || (0, slugify_1.default)(transliteration_1.default.transliterate(i.t), { lower: true, strict: true }), | ||
slug: i.s || (0, slugify_1.default)((0, transliteration_1.transliterate)(i.t), { lower: true, strict: true }), | ||
})), | ||
@@ -52,5 +56,4 @@ }; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield fetch(`https://cdn.seobotai.com/${this._key}/system/base.json`); | ||
const index = (yield response.json()); | ||
return index.map(i => this._decompressIndex(i)).sort((a, b) => b.createdAt.localeCompare(a.createdAt)); | ||
const { data } = yield this._axios.get(`/${this._key}/system/base.json`); | ||
return data.map(i => this._decompressIndex(i)).sort((a, b) => b.createdAt.localeCompare(a.createdAt)); | ||
}); | ||
@@ -60,5 +63,4 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const postData = yield fetch(`https://cdn.seobotai.com/${this._key}/blog/${id}.json`); | ||
const post = (yield postData.json()); | ||
return post; | ||
const { data } = yield this._axios.get(`/${this._key}/blog/${id}.json`); | ||
return data; | ||
}); | ||
@@ -68,14 +70,9 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const base = yield this._fetchIndex(); | ||
const start = page * limit; | ||
const end = start + limit; | ||
return { | ||
articles: base.slice(start, end), | ||
total: base.length, | ||
}; | ||
} | ||
catch (_a) { | ||
return { total: 0, articles: [] }; | ||
} | ||
const base = yield this._fetchIndex(); | ||
const start = page * limit; | ||
const end = start + limit; | ||
return { | ||
articles: base.slice(start, end), | ||
total: base.length, | ||
}; | ||
}); | ||
@@ -85,15 +82,10 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const base = yield this._fetchIndex(); | ||
const categoryIds = base.filter(i => { var _a; return ((_a = i.category) === null || _a === void 0 ? void 0 : _a.slug) == slug; }).sort((a, b) => b.createdAt.localeCompare(a.createdAt)); | ||
const start = page * limit; | ||
const end = start + limit; | ||
return { | ||
articles: categoryIds.slice(start, end), | ||
total: categoryIds.length, | ||
}; | ||
} | ||
catch (_a) { | ||
return { total: 0, articles: [] }; | ||
} | ||
const base = yield this._fetchIndex(); | ||
const categoryIds = base.filter(i => { var _a; return ((_a = i.category) === null || _a === void 0 ? void 0 : _a.slug) == slug; }).sort((a, b) => b.createdAt.localeCompare(a.createdAt)); | ||
const start = page * limit; | ||
const end = start + limit; | ||
return { | ||
articles: categoryIds.slice(start, end), | ||
total: categoryIds.length, | ||
}; | ||
}); | ||
@@ -103,15 +95,10 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const base = yield this._fetchIndex(); | ||
const tags = base.filter(i => i.tags.some(item => (item === null || item === void 0 ? void 0 : item.slug) === slug)).sort((a, b) => b.createdAt.localeCompare(a.createdAt)); | ||
const start = page * limit; | ||
const end = start + limit; | ||
return { | ||
articles: tags.slice(start, end), | ||
total: tags.length, | ||
}; | ||
} | ||
catch (_a) { | ||
return { total: 0, articles: [] }; | ||
} | ||
const base = yield this._fetchIndex(); | ||
const tags = base.filter(i => i.tags.some(item => (item === null || item === void 0 ? void 0 : item.slug) === slug)).sort((a, b) => b.createdAt.localeCompare(a.createdAt)); | ||
const start = page * limit; | ||
const end = start + limit; | ||
return { | ||
articles: tags.slice(start, end), | ||
total: tags.length, | ||
}; | ||
}); | ||
@@ -118,0 +105,0 @@ } |
{ | ||
"name": "seobot", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Client library for the SEObot API", | ||
@@ -16,9 +16,16 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc" | ||
"build": "tsc", | ||
"test": "jest", | ||
"test:watch": "jest --watch" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.14", | ||
"jest": "^29.7.0", | ||
"jest-fetch-mock": "^3.0.3", | ||
"prettier": "^3.1.0", | ||
"ts-jest": "^29.2.5", | ||
"typescript": "^5.2.2" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.7.9", | ||
"slugify": "^1.6.6", | ||
@@ -25,0 +32,0 @@ "transliteration": "^2.3.5" |
@@ -80,2 +80,3 @@ # [SEObot](https://seobotai.com/?utm_source=github) Blog API Client library | ||
html: string; | ||
markdown: string; | ||
outline: string; | ||
@@ -82,0 +83,0 @@ deleted: boolean; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
124
0
14925
3
6
309
+ Addedaxios@^1.7.9
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@1.7.9(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedproxy-from-env@1.1.0(transitive)