@23blocks/block-content 2.1.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +247 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,247 @@
1
+ # @23blocks/block-content
2
+
3
+ Content block for the 23blocks SDK - blog posts, comments, categories, and tags.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@23blocks/block-content.svg)](https://www.npmjs.com/package/@23blocks/block-content)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @23blocks/block-content @23blocks/transport-http
12
+ ```
13
+
14
+ ## Overview
15
+
16
+ This package provides content management functionality including:
17
+
18
+ - **Posts** - Blog posts and articles
19
+ - **Comments** - User comments on posts
20
+ - **Categories** - Content categorization
21
+ - **Tags** - Content tagging
22
+
23
+ ## Quick Start
24
+
25
+ ```typescript
26
+ import { createHttpTransport } from '@23blocks/transport-http';
27
+ import { createContentBlock } from '@23blocks/block-content';
28
+
29
+ const transport = createHttpTransport({
30
+ baseUrl: 'https://api.yourapp.com',
31
+ headers: () => {
32
+ const token = localStorage.getItem('access_token');
33
+ return token ? { Authorization: `Bearer ${token}` } : {};
34
+ },
35
+ });
36
+
37
+ const content = createContentBlock(transport, {
38
+ apiKey: 'your-api-key',
39
+ });
40
+
41
+ // List published posts
42
+ const { data: posts } = await content.posts.list({
43
+ status: 'published',
44
+ limit: 10,
45
+ });
46
+
47
+ posts.forEach((post) => {
48
+ console.log(post.title, post.publishedAt);
49
+ });
50
+ ```
51
+
52
+ ## Services
53
+
54
+ ### posts - Post Management
55
+
56
+ ```typescript
57
+ // List posts
58
+ const { data: posts, meta } = await content.posts.list({
59
+ limit: 20,
60
+ categoryId: 'category-id',
61
+ status: 'published',
62
+ });
63
+
64
+ // Get post by ID
65
+ const post = await content.posts.get('post-id');
66
+
67
+ // Get post by slug
68
+ const post = await content.posts.getBySlug('my-post-slug');
69
+
70
+ // Create post
71
+ const newPost = await content.posts.create({
72
+ title: 'My New Post',
73
+ content: 'Post content here...',
74
+ excerpt: 'Short summary',
75
+ slug: 'my-new-post',
76
+ categoryId: 'category-id',
77
+ tagIds: ['tag-1', 'tag-2'],
78
+ status: 'draft',
79
+ });
80
+
81
+ // Update post
82
+ const updated = await content.posts.update('post-id', {
83
+ title: 'Updated Title',
84
+ status: 'published',
85
+ publishedAt: new Date().toISOString(),
86
+ });
87
+
88
+ // Delete post
89
+ await content.posts.delete('post-id');
90
+ ```
91
+
92
+ ### comments - Comment Management
93
+
94
+ ```typescript
95
+ // List comments for a post
96
+ const { data: comments } = await content.comments.list({
97
+ postId: 'post-id',
98
+ status: 'approved',
99
+ });
100
+
101
+ // Get comment by ID
102
+ const comment = await content.comments.get('comment-id');
103
+
104
+ // Create comment
105
+ const newComment = await content.comments.create({
106
+ postId: 'post-id',
107
+ content: 'Great article!',
108
+ authorName: 'John Doe',
109
+ authorEmail: 'john@example.com',
110
+ });
111
+
112
+ // Update comment
113
+ const updated = await content.comments.update('comment-id', {
114
+ status: 'approved',
115
+ });
116
+
117
+ // Delete comment
118
+ await content.comments.delete('comment-id');
119
+ ```
120
+
121
+ ### categories - Category Management
122
+
123
+ ```typescript
124
+ // List categories
125
+ const { data: categories } = await content.categories.list();
126
+
127
+ // Get category by ID
128
+ const category = await content.categories.get('category-id');
129
+
130
+ // Create category
131
+ const newCategory = await content.categories.create({
132
+ name: 'Technology',
133
+ slug: 'technology',
134
+ description: 'Technology related posts',
135
+ parentId: null,
136
+ });
137
+
138
+ // Update category
139
+ const updated = await content.categories.update('category-id', {
140
+ description: 'Updated description',
141
+ });
142
+
143
+ // Delete category
144
+ await content.categories.delete('category-id');
145
+ ```
146
+
147
+ ### tags - Tag Management
148
+
149
+ ```typescript
150
+ // List tags
151
+ const { data: tags } = await content.tags.list();
152
+
153
+ // Get tag by ID
154
+ const tag = await content.tags.get('tag-id');
155
+
156
+ // Create tag
157
+ const newTag = await content.tags.create({
158
+ name: 'JavaScript',
159
+ slug: 'javascript',
160
+ });
161
+
162
+ // Update tag
163
+ const updated = await content.tags.update('tag-id', {
164
+ name: 'TypeScript',
165
+ slug: 'typescript',
166
+ });
167
+
168
+ // Delete tag
169
+ await content.tags.delete('tag-id');
170
+ ```
171
+
172
+ ## Types
173
+
174
+ ```typescript
175
+ import type {
176
+ Post,
177
+ Comment,
178
+ Category,
179
+ Tag,
180
+ CreatePostRequest,
181
+ UpdatePostRequest,
182
+ CreateCommentRequest,
183
+ CreateCategoryRequest,
184
+ CreateTagRequest,
185
+ ListPostsParams,
186
+ } from '@23blocks/block-content';
187
+ ```
188
+
189
+ ### Post
190
+
191
+ | Property | Type | Description |
192
+ |----------|------|-------------|
193
+ | `id` | `string` | Post ID |
194
+ | `uniqueId` | `string` | Unique identifier |
195
+ | `title` | `string` | Post title |
196
+ | `content` | `string` | Post content (HTML/markdown) |
197
+ | `excerpt` | `string` | Short summary |
198
+ | `slug` | `string` | URL-friendly slug |
199
+ | `status` | `string` | draft, published, archived |
200
+ | `categoryId` | `string` | Category ID |
201
+ | `authorId` | `string` | Author user ID |
202
+ | `publishedAt` | `Date` | Publication date |
203
+ | `tags` | `Tag[]` | Associated tags |
204
+
205
+ ### Comment
206
+
207
+ | Property | Type | Description |
208
+ |----------|------|-------------|
209
+ | `id` | `string` | Comment ID |
210
+ | `postId` | `string` | Parent post ID |
211
+ | `content` | `string` | Comment content |
212
+ | `authorName` | `string` | Author name |
213
+ | `authorEmail` | `string` | Author email |
214
+ | `status` | `string` | pending, approved, spam |
215
+ | `parentId` | `string` | Parent comment ID (for replies) |
216
+
217
+ ## Error Handling
218
+
219
+ ```typescript
220
+ import { isBlockErrorException, ErrorCodes } from '@23blocks/contracts';
221
+
222
+ try {
223
+ await content.posts.get('invalid-id');
224
+ } catch (error) {
225
+ if (isBlockErrorException(error)) {
226
+ switch (error.code) {
227
+ case ErrorCodes.NOT_FOUND:
228
+ console.log('Post not found');
229
+ break;
230
+ case ErrorCodes.UNAUTHORIZED:
231
+ console.log('Not authorized to view this post');
232
+ break;
233
+ }
234
+ }
235
+ }
236
+ ```
237
+
238
+ ## Related Packages
239
+
240
+ - [`@23blocks/block-files`](https://www.npmjs.com/package/@23blocks/block-files) - File uploads for media
241
+ - [`@23blocks/angular`](https://www.npmjs.com/package/@23blocks/angular) - Angular integration
242
+ - [`@23blocks/react`](https://www.npmjs.com/package/@23blocks/react) - React integration
243
+ - [`@23blocks/sdk`](https://www.npmjs.com/package/@23blocks/sdk) - Full SDK package
244
+
245
+ ## License
246
+
247
+ MIT - Copyright (c) 2024 23blocks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@23blocks/block-content",
3
- "version": "2.1.0",
3
+ "version": "3.0.1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",