Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
microcms-lib
Advanced tools
Readme
Export the MicroCMS schema file and save it in a folder.
If you use microcms-typescript
and execute the command as follows, TypeScript types will be generated.
yarn add -D microcms-typescript
microcms-typescript schema types/cms-types.ts
Import the MicroCMS class and set the EndPoints.
import type { EndPoints } from './types/cms-types';
const cms = new MicroCMS<EndPoints>({service,...keys})
interface GetOptions<T> {
draftKey?: string;
fields?: ReadonlyArray<T>;
depth?: number;
globalKey?: boolean;
}
interface GetsOptions<T> {
draftKey?: string;
limit?: number;
offset?: number;
orders?: string;
q?: string;
fields?: T[];
ids?: string;
filters?: string;
depth?: number;
globalKey?: boolean;
}
class MicroCMS {
// Constructor
constructor(options: {
service: string;
apiKey?: string;
apiWriteKey?: string;
apiGlobalKey?: string;
});
// Get a single content
get(endpoint:string ,id: string,options: GetOptions) : Promise<Contents>;
// Acquiring multiple contents
gets(endpoint:string ,id: string,options: GetsOptions) : Promise<{
contents: Contents[];
totalCount: number;
offset: number;
limit: number;
}>;
// Create new content
post(endpoint: string,params: Contents) : Promise<ID>;
// Create a new content with ID
put(endpoint: string, id: string, params: Contents) : Promise<ID>;
// Rewriting content
patch(endpoint: string, id: string, params: Contents) : Promise<ID>;
// Deleting content
del(id: string) : Promise<boolean>;
}
import type { EndPoints } from './types/cms-types';
import { MicroCMS } from '../src/index';
import { config } from 'dotenv';
config(); // .env
const cms = new MicroCMS<EndPoints>({
service: process.env.SERVICE!,
apiKey: process.env.APIKEY,
apiWriteKey: process.env.APIKEY_WRITE,
apiGlobalKey: process.env.APIKEY_GLOBAL,
});
const main = async () => {
// 10 write tests
for (let i = 0; i < 10; i++) {
await cms.post('contents', { title: 'Write' + i }).then((id) => console.log(`id:${id}`));
}
// loading content
const result = await cms.gets('contents', {
limit: 10000,
fields: ['id', 'title'],
orders: 'createdAt',
});
if (result) {
const { totalCount, contents } = result;
console.log(`Acquisition data: ${contents.length}/${totalCount}`);
contents.forEach(({ id, title }) => {
console.log(id, title);
});
}
// batch deletion
if (result)
for (let i = 0; i < result.contents.length; i++) {
const ps = new Set();
const p = cms
.del('contents', result.contents[i]['id'])
.then((v) => (v ? console.log(i) : false));
ps.add(p);
if (ps.size > 20) {
await Promise.all(ps);
ps.clear();
}
}
};
main();
FAQs
Export the MicroCMS schema file and save it in a folder. Execute the command as follows to generate the TypeScript types.
We found that microcms-lib demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).