@webbyon/promptly-sdk
v1.0.1
Published
Promptly AI CMS SDK for JavaScript/TypeScript
Readme
@webbyon/promptly-sdk
Promptly AI CMS SDK for JavaScript/TypeScript
Installation
npm install @webbyon/promptly-sdkQuick Start
import { Promptly } from '@webbyon/promptly-sdk';
const client = new Promptly({
tenantId: 'demo',
baseUrl: 'https://promptly.webbyon.com',
});API Reference
Boards (게시판)
// 게시판 목록
const boards = await client.boards.list();
// Returns: Board[]
// 게시판 상세
const board = await client.boards.get('first'); // slug or id
// Returns: Board
// 게시판 글 목록
const posts = await client.boards.listPosts('first', {
page: 1,
per_page: 10,
search: '검색어', // optional
});
// Returns: { data: BoardPost[], meta: { current_page, last_page, per_page, total } }
// 글 상세
const post = await client.boards.getPost(1);
// Returns: BoardPost
// 댓글 목록
const comments = await client.boards.listComments(1);
// Returns: BoardComment[]Blog (블로그)
// 블로그 글 목록
const posts = await client.blog.list({
page: 1,
per_page: 10,
category: 'news', // optional
tag: 'featured', // optional
});
// Returns: { data: BlogPost[], meta: {...} }
// 블로그 글 상세
const post = await client.blog.get('post-slug');
// Returns: BlogPostShop (쇼핑)
// 상품 목록
const products = await client.shop.listProducts({
page: 1,
per_page: 10,
category: 'electronics', // optional
is_featured: true, // optional
});
// Returns: { data: Product[], meta: {...} }
// 상품 상세
const product = await client.shop.getProduct('product-slug');
// Returns: Product
// 카테고리 목록
const categories = await client.shop.listCategories();
// Returns: ProductCategory[]
// 장바구니 조회
const cart = await client.shop.getCart();
// Returns: Cart
// 장바구니 추가
await client.shop.addToCart({
product_id: 1,
quantity: 2,
variant_id: 10, // optional
});
// 주문 목록
const orders = await client.shop.listOrders();
// Returns: { data: Order[], meta: {...} }Auth (인증)
// 로그인
const response = await client.auth.login({
email: '[email protected]',
password: 'password',
});
// Returns: { member: Member, token: string }
// 회원가입
await client.auth.register({
name: '홍길동',
email: '[email protected]',
password: 'password',
password_confirmation: 'password',
});
// 로그아웃
await client.auth.logout();
// 내 정보
const me = await client.auth.me();
// Returns: Member
// 인증 여부 확인
client.isAuthenticated(); // true or falseForms (폼)
// 폼 목록
const forms = await client.forms.list();
// Returns: Form[]
// 폼 상세
const form = await client.forms.get('contact');
// Returns: Form
// 폼 제출
await client.forms.submit('contact', {
name: '홍길동',
email: '[email protected]',
message: '문의 내용',
});Media (미디어)
// 파일 업로드 (인증 필요)
const media = await client.media.upload(file);
// Returns: Media
// 내 미디어 목록
const mediaList = await client.media.list();
// Returns: { data: Media[], meta: {...} }Types
interface Board {
id: number;
slug: string;
name: string;
description?: string;
is_active: boolean;
created_at: string;
}
interface BoardPost {
id: number;
title: string;
content: string;
excerpt?: string;
author: string;
views: number;
is_notice: boolean;
created_at: string;
}
interface BlogPost {
id: number;
slug: string;
title: string;
content: string;
excerpt?: string;
featured_image?: string;
category?: string;
tags?: string[];
is_published: boolean;
published_at?: string;
view_count: number;
created_at: string;
}
interface Product {
id: number;
slug: string;
name: string;
description?: string;
price: number;
compare_price?: number;
thumbnail?: string;
images?: string[];
status: 'draft' | 'active' | 'inactive';
is_featured: boolean;
in_stock?: boolean;
created_at: string;
}
interface Member {
id: number;
name: string;
email: string;
phone?: string;
avatar?: string;
is_active: boolean;
created_at: string;
}React Example
import { useState, useEffect } from 'react';
import { Promptly } from '@webbyon/promptly-sdk';
const client = new Promptly({
tenantId: 'demo',
baseUrl: 'https://promptly.webbyon.com',
});
function BoardPosts() {
const [posts, setPosts] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
client.boards.listPosts('first')
.then(res => setPosts(res.data))
.finally(() => setLoading(false));
}, []);
if (loading) return <div>Loading...</div>;
return (
<table>
<thead>
<tr>
<th>제목</th>
<th>작성자</th>
<th>조회수</th>
<th>작성일</th>
</tr>
</thead>
<tbody>
{posts.map(post => (
<tr key={post.id}>
<td>{post.title}</td>
<td>{post.author}</td>
<td>{post.views}</td>
<td>{new Date(post.created_at).toLocaleDateString()}</td>
</tr>
))}
</tbody>
</table>
);
}License
MIT
