@23blocks/block-content 1.0.3 → 1.0.5

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 +601 -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,601 @@
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
+ data: {
199
+ type: 'Post',
200
+ attributes: {
201
+ title: data.title,
202
+ abstract: data.abstract,
203
+ keywords: data.keywords,
204
+ content: data.content,
205
+ thumbnail_url: data.thumbnailUrl,
206
+ image_url: data.imageUrl,
207
+ media_url: data.mediaUrl,
208
+ category_unique_ids: data.categoryUniqueIds,
209
+ tag_unique_ids: data.tagUniqueIds,
210
+ is_public: data.isPublic,
211
+ publish_at: data.publishAt,
212
+ publish_until: data.publishUntil,
213
+ payload: data.payload
214
+ }
215
+ }
216
+ });
217
+ return decodeOne(response, postMapper);
218
+ },
219
+ async update (uniqueId, data) {
220
+ const response = await transport.put(`/posts/${uniqueId}`, {
221
+ data: {
222
+ type: 'Post',
223
+ attributes: {
224
+ title: data.title,
225
+ abstract: data.abstract,
226
+ keywords: data.keywords,
227
+ content: data.content,
228
+ thumbnail_url: data.thumbnailUrl,
229
+ image_url: data.imageUrl,
230
+ media_url: data.mediaUrl,
231
+ category_unique_ids: data.categoryUniqueIds,
232
+ tag_unique_ids: data.tagUniqueIds,
233
+ is_public: data.isPublic,
234
+ publish_at: data.publishAt,
235
+ publish_until: data.publishUntil,
236
+ enabled: data.enabled,
237
+ status: data.status,
238
+ payload: data.payload
239
+ }
240
+ }
241
+ });
242
+ return decodeOne(response, postMapper);
243
+ },
244
+ async delete (uniqueId) {
245
+ await transport.delete(`/posts/${uniqueId}`);
246
+ },
247
+ async recover (uniqueId) {
248
+ const response = await transport.put(`/posts/${uniqueId}/recover`, {});
249
+ return decodeOne(response, postMapper);
250
+ },
251
+ async search (query, params) {
252
+ const queryParams = {
253
+ search: query
254
+ };
255
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
256
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
257
+ const response = await transport.post('/posts/search', {
258
+ search: query
259
+ }, {
260
+ params: queryParams
261
+ });
262
+ return decodePageResult(response, postMapper);
263
+ },
264
+ async listDeleted (params) {
265
+ const queryParams = {};
266
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
267
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
268
+ const response = await transport.get('/posts/trash/show', {
269
+ params: queryParams
270
+ });
271
+ return decodePageResult(response, postMapper);
272
+ },
273
+ // Engagement
274
+ async like (uniqueId) {
275
+ const response = await transport.post(`/posts/${uniqueId}/like`, {});
276
+ return decodeOne(response, postMapper);
277
+ },
278
+ async dislike (uniqueId) {
279
+ const response = await transport.post(`/posts/${uniqueId}/dislike`, {});
280
+ return decodeOne(response, postMapper);
281
+ },
282
+ async save (uniqueId) {
283
+ const response = await transport.post(`/posts/${uniqueId}/save`, {});
284
+ return decodeOne(response, postMapper);
285
+ },
286
+ async follow (uniqueId) {
287
+ const response = await transport.post(`/posts/${uniqueId}/follow`, {});
288
+ return decodeOne(response, postMapper);
289
+ }
290
+ };
291
+ }
292
+
293
+ const commentMapper = {
294
+ type: 'Comment',
295
+ map: (resource)=>({
296
+ id: resource.id,
297
+ uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
298
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
299
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
300
+ postUniqueId: parseString(resource.attributes['post_unique_id']) || '',
301
+ postVersion: parseOptionalNumber(resource.attributes['post_version']),
302
+ content: parseString(resource.attributes['content']) || '',
303
+ thumbnailUrl: parseString(resource.attributes['thumbnail_url']),
304
+ imageUrl: parseString(resource.attributes['image_url']),
305
+ contentUrl: parseString(resource.attributes['content_url']),
306
+ mediaUrl: parseString(resource.attributes['media_url']),
307
+ // User
308
+ userUniqueId: parseString(resource.attributes['user_unique_id']),
309
+ userName: parseString(resource.attributes['user_name']),
310
+ userAlias: parseString(resource.attributes['user_alias']),
311
+ userAvatarUrl: parseString(resource.attributes['user_avatar_url']),
312
+ payload: resource.attributes['payload'],
313
+ status: parseStatus(resource.attributes['status']),
314
+ enabled: parseBoolean(resource.attributes['enabled']),
315
+ // Threading
316
+ parentId: parseString(resource.attributes['parent_id']),
317
+ // Engagement
318
+ likes: parseOptionalNumber(resource.attributes['likes']),
319
+ dislikes: parseOptionalNumber(resource.attributes['dislikes']),
320
+ followers: parseOptionalNumber(resource.attributes['followers']),
321
+ savers: parseOptionalNumber(resource.attributes['savers']),
322
+ // AI
323
+ aiGenerated: parseBoolean(resource.attributes['ai_generated']),
324
+ aiModel: parseString(resource.attributes['ai_model']),
325
+ // Moderation
326
+ moderated: parseBoolean(resource.attributes['moderated']),
327
+ moderatedBy: parseString(resource.attributes['moderated_by']),
328
+ moderatedAt: parseDate(resource.attributes['moderated_at']),
329
+ moderationReason: parseString(resource.attributes['moderation_reason']),
330
+ moderationDecision: parseString(resource.attributes['moderation_decision'])
331
+ })
332
+ };
333
+
334
+ function createCommentsService(transport, _config) {
335
+ return {
336
+ async list (params) {
337
+ const queryParams = {};
338
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
339
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
340
+ if (params == null ? void 0 : params.postUniqueId) queryParams['post_unique_id'] = params.postUniqueId;
341
+ if (params == null ? void 0 : params.userUniqueId) queryParams['user_unique_id'] = params.userUniqueId;
342
+ if (params == null ? void 0 : params.parentId) queryParams['parent_id'] = params.parentId;
343
+ if (params == null ? void 0 : params.status) queryParams['status'] = params.status;
344
+ const response = await transport.get('/comments', {
345
+ params: queryParams
346
+ });
347
+ return decodePageResult(response, commentMapper);
348
+ },
349
+ async get (uniqueId) {
350
+ const response = await transport.get(`/comments/${uniqueId}`);
351
+ return decodeOne(response, commentMapper);
352
+ },
353
+ async create (data) {
354
+ const response = await transport.post('/comments', {
355
+ data: {
356
+ type: 'Comment',
357
+ attributes: {
358
+ post_unique_id: data.postUniqueId,
359
+ content: data.content,
360
+ thumbnail_url: data.thumbnailUrl,
361
+ image_url: data.imageUrl,
362
+ content_url: data.contentUrl,
363
+ media_url: data.mediaUrl,
364
+ parent_id: data.parentId,
365
+ payload: data.payload
366
+ }
367
+ }
368
+ });
369
+ return decodeOne(response, commentMapper);
370
+ },
371
+ async update (uniqueId, data) {
372
+ const response = await transport.put(`/comments/${uniqueId}`, {
373
+ data: {
374
+ type: 'Comment',
375
+ attributes: {
376
+ content: data.content,
377
+ thumbnail_url: data.thumbnailUrl,
378
+ image_url: data.imageUrl,
379
+ content_url: data.contentUrl,
380
+ media_url: data.mediaUrl,
381
+ enabled: data.enabled,
382
+ status: data.status,
383
+ payload: data.payload
384
+ }
385
+ }
386
+ });
387
+ return decodeOne(response, commentMapper);
388
+ },
389
+ async delete (uniqueId) {
390
+ await transport.delete(`/comments/${uniqueId}`);
391
+ },
392
+ // Engagement
393
+ async like (uniqueId) {
394
+ const response = await transport.post(`/comments/${uniqueId}/like`, {});
395
+ return decodeOne(response, commentMapper);
396
+ },
397
+ async dislike (uniqueId) {
398
+ const response = await transport.post(`/comments/${uniqueId}/dislike`, {});
399
+ return decodeOne(response, commentMapper);
400
+ }
401
+ };
402
+ }
403
+
404
+ const categoryMapper = {
405
+ type: 'Category',
406
+ map: (resource)=>({
407
+ id: resource.id,
408
+ uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
409
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
410
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
411
+ code: parseString(resource.attributes['code']) || '',
412
+ name: parseString(resource.attributes['name']) || '',
413
+ description: parseString(resource.attributes['description']),
414
+ parentId: parseString(resource.attributes['parent_id']),
415
+ parentUniqueId: parseString(resource.attributes['parent_unique_id']),
416
+ // Display
417
+ displayOrder: parseOptionalNumber(resource.attributes['display_order']),
418
+ iconUrl: parseString(resource.attributes['icon_url']),
419
+ imageUrl: parseString(resource.attributes['image_url']),
420
+ contentUrl: parseString(resource.attributes['content_url']),
421
+ slug: parseString(resource.attributes['slug']),
422
+ // Business Logic
423
+ status: parseStatus(resource.attributes['status']),
424
+ enabled: parseBoolean(resource.attributes['enabled']),
425
+ // SEO
426
+ metaTitle: parseString(resource.attributes['meta_title']),
427
+ metaDescription: parseString(resource.attributes['meta_description']),
428
+ metaKeywords: parseString(resource.attributes['meta_keywords']),
429
+ // Source
430
+ source: parseString(resource.attributes['source']),
431
+ sourceAlias: parseString(resource.attributes['source_alias']),
432
+ sourceId: parseString(resource.attributes['source_id']),
433
+ sourceType: parseString(resource.attributes['source_type']),
434
+ // Extra
435
+ payload: resource.attributes['payload'],
436
+ postCount: parseOptionalNumber(resource.attributes['post_count'])
437
+ })
438
+ };
439
+
440
+ function createCategoriesService(transport, _config) {
441
+ return {
442
+ async list (params) {
443
+ const queryParams = {};
444
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
445
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
446
+ if (params == null ? void 0 : params.parentUniqueId) queryParams['parent_unique_id'] = params.parentUniqueId;
447
+ if (params == null ? void 0 : params.withChildren) queryParams['with'] = 'children';
448
+ if (params == null ? void 0 : params.withPosts) queryParams['with'] = params.withChildren ? 'children,posts' : 'posts';
449
+ const response = await transport.get('/content/categories', {
450
+ params: queryParams
451
+ });
452
+ return decodePageResult(response, categoryMapper);
453
+ },
454
+ async get (uniqueId) {
455
+ const response = await transport.get(`/content/categories/${uniqueId}`);
456
+ return decodeOne(response, categoryMapper);
457
+ },
458
+ async create (data) {
459
+ const response = await transport.post('/content/categories', {
460
+ data: {
461
+ type: 'Category',
462
+ attributes: {
463
+ name: data.name,
464
+ description: data.description,
465
+ parent_unique_id: data.parentUniqueId,
466
+ display_order: data.displayOrder,
467
+ image_url: data.imageUrl,
468
+ icon_url: data.iconUrl
469
+ }
470
+ }
471
+ });
472
+ return decodeOne(response, categoryMapper);
473
+ },
474
+ async update (uniqueId, data) {
475
+ const response = await transport.put(`/content/categories/${uniqueId}`, {
476
+ data: {
477
+ type: 'Category',
478
+ attributes: {
479
+ name: data.name,
480
+ description: data.description,
481
+ parent_unique_id: data.parentUniqueId,
482
+ display_order: data.displayOrder,
483
+ image_url: data.imageUrl,
484
+ icon_url: data.iconUrl,
485
+ enabled: data.enabled,
486
+ status: data.status
487
+ }
488
+ }
489
+ });
490
+ return decodeOne(response, categoryMapper);
491
+ },
492
+ async delete (uniqueId) {
493
+ await transport.delete(`/content/categories/${uniqueId}`);
494
+ },
495
+ async recover (uniqueId) {
496
+ const response = await transport.put(`/content/categories/${uniqueId}/recover`, {});
497
+ return decodeOne(response, categoryMapper);
498
+ },
499
+ async getChildren (uniqueId) {
500
+ const response = await transport.get(`/content/categories/${uniqueId}/children`);
501
+ return decodeMany(response, categoryMapper);
502
+ }
503
+ };
504
+ }
505
+
506
+ const tagMapper = {
507
+ type: 'Tag',
508
+ map: (resource)=>({
509
+ id: resource.id,
510
+ uniqueId: parseString(resource.attributes['unique_id']) || resource.id,
511
+ createdAt: parseDate(resource.attributes['created_at']) || new Date(),
512
+ updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
513
+ tag: parseString(resource.attributes['tag']) || '',
514
+ thumbnailUrl: parseString(resource.attributes['thumbnail_url']),
515
+ imageUrl: parseString(resource.attributes['image_url']),
516
+ contentUrl: parseString(resource.attributes['content_url']),
517
+ mediaUrl: parseString(resource.attributes['media_url']),
518
+ payload: resource.attributes['payload'],
519
+ status: parseStatus(resource.attributes['status']),
520
+ enabled: parseBoolean(resource.attributes['enabled']),
521
+ slug: parseString(resource.attributes['slug'])
522
+ })
523
+ };
524
+
525
+ function createTagsService(transport, _config) {
526
+ return {
527
+ async list (params) {
528
+ const queryParams = {};
529
+ if (params == null ? void 0 : params.page) queryParams['page'] = String(params.page);
530
+ if (params == null ? void 0 : params.perPage) queryParams['records'] = String(params.perPage);
531
+ if (params == null ? void 0 : params.search) queryParams['search'] = params.search;
532
+ const response = await transport.get('/tags', {
533
+ params: queryParams
534
+ });
535
+ return decodePageResult(response, tagMapper);
536
+ },
537
+ async get (uniqueId) {
538
+ const response = await transport.get(`/tags/${uniqueId}`);
539
+ return decodeOne(response, tagMapper);
540
+ },
541
+ async create (data) {
542
+ const response = await transport.post('/tags', {
543
+ data: {
544
+ type: 'Tag',
545
+ attributes: {
546
+ tag: data.tag,
547
+ thumbnail_url: data.thumbnailUrl,
548
+ image_url: data.imageUrl,
549
+ content_url: data.contentUrl,
550
+ media_url: data.mediaUrl,
551
+ payload: data.payload
552
+ }
553
+ }
554
+ });
555
+ return decodeOne(response, tagMapper);
556
+ },
557
+ async update (uniqueId, data) {
558
+ const response = await transport.put(`/tags/${uniqueId}`, {
559
+ data: {
560
+ type: 'Tag',
561
+ attributes: {
562
+ tag: data.tag,
563
+ thumbnail_url: data.thumbnailUrl,
564
+ image_url: data.imageUrl,
565
+ content_url: data.contentUrl,
566
+ media_url: data.mediaUrl,
567
+ enabled: data.enabled,
568
+ status: data.status,
569
+ payload: data.payload
570
+ }
571
+ }
572
+ });
573
+ return decodeOne(response, tagMapper);
574
+ },
575
+ async delete (uniqueId) {
576
+ await transport.delete(`/tags/${uniqueId}`);
577
+ }
578
+ };
579
+ }
580
+
581
+ function createContentBlock(transport, config) {
582
+ return {
583
+ posts: createPostsService(transport),
584
+ comments: createCommentsService(transport),
585
+ categories: createCategoriesService(transport),
586
+ tags: createTagsService(transport)
587
+ };
588
+ }
589
+ const contentBlockMetadata = {
590
+ name: 'content',
591
+ version: '0.1.0',
592
+ description: 'Content management for posts, comments, categories, and tags',
593
+ resourceTypes: [
594
+ 'Post',
595
+ 'Comment',
596
+ 'Category',
597
+ 'Tag'
598
+ ]
599
+ };
600
+
601
+ 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