1.2.0 • Published 1 year ago
microcms-ts-sdk v1.2.0
MicroCMS TypeScript SDK
This package is a wrapper for "microcms-js-sdk". More TYPE SAFE. 🛡️
Getting Started
install
install npm package.
npm i microcms-ts-sdk
# or
yarn add microcms-ts-sdk
How to use
Supported of "microcms-js-sdk". For more information on how to use this service, please click here.
Type safe usage
import { createClient } from 'microcms-ts-sdk';
type Category = {
slug: string;
name: string;
};
type Post = {
text: string;
category: MicroCMSRelation<Category>;
relatedArticles: MicroCMSRelation<Post>[];
};
type Endpoints = {
// List API
posts: MicroCMSListAPI<Post>;
categories: MicroCMSListAPI<Category>;
// Object API
pickup: MicroCMSObjectAPI<{
articles: MicroCMSRelation<Post>[];
}>;
};
// Initialize Client SDK.
const client = createClient<Endpoints>({
serviceDomain: 'YOUR_DOMAIN',
apiKey: 'YOUR_API_KEY'
});
client
.getList({
endpoint: 'posts' // type safe endpoint
})
.then((res) => {
// res: MicroCMSListResponse<Post>
console.log(res);
});
Feature
Support endpoint specification.
// The "contents" will be complemented.
client.getList({ endpoint: 'posts' });
// Error: Not in list format endpoint.
client.getList({ endpoint: 'posts' });
Support response types.
// getList response type
client.getList({ endpoint: 'posts' });
// {
// contents: {
// id: string;
// createdAt: string;
// updatedAt: string;
// publishedAt?: string;
// revisedAt?: string;
// text: string;
// category: {
// id: string;
// createdAt: string;
// updatedAt: string;
// publishedAt?: string;
// revisedAt?: string;
// slug: string;
// name: string;
// }
// relatedArticles: {...}[];
// }[];
// totalCount: number;
// limit: number;
// offset: number;
// }
// Set options "queries.fields"
client.getList({
endpoint: 'posts',
queries: {
fields: ['id', 'text', 'publishedAt', 'category.slug']
// ^ (keyof (Post & MicroCMSListContent))[]
}
});
// {
// contents: {
// id: string;
// publishedAt?: string;
// text: string;
// category: {
// slug: string;
// }
// }[];
// totalCount: number;
// limit: number;
// offset: number;
// }
Support request types.
// create response type
client.create({
endpoint: 'posts'
content: {
text: 'text',
category: 'CATEGORY_CONTENT_ID'
relatedArticles: ['CONTENTS_ID', 'CONTENTS_ID']
}
});
LICENSE
Apache-2.0
1.2.0
1 year ago
2.0.0-canary.0
1 year ago
1.2.0-canary.3
1 year ago
1.1.2
1 year ago
1.1.1
1 year ago
1.2.0-canary.2
1 year ago
1.2.0-canary.1
1 year ago
1.1.0
1 year ago
1.2.0-canary.0
1 year ago
1.1.0-canary.0
1 year ago
1.1.0-canary.2
1 year ago
1.1.0-canary.1
1 year ago
1.1.0-canary.3
1 year ago
1.0.4
1 year ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
0.7.0
2 years ago
0.6.0
2 years ago
0.5.0
2 years ago
0.4.3
2 years ago
0.4.2
2 years ago
0.4.1
3 years ago
0.4.0
3 years ago
0.3.0
3 years ago
0.2.3
3 years ago
0.2.2
3 years ago
0.2.1
3 years ago
0.2.0
3 years ago
0.1.1
3 years ago
0.1.0
3 years ago
0.1.0-beta.4
3 years ago