@23blocks/block-content 1.0.4 → 2.0.0

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 (76) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.esm.js +577 -0
  3. package/dist/src/index.d.ts +7 -0
  4. package/dist/src/index.d.ts.map +1 -0
  5. package/dist/src/lib/block-content.d.ts +2 -0
  6. package/dist/src/lib/block-content.d.ts.map +1 -0
  7. package/dist/src/lib/content.block.d.ts +15 -0
  8. package/dist/src/lib/content.block.d.ts.map +1 -0
  9. package/dist/src/lib/mappers/category.mapper.d.ts +4 -0
  10. package/dist/src/lib/mappers/category.mapper.d.ts.map +1 -0
  11. package/dist/src/lib/mappers/comment.mapper.d.ts +4 -0
  12. package/dist/src/lib/mappers/comment.mapper.d.ts.map +1 -0
  13. package/dist/{lib/mappers/index.js → src/lib/mappers/index.d.ts} +1 -2
  14. package/dist/src/lib/mappers/index.d.ts.map +1 -0
  15. package/dist/src/lib/mappers/post.mapper.d.ts +4 -0
  16. package/dist/src/lib/mappers/post.mapper.d.ts.map +1 -0
  17. package/dist/src/lib/mappers/tag.mapper.d.ts +4 -0
  18. package/dist/src/lib/mappers/tag.mapper.d.ts.map +1 -0
  19. package/dist/src/lib/mappers/utils.d.ts +29 -0
  20. package/dist/src/lib/mappers/utils.d.ts.map +1 -0
  21. package/dist/src/lib/services/categories.service.d.ts +15 -0
  22. package/dist/src/lib/services/categories.service.d.ts.map +1 -0
  23. package/dist/src/lib/services/comments.service.d.ts +15 -0
  24. package/dist/src/lib/services/comments.service.d.ts.map +1 -0
  25. package/dist/{lib/services/index.js → src/lib/services/index.d.ts} +1 -2
  26. package/dist/src/lib/services/index.d.ts.map +1 -0
  27. package/dist/src/lib/services/posts.service.d.ts +20 -0
  28. package/dist/src/lib/services/posts.service.d.ts.map +1 -0
  29. package/dist/src/lib/services/tags.service.d.ts +13 -0
  30. package/dist/src/lib/services/tags.service.d.ts.map +1 -0
  31. package/dist/src/lib/types/category.d.ts +51 -0
  32. package/dist/src/lib/types/category.d.ts.map +1 -0
  33. package/dist/src/lib/types/comment.d.ts +59 -0
  34. package/dist/src/lib/types/comment.d.ts.map +1 -0
  35. package/dist/{lib/types/index.js → src/lib/types/index.d.ts} +1 -2
  36. package/dist/src/lib/types/index.d.ts.map +1 -0
  37. package/dist/src/lib/types/post.d.ts +84 -0
  38. package/dist/src/lib/types/post.d.ts.map +1 -0
  39. package/dist/src/lib/types/tag.d.ts +37 -0
  40. package/dist/src/lib/types/tag.d.ts.map +1 -0
  41. package/package.json +10 -8
  42. package/dist/index.js +0 -7
  43. package/dist/index.js.map +0 -1
  44. package/dist/lib/block-content.js +0 -5
  45. package/dist/lib/block-content.js.map +0 -1
  46. package/dist/lib/content.block.js +0 -22
  47. package/dist/lib/content.block.js.map +0 -1
  48. package/dist/lib/mappers/category.mapper.js +0 -38
  49. package/dist/lib/mappers/category.mapper.js.map +0 -1
  50. package/dist/lib/mappers/comment.mapper.js +0 -43
  51. package/dist/lib/mappers/comment.mapper.js.map +0 -1
  52. package/dist/lib/mappers/index.js.map +0 -1
  53. package/dist/lib/mappers/post.mapper.js +0 -51
  54. package/dist/lib/mappers/post.mapper.js.map +0 -1
  55. package/dist/lib/mappers/tag.mapper.js +0 -21
  56. package/dist/lib/mappers/tag.mapper.js.map +0 -1
  57. package/dist/lib/mappers/utils.js +0 -75
  58. package/dist/lib/mappers/utils.js.map +0 -1
  59. package/dist/lib/services/categories.service.js +0 -69
  60. package/dist/lib/services/categories.service.js.map +0 -1
  61. package/dist/lib/services/comments.service.js +0 -73
  62. package/dist/lib/services/comments.service.js.map +0 -1
  63. package/dist/lib/services/index.js.map +0 -1
  64. package/dist/lib/services/posts.service.js +0 -127
  65. package/dist/lib/services/posts.service.js.map +0 -1
  66. package/dist/lib/services/tags.service.js +0 -59
  67. package/dist/lib/services/tags.service.js.map +0 -1
  68. package/dist/lib/types/category.js +0 -3
  69. package/dist/lib/types/category.js.map +0 -1
  70. package/dist/lib/types/comment.js +0 -3
  71. package/dist/lib/types/comment.js.map +0 -1
  72. package/dist/lib/types/index.js.map +0 -1
  73. package/dist/lib/types/post.js +0 -3
  74. package/dist/lib/types/post.js.map +0 -1
  75. package/dist/lib/types/tag.js +0 -3
  76. package/dist/lib/types/tag.js.map +0 -1
@@ -0,0 +1 @@
1
+ export * from "./src/index";
@@ -0,0 +1,577 @@
1
+ import '@swc/helpers/_/_extends';
2
+
3
+ /**
4
+ * Type guard for single resource document
5
+ */ function isSingleResourceDocument(doc) {
6
+ return doc.data !== null && doc.data !== undefined && !Array.isArray(doc.data);
7
+ }
8
+ /**
9
+ * Type guard for collection resource document
10
+ */ function isCollectionDocument(doc) {
11
+ return Array.isArray(doc.data);
12
+ }
13
+ /**
14
+ * Create a key for the included map
15
+ */ function resourceKey(type, id) {
16
+ return `${type}:${id}`;
17
+ }
18
+ /**
19
+ * Build an included map from an array of resources
20
+ */ function buildIncludedMap(included = []) {
21
+ const map = new Map();
22
+ for (const resource of included){
23
+ map.set(resourceKey(resource.type, resource.id), resource);
24
+ }
25
+ return map;
26
+ }
27
+ /**
28
+ * Decode a single resource from a JSON:API document
29
+ */ function decodeOne(document, mapper) {
30
+ if (!isSingleResourceDocument(document)) {
31
+ throw new Error('Expected single resource document');
32
+ }
33
+ const included = buildIncludedMap(document.included);
34
+ return mapper.map(document.data, included);
35
+ }
36
+ /**
37
+ * Decode multiple resources from a JSON:API document
38
+ */ function decodeMany(document, mapper) {
39
+ if (!isCollectionDocument(document)) {
40
+ throw new Error('Expected collection document');
41
+ }
42
+ const included = buildIncludedMap(document.included);
43
+ return document.data.map((resource)=>mapper.map(resource, included));
44
+ }
45
+ /**
46
+ * Extract pagination metadata from JSON:API meta
47
+ */ function extractPageMeta(meta) {
48
+ var _meta_current_page, _meta_total_pages, _meta_total_count, _meta_per_page;
49
+ return {
50
+ currentPage: (_meta_current_page = meta == null ? void 0 : meta.current_page) != null ? _meta_current_page : 1,
51
+ totalPages: (_meta_total_pages = meta == null ? void 0 : meta.total_pages) != null ? _meta_total_pages : 1,
52
+ totalCount: (_meta_total_count = meta == null ? void 0 : meta.total_count) != null ? _meta_total_count : 0,
53
+ perPage: (_meta_per_page = meta == null ? void 0 : meta.per_page) != null ? _meta_per_page : 0
54
+ };
55
+ }
56
+ /**
57
+ * Decode a paginated collection from a JSON:API document
58
+ */ function decodePageResult(document, mapper) {
59
+ const data = isCollectionDocument(document) ? decodeMany(document, mapper) : [];
60
+ return {
61
+ data,
62
+ meta: extractPageMeta(document.meta)
63
+ };
64
+ }
65
+
66
+ /**
67
+ * Parse a string value, returning undefined for empty/undefined
68
+ */ function parseString(value) {
69
+ if (value === null || value === undefined) {
70
+ return undefined;
71
+ }
72
+ const str = String(value);
73
+ return str.length > 0 ? str : undefined;
74
+ }
75
+ /**
76
+ * Parse a date value
77
+ */ function parseDate(value) {
78
+ if (value === null || value === undefined) {
79
+ return undefined;
80
+ }
81
+ if (value instanceof Date) {
82
+ return value;
83
+ }
84
+ if (typeof value === 'string' || typeof value === 'number') {
85
+ const date = new Date(value);
86
+ return isNaN(date.getTime()) ? undefined : date;
87
+ }
88
+ return undefined;
89
+ }
90
+ /**
91
+ * Parse a boolean value
92
+ */ function parseBoolean(value) {
93
+ if (typeof value === 'boolean') {
94
+ return value;
95
+ }
96
+ if (value === 'true' || value === '1' || value === 1) {
97
+ return true;
98
+ }
99
+ return false;
100
+ }
101
+ /**
102
+ * Parse an optional number value
103
+ */ function parseOptionalNumber(value) {
104
+ if (value === null || value === undefined) {
105
+ return undefined;
106
+ }
107
+ const num = Number(value);
108
+ return isNaN(num) ? undefined : num;
109
+ }
110
+ /**
111
+ * Parse entity status
112
+ */ function parseStatus(value) {
113
+ const status = parseString(value);
114
+ if (status === 'active' || status === 'inactive' || status === 'pending' || status === 'archived' || status === 'deleted') {
115
+ return status;
116
+ }
117
+ return 'active';
118
+ }
119
+
120
+ const postMapper = {
121
+ type: 'Post',
122
+ map: (resource)=>({
123
+ id: resource.id,
124
+ uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
125
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
126
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
127
+ postVersionUniqueId: parseString(resource.attributes['post_version_unique_id']),
128
+ title: parseString(resource.attributes['title']) || '',
129
+ abstract: parseString(resource.attributes['abstract']),
130
+ keywords: parseString(resource.attributes['keywords']),
131
+ content: parseString(resource.attributes['content']),
132
+ thumbnailUrl: parseString(resource.attributes['thumbnail_url']),
133
+ imageUrl: parseString(resource.attributes['image_url']),
134
+ mediaUrl: parseString(resource.attributes['media_url']),
135
+ payload: resource.attributes['payload'],
136
+ status: parseStatus(resource.attributes['status']),
137
+ enabled: parseBoolean(resource.attributes['enabled']),
138
+ publishAt: parseDate(resource.attributes['publish_at']),
139
+ publishUntil: parseDate(resource.attributes['publish_until']),
140
+ // User
141
+ userUniqueId: parseString(resource.attributes['user_unique_id']),
142
+ userName: parseString(resource.attributes['user_name']),
143
+ userAlias: parseString(resource.attributes['user_alias']),
144
+ userAvatarUrl: parseString(resource.attributes['user_avatar_url']),
145
+ // Visibility
146
+ isPublic: parseBoolean(resource.attributes['is_public']),
147
+ // Versioning
148
+ version: parseOptionalNumber(resource.attributes['version']),
149
+ // Engagement
150
+ likes: parseOptionalNumber(resource.attributes['likes']),
151
+ dislikes: parseOptionalNumber(resource.attributes['dislikes']),
152
+ comments: parseOptionalNumber(resource.attributes['comments']),
153
+ followers: parseOptionalNumber(resource.attributes['followers']),
154
+ savers: parseOptionalNumber(resource.attributes['savers']),
155
+ // SEO
156
+ slug: parseString(resource.attributes['slug']),
157
+ // AI
158
+ aiGenerated: parseBoolean(resource.attributes['ai_generated']),
159
+ aiModel: parseString(resource.attributes['ai_model']),
160
+ // Moderation
161
+ moderated: parseBoolean(resource.attributes['moderated']),
162
+ moderatedBy: parseString(resource.attributes['moderated_by']),
163
+ moderatedAt: parseDate(resource.attributes['moderated_at']),
164
+ moderationReason: parseString(resource.attributes['moderation_reason']),
165
+ moderationDecision: parseString(resource.attributes['moderation_decision'])
166
+ })
167
+ };
168
+
169
+ function createPostsService(transport, _config) {
170
+ return {
171
+ async list (params) {
172
+ const queryParams = {};
173
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
174
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
175
+ if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
176
+ if (params == null ? void 0 : params.categoryUniqueId) queryParams['category_unique_id'] = params.categoryUniqueId;
177
+ if (params == null ? void 0 : params.tagUniqueId) queryParams['tag_unique_id'] = params.tagUniqueId;
178
+ if (params == null ? void 0 : params.userUniqueId) queryParams['user_unique_id'] = params.userUniqueId;
179
+ if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
180
+ if ((params == null ? void 0 : params.isPublic) !== undefined) queryParams['is_public'] = String(params.isPublic);
181
+ if (params == null ? void 0 : params.withComments) queryParams['with'] = 'comments';
182
+ if (params == null ? void 0 : params.withCategories) queryParams['with'] = params.withComments ? 'comments,categories' : 'categories';
183
+ if (params == null ? void 0 : params.withTags) {
184
+ queryParams['with'] = queryParams['with'] ? `${queryParams['with']},tags` : 'tags';
185
+ }
186
+ if (params == null ? void 0 : params.sortBy) queryParams['sort'] = params.sortOrder === 'desc' ? `-${params.sortBy}` : params.sortBy;
187
+ const response = await transport.get('/posts', {
188
+ params: queryParams
189
+ });
190
+ return decodePageResult(response, postMapper);
191
+ },
192
+ async get (uniqueId) {
193
+ const response = await transport.get(`/posts/${uniqueId}`);
194
+ return decodeOne(response, postMapper);
195
+ },
196
+ async create (data) {
197
+ const response = await transport.post('/posts', {
198
+ post: {
199
+ title: data.title,
200
+ abstract: data.abstract,
201
+ keywords: data.keywords,
202
+ content: data.content,
203
+ thumbnail_url: data.thumbnailUrl,
204
+ image_url: data.imageUrl,
205
+ media_url: data.mediaUrl,
206
+ category_unique_ids: data.categoryUniqueIds,
207
+ tag_unique_ids: data.tagUniqueIds,
208
+ is_public: data.isPublic,
209
+ publish_at: data.publishAt,
210
+ publish_until: data.publishUntil,
211
+ payload: data.payload
212
+ }
213
+ });
214
+ return decodeOne(response, postMapper);
215
+ },
216
+ async update (uniqueId, data) {
217
+ const response = await transport.put(`/posts/${uniqueId}`, {
218
+ post: {
219
+ title: data.title,
220
+ abstract: data.abstract,
221
+ keywords: data.keywords,
222
+ content: data.content,
223
+ thumbnail_url: data.thumbnailUrl,
224
+ image_url: data.imageUrl,
225
+ media_url: data.mediaUrl,
226
+ category_unique_ids: data.categoryUniqueIds,
227
+ tag_unique_ids: data.tagUniqueIds,
228
+ is_public: data.isPublic,
229
+ publish_at: data.publishAt,
230
+ publish_until: data.publishUntil,
231
+ enabled: data.enabled,
232
+ status: data.status,
233
+ payload: data.payload
234
+ }
235
+ });
236
+ return decodeOne(response, postMapper);
237
+ },
238
+ async delete (uniqueId) {
239
+ await transport.delete(`/posts/${uniqueId}`);
240
+ },
241
+ async recover (uniqueId) {
242
+ const response = await transport.put(`/posts/${uniqueId}/recover`, {});
243
+ return decodeOne(response, postMapper);
244
+ },
245
+ async search (query, params) {
246
+ const queryParams = {
247
+ search: query
248
+ };
249
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
250
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
251
+ const response = await transport.post('/posts/search', {
252
+ search: query
253
+ }, {
254
+ params: queryParams
255
+ });
256
+ return decodePageResult(response, postMapper);
257
+ },
258
+ async listDeleted (params) {
259
+ const queryParams = {};
260
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
261
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
262
+ const response = await transport.get('/posts/trash/show', {
263
+ params: queryParams
264
+ });
265
+ return decodePageResult(response, postMapper);
266
+ },
267
+ // Engagement
268
+ async like (uniqueId) {
269
+ const response = await transport.post(`/posts/${uniqueId}/like`, {});
270
+ return decodeOne(response, postMapper);
271
+ },
272
+ async dislike (uniqueId) {
273
+ const response = await transport.post(`/posts/${uniqueId}/dislike`, {});
274
+ return decodeOne(response, postMapper);
275
+ },
276
+ async save (uniqueId) {
277
+ const response = await transport.post(`/posts/${uniqueId}/save`, {});
278
+ return decodeOne(response, postMapper);
279
+ },
280
+ async follow (uniqueId) {
281
+ const response = await transport.post(`/posts/${uniqueId}/follow`, {});
282
+ return decodeOne(response, postMapper);
283
+ }
284
+ };
285
+ }
286
+
287
+ const commentMapper = {
288
+ type: 'Comment',
289
+ map: (resource)=>({
290
+ id: resource.id,
291
+ uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
292
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
293
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
294
+ postUniqueId: parseString(resource.attributes['post_unique_id']) || '',
295
+ postVersion: parseOptionalNumber(resource.attributes['post_version']),
296
+ content: parseString(resource.attributes['content']) || '',
297
+ thumbnailUrl: parseString(resource.attributes['thumbnail_url']),
298
+ imageUrl: parseString(resource.attributes['image_url']),
299
+ contentUrl: parseString(resource.attributes['content_url']),
300
+ mediaUrl: parseString(resource.attributes['media_url']),
301
+ // User
302
+ userUniqueId: parseString(resource.attributes['user_unique_id']),
303
+ userName: parseString(resource.attributes['user_name']),
304
+ userAlias: parseString(resource.attributes['user_alias']),
305
+ userAvatarUrl: parseString(resource.attributes['user_avatar_url']),
306
+ payload: resource.attributes['payload'],
307
+ status: parseStatus(resource.attributes['status']),
308
+ enabled: parseBoolean(resource.attributes['enabled']),
309
+ // Threading
310
+ parentId: parseString(resource.attributes['parent_id']),
311
+ // Engagement
312
+ likes: parseOptionalNumber(resource.attributes['likes']),
313
+ dislikes: parseOptionalNumber(resource.attributes['dislikes']),
314
+ followers: parseOptionalNumber(resource.attributes['followers']),
315
+ savers: parseOptionalNumber(resource.attributes['savers']),
316
+ // AI
317
+ aiGenerated: parseBoolean(resource.attributes['ai_generated']),
318
+ aiModel: parseString(resource.attributes['ai_model']),
319
+ // Moderation
320
+ moderated: parseBoolean(resource.attributes['moderated']),
321
+ moderatedBy: parseString(resource.attributes['moderated_by']),
322
+ moderatedAt: parseDate(resource.attributes['moderated_at']),
323
+ moderationReason: parseString(resource.attributes['moderation_reason']),
324
+ moderationDecision: parseString(resource.attributes['moderation_decision'])
325
+ })
326
+ };
327
+
328
+ function createCommentsService(transport, _config) {
329
+ return {
330
+ async list (params) {
331
+ const queryParams = {};
332
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
333
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
334
+ if (params == null ? void 0 : params.postUniqueId) queryParams['post_unique_id'] = params.postUniqueId;
335
+ if (params == null ? void 0 : params.userUniqueId) queryParams['user_unique_id'] = params.userUniqueId;
336
+ if (params == null ? void 0 : params.parentId) queryParams['parent_id'] = params.parentId;
337
+ if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
338
+ const response = await transport.get('/comments', {
339
+ params: queryParams
340
+ });
341
+ return decodePageResult(response, commentMapper);
342
+ },
343
+ async get (uniqueId) {
344
+ const response = await transport.get(`/comments/${uniqueId}`);
345
+ return decodeOne(response, commentMapper);
346
+ },
347
+ async create (data) {
348
+ const response = await transport.post('/comments', {
349
+ comment: {
350
+ post_unique_id: data.postUniqueId,
351
+ content: data.content,
352
+ thumbnail_url: data.thumbnailUrl,
353
+ image_url: data.imageUrl,
354
+ content_url: data.contentUrl,
355
+ media_url: data.mediaUrl,
356
+ parent_id: data.parentId,
357
+ payload: data.payload
358
+ }
359
+ });
360
+ return decodeOne(response, commentMapper);
361
+ },
362
+ async update (uniqueId, data) {
363
+ const response = await transport.put(`/comments/${uniqueId}`, {
364
+ comment: {
365
+ content: data.content,
366
+ thumbnail_url: data.thumbnailUrl,
367
+ image_url: data.imageUrl,
368
+ content_url: data.contentUrl,
369
+ media_url: data.mediaUrl,
370
+ enabled: data.enabled,
371
+ status: data.status,
372
+ payload: data.payload
373
+ }
374
+ });
375
+ return decodeOne(response, commentMapper);
376
+ },
377
+ async delete (uniqueId) {
378
+ await transport.delete(`/comments/${uniqueId}`);
379
+ },
380
+ // Engagement
381
+ async like (uniqueId) {
382
+ const response = await transport.post(`/comments/${uniqueId}/like`, {});
383
+ return decodeOne(response, commentMapper);
384
+ },
385
+ async dislike (uniqueId) {
386
+ const response = await transport.post(`/comments/${uniqueId}/dislike`, {});
387
+ return decodeOne(response, commentMapper);
388
+ }
389
+ };
390
+ }
391
+
392
+ const categoryMapper = {
393
+ type: 'Category',
394
+ map: (resource)=>({
395
+ id: resource.id,
396
+ uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
397
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
398
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
399
+ code: parseString(resource.attributes['code']) || '',
400
+ name: parseString(resource.attributes['name']) || '',
401
+ description: parseString(resource.attributes['description']),
402
+ parentId: parseString(resource.attributes['parent_id']),
403
+ parentUniqueId: parseString(resource.attributes['parent_unique_id']),
404
+ // Display
405
+ displayOrder: parseOptionalNumber(resource.attributes['display_order']),
406
+ iconUrl: parseString(resource.attributes['icon_url']),
407
+ imageUrl: parseString(resource.attributes['image_url']),
408
+ contentUrl: parseString(resource.attributes['content_url']),
409
+ slug: parseString(resource.attributes['slug']),
410
+ // Business Logic
411
+ status: parseStatus(resource.attributes['status']),
412
+ enabled: parseBoolean(resource.attributes['enabled']),
413
+ // SEO
414
+ metaTitle: parseString(resource.attributes['meta_title']),
415
+ metaDescription: parseString(resource.attributes['meta_description']),
416
+ metaKeywords: parseString(resource.attributes['meta_keywords']),
417
+ // Source
418
+ source: parseString(resource.attributes['source']),
419
+ sourceAlias: parseString(resource.attributes['source_alias']),
420
+ sourceId: parseString(resource.attributes['source_id']),
421
+ sourceType: parseString(resource.attributes['source_type']),
422
+ // Extra
423
+ payload: resource.attributes['payload'],
424
+ postCount: parseOptionalNumber(resource.attributes['post_count'])
425
+ })
426
+ };
427
+
428
+ function createCategoriesService(transport, _config) {
429
+ return {
430
+ async list (params) {
431
+ const queryParams = {};
432
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
433
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
434
+ if (params == null ? void 0 : params.parentUniqueId) queryParams['parent_unique_id'] = params.parentUniqueId;
435
+ if (params == null ? void 0 : params.withChildren) queryParams['with'] = 'children';
436
+ if (params == null ? void 0 : params.withPosts) queryParams['with'] = params.withChildren ? 'children,posts' : 'posts';
437
+ const response = await transport.get('/content/categories', {
438
+ params: queryParams
439
+ });
440
+ return decodePageResult(response, categoryMapper);
441
+ },
442
+ async get (uniqueId) {
443
+ const response = await transport.get(`/content/categories/${uniqueId}`);
444
+ return decodeOne(response, categoryMapper);
445
+ },
446
+ async create (data) {
447
+ const response = await transport.post('/content/categories', {
448
+ category: {
449
+ name: data.name,
450
+ description: data.description,
451
+ parent_unique_id: data.parentUniqueId,
452
+ display_order: data.displayOrder,
453
+ image_url: data.imageUrl,
454
+ icon_url: data.iconUrl
455
+ }
456
+ });
457
+ return decodeOne(response, categoryMapper);
458
+ },
459
+ async update (uniqueId, data) {
460
+ const response = await transport.put(`/content/categories/${uniqueId}`, {
461
+ category: {
462
+ name: data.name,
463
+ description: data.description,
464
+ parent_unique_id: data.parentUniqueId,
465
+ display_order: data.displayOrder,
466
+ image_url: data.imageUrl,
467
+ icon_url: data.iconUrl,
468
+ enabled: data.enabled,
469
+ status: data.status
470
+ }
471
+ });
472
+ return decodeOne(response, categoryMapper);
473
+ },
474
+ async delete (uniqueId) {
475
+ await transport.delete(`/content/categories/${uniqueId}`);
476
+ },
477
+ async recover (uniqueId) {
478
+ const response = await transport.put(`/content/categories/${uniqueId}/recover`, {});
479
+ return decodeOne(response, categoryMapper);
480
+ },
481
+ async getChildren (uniqueId) {
482
+ const response = await transport.get(`/content/categories/${uniqueId}/children`);
483
+ return decodeMany(response, categoryMapper);
484
+ }
485
+ };
486
+ }
487
+
488
+ const tagMapper = {
489
+ type: 'Tag',
490
+ map: (resource)=>({
491
+ id: resource.id,
492
+ uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
493
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
494
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
495
+ tag: parseString(resource.attributes['tag']) || '',
496
+ thumbnailUrl: parseString(resource.attributes['thumbnail_url']),
497
+ imageUrl: parseString(resource.attributes['image_url']),
498
+ contentUrl: parseString(resource.attributes['content_url']),
499
+ mediaUrl: parseString(resource.attributes['media_url']),
500
+ payload: resource.attributes['payload'],
501
+ status: parseStatus(resource.attributes['status']),
502
+ enabled: parseBoolean(resource.attributes['enabled']),
503
+ slug: parseString(resource.attributes['slug'])
504
+ })
505
+ };
506
+
507
+ function createTagsService(transport, _config) {
508
+ return {
509
+ async list (params) {
510
+ const queryParams = {};
511
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
512
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
513
+ if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
514
+ const response = await transport.get('/tags', {
515
+ params: queryParams
516
+ });
517
+ return decodePageResult(response, tagMapper);
518
+ },
519
+ async get (uniqueId) {
520
+ const response = await transport.get(`/tags/${uniqueId}`);
521
+ return decodeOne(response, tagMapper);
522
+ },
523
+ async create (data) {
524
+ const response = await transport.post('/tags', {
525
+ tag: {
526
+ tag: data.tag,
527
+ thumbnail_url: data.thumbnailUrl,
528
+ image_url: data.imageUrl,
529
+ content_url: data.contentUrl,
530
+ media_url: data.mediaUrl,
531
+ payload: data.payload
532
+ }
533
+ });
534
+ return decodeOne(response, tagMapper);
535
+ },
536
+ async update (uniqueId, data) {
537
+ const response = await transport.put(`/tags/${uniqueId}`, {
538
+ tag: {
539
+ tag: data.tag,
540
+ thumbnail_url: data.thumbnailUrl,
541
+ image_url: data.imageUrl,
542
+ content_url: data.contentUrl,
543
+ media_url: data.mediaUrl,
544
+ enabled: data.enabled,
545
+ status: data.status,
546
+ payload: data.payload
547
+ }
548
+ });
549
+ return decodeOne(response, tagMapper);
550
+ },
551
+ async delete (uniqueId) {
552
+ await transport.delete(`/tags/${uniqueId}`);
553
+ }
554
+ };
555
+ }
556
+
557
+ function createContentBlock(transport, config) {
558
+ return {
559
+ posts: createPostsService(transport),
560
+ comments: createCommentsService(transport),
561
+ categories: createCategoriesService(transport),
562
+ tags: createTagsService(transport)
563
+ };
564
+ }
565
+ const contentBlockMetadata = {
566
+ name: 'content',
567
+ version: '0.1.0',
568
+ description: 'Content management for posts, comments, categories, and tags',
569
+ resourceTypes: [
570
+ 'Post',
571
+ 'Comment',
572
+ 'Category',
573
+ 'Tag'
574
+ ]
575
+ };
576
+
577
+ export { categoryMapper, commentMapper, contentBlockMetadata, createCategoriesService, createCommentsService, createContentBlock, createPostsService, createTagsService, postMapper, tagMapper };
@@ -0,0 +1,7 @@
1
+ export { createContentBlock, contentBlockMetadata } from './lib/content.block';
2
+ export type { ContentBlock, ContentBlockConfig } from './lib/content.block';
3
+ export type { Post, CreatePostRequest, UpdatePostRequest, ListPostsParams, Comment, CreateCommentRequest, UpdateCommentRequest, ListCommentsParams, Category, CreateCategoryRequest, UpdateCategoryRequest, ListCategoriesParams, Tag, CreateTagRequest, UpdateTagRequest, ListTagsParams, } from './lib/types';
4
+ export type { PostsService, CommentsService, CategoriesService, TagsService, } from './lib/services';
5
+ export { createPostsService, createCommentsService, createCategoriesService, createTagsService, } from './lib/services';
6
+ export { postMapper, commentMapper, categoryMapper, tagMapper, } from './lib/mappers';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAG5E,YAAY,EAEV,IAAI,EACJ,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EAEf,OAAO,EACP,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAElB,QAAQ,EACR,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EAEpB,GAAG,EACH,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,GACf,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,WAAW,GACZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,SAAS,GACV,MAAM,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function blockContent(): string;
2
+ //# sourceMappingURL=block-content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block-content.d.ts","sourceRoot":"","sources":["../../../src/lib/block-content.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,IAAI,MAAM,CAErC"}
@@ -0,0 +1,15 @@
1
+ import type { Transport, BlockConfig, BlockMetadata } from '@23blocks/contracts';
2
+ import { type PostsService, type CommentsService, type CategoriesService, type TagsService } from './services';
3
+ export interface ContentBlockConfig extends BlockConfig {
4
+ appId: string;
5
+ tenantId?: string;
6
+ }
7
+ export interface ContentBlock {
8
+ posts: PostsService;
9
+ comments: CommentsService;
10
+ categories: CategoriesService;
11
+ tags: TagsService;
12
+ }
13
+ export declare function createContentBlock(transport: Transport, config: ContentBlockConfig): ContentBlock;
14
+ export declare const contentBlockMetadata: BlockMetadata;
15
+ //# sourceMappingURL=content.block.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.block.d.ts","sourceRoot":"","sources":["../../../src/lib/content.block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAKL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EACjB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,YAAY,CAAC;IACpB,QAAQ,EAAE,eAAe,CAAC;IAC1B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,kBAAkB,GACzB,YAAY,CAOd;AAED,eAAO,MAAM,oBAAoB,EAAE,aAUlC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ResourceMapper } from '@23blocks/jsonapi-codec';
2
+ import type { Category } from '../types/category';
3
+ export declare const categoryMapper: ResourceMapper<Category>;
4
+ //# sourceMappingURL=category.mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"category.mapper.d.ts","sourceRoot":"","sources":["../../../../src/lib/mappers/category.mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGlD,eAAO,MAAM,cAAc,EAAE,cAAc,CAAC,QAAQ,CAwCnD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ResourceMapper } from '@23blocks/jsonapi-codec';
2
+ import type { Comment } from '../types/comment';
3
+ export declare const commentMapper: ResourceMapper<Comment>;
4
+ //# sourceMappingURL=comment.mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comment.mapper.d.ts","sourceRoot":"","sources":["../../../../src/lib/mappers/comment.mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,eAAO,MAAM,aAAa,EAAE,cAAc,CAAC,OAAO,CA8CjD,CAAC"}
@@ -2,5 +2,4 @@ export * from './post.mapper';
2
2
  export * from './comment.mapper';
3
3
  export * from './category.mapper';
4
4
  export * from './tag.mapper';
5
-
6
- //# sourceMappingURL=index.js.map
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/mappers/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ResourceMapper } from '@23blocks/jsonapi-codec';
2
+ import type { Post } from '../types/post';
3
+ export declare const postMapper: ResourceMapper<Post>;
4
+ //# sourceMappingURL=post.mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post.mapper.d.ts","sourceRoot":"","sources":["../../../../src/lib/mappers/post.mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAG1C,eAAO,MAAM,UAAU,EAAE,cAAc,CAAC,IAAI,CAuD3C,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ResourceMapper } from '@23blocks/jsonapi-codec';
2
+ import type { Tag } from '../types/tag';
3
+ export declare const tagMapper: ResourceMapper<Tag>;
4
+ //# sourceMappingURL=tag.mapper.d.ts.map