Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@burdy-cms/web-utils

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@burdy-cms/web-utils - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

39

dist/api/burdy-api.d.ts

@@ -1,11 +0,46 @@

import { IBurdyPage } from '../types';
import { IBurdyPage, IBurdyTag } from '../types';
declare type GetPageOptions = {
token?: string;
draft?: boolean;
includeChildren?: boolean;
perPage?: number;
page?: number;
versionId?: number | string;
relationsDepth?: number;
xContentToken?: string;
};
declare type SearchPostsOptions = {
draft?: boolean;
type?: string;
contentTypeName?: string;
search?: string;
parent?: string;
onlyOrphans?: boolean;
slugPath?: string;
tags?: string;
expand?: string;
compile?: boolean;
relationsDepth?: number;
orderBy?: string;
order?: 'ASC' | 'DESC';
limit?: number;
page?: number;
xContentToken: string;
};
declare type SearchTagsOptions = {
search?: string;
parent?: string;
onlyOrphans?: boolean;
slugPath?: string;
expand?: string;
orderBy?: string;
order?: 'ASC' | 'DESC';
limit?: number;
page?: number;
xContentToken: string;
};
export declare const BurdyApi: {
getPage: <T = any>(url: string, options?: GetPageOptions) => Promise<IBurdyPage<T>>;
searchPages: <T_1 = any>(host: string, options: SearchPostsOptions) => Promise<IBurdyPage<T_1>[]>;
searchTags: (host: string, options: SearchTagsOptions) => Promise<IBurdyTag[]>;
};
export {};

@@ -19,3 +19,2 @@ "use strict";

getPage: (url, options) => __awaiter(void 0, void 0, void 0, function* () {
const token = options === null || options === void 0 ? void 0 : options.token;
const headers = {};

@@ -29,12 +28,86 @@ const params = {};

params.page = options.page;
if (token) {
headers.token = token;
params.allowUnpublished = true;
}
if (options === null || options === void 0 ? void 0 : options.xContentToken)
headers['x-content-token'] = options === null || options === void 0 ? void 0 : options.xContentToken;
if (options === null || options === void 0 ? void 0 : options.versionId)
params.versionId = options === null || options === void 0 ? void 0 : options.versionId;
if (options === null || options === void 0 ? void 0 : options.relationsDepth)
params.relationsDepth = options === null || options === void 0 ? void 0 : options.relationsDepth;
if (options === null || options === void 0 ? void 0 : options.draft)
params.draft = options === null || options === void 0 ? void 0 : options.draft;
const { data: page } = yield axios_1.default.get(url, {
params,
headers,
headers
});
return page;
}),
searchPages: (host, options) => __awaiter(void 0, void 0, void 0, function* () {
const headers = {};
const params = {};
if (options === null || options === void 0 ? void 0 : options.xContentToken)
headers['x-content-token'] = options === null || options === void 0 ? void 0 : options.xContentToken;
if (options === null || options === void 0 ? void 0 : options.draft)
params.draft = true;
if (options === null || options === void 0 ? void 0 : options.type)
params.type = options.type;
if (options === null || options === void 0 ? void 0 : options.contentTypeName)
params.contentTypeName = options.contentTypeName;
if (options === null || options === void 0 ? void 0 : options.search)
params.search = options.search;
if (options === null || options === void 0 ? void 0 : options.parent)
params.parent = options.parent;
if (options === null || options === void 0 ? void 0 : options.onlyOrphans)
params.onlyOrphans = options.onlyOrphans;
if (options === null || options === void 0 ? void 0 : options.slugPath)
params.slugPath = options.slugPath;
if (options === null || options === void 0 ? void 0 : options.tags)
params.tags = options.tags;
if (options === null || options === void 0 ? void 0 : options.expand)
params.expand = options.expand;
if (options === null || options === void 0 ? void 0 : options.compile)
params.compile = options.compile;
if (options === null || options === void 0 ? void 0 : options.relationsDepth)
params.relationsDepth = options.relationsDepth;
if (options === null || options === void 0 ? void 0 : options.orderBy)
params.orderBy = options.orderBy;
if (options === null || options === void 0 ? void 0 : options.order)
params.order = options.order;
if (options === null || options === void 0 ? void 0 : options.limit)
params.limit = options.limit;
if (options === null || options === void 0 ? void 0 : options.page)
params.page = options.page;
const { data: pages } = yield axios_1.default.get(`${host}/api/search/posts`, {
params,
headers
});
return pages;
}),
searchTags: (host, options) => __awaiter(void 0, void 0, void 0, function* () {
const headers = {};
const params = {};
if (options === null || options === void 0 ? void 0 : options.xContentToken)
headers['x-content-token'] = options === null || options === void 0 ? void 0 : options.xContentToken;
if (options === null || options === void 0 ? void 0 : options.search)
params.search = options.search;
if (options === null || options === void 0 ? void 0 : options.parent)
params.parent = options.parent;
if (options === null || options === void 0 ? void 0 : options.onlyOrphans)
params.onlyOrphans = options.onlyOrphans;
if (options === null || options === void 0 ? void 0 : options.slugPath)
params.slugPath = options.slugPath;
if (options === null || options === void 0 ? void 0 : options.expand)
params.expand = options.expand;
if (options === null || options === void 0 ? void 0 : options.orderBy)
params.orderBy = options.orderBy;
if (options === null || options === void 0 ? void 0 : options.order)
params.order = options.order;
if (options === null || options === void 0 ? void 0 : options.limit)
params.limit = options.limit;
if (options === null || options === void 0 ? void 0 : options.page)
params.page = options.page;
const { data: tags } = yield axios_1.default.get(`${host}/api/search/posts`, {
params,
headers
});
return tags;
})
};

7

dist/rewrites/build-path.d.ts

@@ -1,2 +0,5 @@

import { Rewrites, RewritesReturn } from '../types';
export declare const buildPath: <T>(path: string, map?: Rewrites<T>[], baseUrl?: string) => RewritesReturn<T>;
import { Key } from 'path-to-regexp';
import { Rewrites, RewritesMap, RewritesReturn } from '../types';
export declare const rewrite: (string: string, params?: Record<Key['name'], string | undefined>) => string;
export declare const matchAndRewrite: (path: string, map: Rewrites[]) => string;
export declare const matchAndRewriteMap: <T>(path: string, map?: RewritesMap<T>[], baseUrl?: string) => RewritesReturn<T>;

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.buildPath = void 0;
exports.matchAndRewriteMap = exports.matchAndRewrite = exports.rewrite = void 0;
const path_to_regexp_1 = require("path-to-regexp");

@@ -13,3 +13,11 @@ const deepcopy_1 = __importDefault(require("deepcopy"));

};
const buildPath = (path, map = [], baseUrl = '') => {
const rewrite = (string, params = {}) => {
let tmpString = string;
Object.keys(params).forEach((key) => {
tmpString = tmpString.replace(new RegExp(escapeRegExp(`{${key}}`), 'g'), params[key] || '');
});
return tmpString;
};
exports.rewrite = rewrite;
const matchAndRewrite = (path, map) => {
let resultArray;

@@ -25,2 +33,22 @@ let keys = [];

if (!rule) {
return null;
}
const params = {};
keys.forEach((key, index) => {
params[key.name] = resultArray === null || resultArray === void 0 ? void 0 : resultArray[index + 1];
});
return (0, exports.rewrite)((rule === null || rule === void 0 ? void 0 : rule.rewrite) || '', params);
};
exports.matchAndRewrite = matchAndRewrite;
const matchAndRewriteMap = (path, map = [], baseUrl = '') => {
let resultArray;
let keys = [];
map = (0, deepcopy_1.default)(map);
const rule = map.find((rule) => {
keys = [];
const regexp = (0, path_to_regexp_1.pathToRegexp)(rule.source, keys);
resultArray = regexp.exec(path);
return !!resultArray;
});
if (!rule) {
return Object.keys(map).reduce((previousValue, currentValue) => (Object.assign(Object.assign({}, previousValue), { [currentValue]: null })), {});

@@ -32,15 +60,8 @@ }

});
const rewrite = (string, params = {}) => {
let tmpString = string;
Object.keys(params).forEach((key) => {
tmpString = tmpString.replace(new RegExp(escapeRegExp(`{${key}}`), 'g'), params[key] || '');
});
return tmpString;
};
Object.keys(rule.rewrites || {}).forEach((key) => {
var _a;
rule.rewrites = Object.assign(Object.assign({}, (rule.rewrites || {})), { [key]: baseUrl.replace(/\/$/i, '') + rewrite((_a = rule.rewrites) === null || _a === void 0 ? void 0 : _a[key], params) });
rule.rewrites = Object.assign(Object.assign({}, (rule.rewrites || {})), { [key]: baseUrl.replace(/\/$/i, '') + (0, exports.rewrite)((_a = rule.rewrites) === null || _a === void 0 ? void 0 : _a[key], params) });
});
return rule.rewrites;
};
exports.buildPath = buildPath;
exports.matchAndRewriteMap = matchAndRewriteMap;

@@ -8,4 +8,6 @@ "use strict";

getRewriteMap: () => options.rewriteMap,
rewrite: (path) => (0, build_path_1.buildPath)(path, options.rewriteMap, (options === null || options === void 0 ? void 0 : options.origin) || ''),
getRewrite: () => options.rewrite,
rewrite: (path) => (0, build_path_1.matchAndRewrite)(path, options.rewrite),
rewriteMap: (path) => (0, build_path_1.matchAndRewriteMap)(path, options.rewriteMap, (options === null || options === void 0 ? void 0 : options.origin) || '')
});
exports.createRewrites = createRewrites;
export * from './model';
export declare type Rewrites<T extends {}> = {
export declare type Rewrites = {
source: string;
rewrite: string;
};
export declare type RewritesMap<T extends {}> = {
source: string;
rewrites: {

@@ -10,3 +14,4 @@ [key in keyof T]: string;

origin?: string;
rewriteMap: Rewrites<T>[];
rewrite?: Rewrites[];
rewriteMap?: RewritesMap<T>[];
};

@@ -17,5 +22,7 @@ export declare type RewritesReturn<T> = {

export declare type RewritesObject<T extends {}> = {
rewrite: (path: string) => RewritesReturn<T>;
rewriteMap: (path: string) => RewritesReturn<T>;
rewrite: (path: string) => string | undefined;
getOrigin: () => string | undefined;
getRewriteMap: () => Rewrites<T>[];
getRewrite: () => Rewrites[];
getRewriteMap: () => RewritesMap<T>[];
};

@@ -1,19 +0,29 @@

export interface IBurdyPage<T extends {}> {
export declare type IBurdyAuthor = {
firstName?: string;
lastName?: string;
};
export declare type IBurdyContentType = {
name: string;
type: string;
fields?: any[];
};
export interface IBurdyPage<T extends {} = any> {
id: number;
name: string;
type: string;
slug: string;
slugPath: string;
createdAt: Date;
updatedAt: Date;
contentType: {
name: string;
type: string;
};
author: {
firstName: string;
lastName: string;
};
meta: {
publishedAt?: Date;
publishedFrom?: Date;
publishedUntil?: Date;
status?: string;
parent?: IBurdyPage;
contentType?: IBurdyContentType;
author?: IBurdyAuthor;
meta?: {
content: T;
};
tags: IBurdyTag[];
} & any;
tags?: IBurdyTag[];
}

@@ -25,3 +35,4 @@ export interface IBurdyTag {

slugPath: string;
parent: Omit<IBurdyTag, 'parent'>;
author?: IBurdyAuthor;
parent?: Omit<IBurdyTag, 'parent'>;
}

@@ -28,0 +39,0 @@ export interface IBurdyImage {

{
"name": "@burdy-cms/web-utils",
"version": "1.0.1",
"version": "1.1.0",
"description": "Burdy web utilities",

@@ -28,9 +28,9 @@ "author": "Team Burdy <team@burdy.io>",

},
"devDependencies": {
"@types/prismjs": "^1.16.6"
},
"peerDependencies": {
"axios": ">= 0.21"
},
"devDependencies": {
"@types/prismjs": "^1.16.6"
},
"gitHead": "b8ebbc3f4a4c32b1de11658c1bbaf90cabb724c0"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc