@yimingliao/cms 0.0.8 → 0.0.10

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.
@@ -0,0 +1,566 @@
1
+ import jwt from 'jsonwebtoken';
2
+ import { BinaryLike } from 'node:crypto';
3
+ import { cookies } from 'next/headers';
4
+ import { e as AdminRole, v as SingleItem, B as BaseTranslation, a as Admin, c as AdminFull, f as AdminSafe, D as DeviceInfo, d as AdminRefreshToken, k as File, m as FileFull, o as FileType, p as Folder, F as FolderFull, u as PostType, M as MultiItems, E as ExternalLink, j as Faq, T as TocItem, q as Post, s as PostListCard, t as PostTranslation, r as PostFull, S as SeoMetadata, h as Alternate } from '../base-DbGnfZr6.js';
5
+
6
+ interface JwtServiceConfig {
7
+ defaultSecret: string;
8
+ issuer?: string;
9
+ audience?: string;
10
+ }
11
+ /**
12
+ * JWT service
13
+ *
14
+ * Sign, Verify
15
+ */
16
+ declare function createJwtService(config: JwtServiceConfig): {
17
+ sign: ({ payload, secret, expiresIn, }: {
18
+ payload: object;
19
+ secret: string;
20
+ expiresIn: number;
21
+ }) => string;
22
+ verify: ({ token, secret, }: {
23
+ token: string;
24
+ secret: string;
25
+ }) => jwt.JwtPayload;
26
+ };
27
+
28
+ declare function createArgon2Service(): {
29
+ hash: (password: string) => Promise<string>;
30
+ verify: (hash: string, plain: string) => Promise<boolean>;
31
+ };
32
+
33
+ interface CryptoServiceConfig {
34
+ defaultSecret: string;
35
+ }
36
+ /**
37
+ * Crypto service
38
+ *
39
+ * Encrypt & Decrypt, Calculate checksum, Sign
40
+ */
41
+ declare function createCryptoService(config: CryptoServiceConfig): {
42
+ generateToken: () => string;
43
+ hash: (value: BinaryLike) => string;
44
+ hashBuffer: (value: BinaryLike) => Buffer;
45
+ encrypt: (data: string) => string;
46
+ decrypt: (data: string) => string;
47
+ sign: ({ value, expireSeconds, createdAt, }: {
48
+ value: string;
49
+ expireSeconds: number;
50
+ createdAt?: number;
51
+ }) => {
52
+ signed: string;
53
+ signature: string;
54
+ };
55
+ };
56
+
57
+ /**
58
+ * Cookie Service
59
+ *
60
+ * Set, Get, Verify, Delete
61
+ */
62
+ declare function createCookieService(nextCookies: () => Promise<Awaited<ReturnType<typeof cookies>>>, cryptoService: ReturnType<typeof createCryptoService>): {
63
+ set: ({ name, value, expireSeconds, }: {
64
+ name: string;
65
+ value: string;
66
+ expireSeconds: number;
67
+ }) => Promise<void>;
68
+ setSignedCookie: ({ name, value, expireSeconds, }: {
69
+ name: string;
70
+ value: string;
71
+ expireSeconds: number;
72
+ }) => Promise<void>;
73
+ get: ({ name }: {
74
+ name: string;
75
+ }) => Promise<string | undefined>;
76
+ getSignedCookie: ({ name }: {
77
+ name: string;
78
+ }) => Promise<string>;
79
+ verifySignedCookie: ({ signed }: {
80
+ signed: string | undefined;
81
+ }) => string;
82
+ delete: ({ name }: {
83
+ name: string;
84
+ }) => Promise<void>;
85
+ };
86
+
87
+ interface CreateParams$4 {
88
+ email: string;
89
+ role: AdminRole;
90
+ passwordHash: string;
91
+ socialLinks: string[];
92
+ avatarImage: SingleItem;
93
+ translations: (BaseTranslation & {
94
+ name: string | null;
95
+ authorName: string | null;
96
+ description: string | null;
97
+ jobTitle: string | null;
98
+ url: string | null;
99
+ worksFor: string | null;
100
+ knowsAbout: string[];
101
+ homeLocation: string | null;
102
+ nationality: string | null;
103
+ })[];
104
+ }
105
+ interface UpdateParams$3 {
106
+ id: string;
107
+ email?: string;
108
+ role: AdminRole;
109
+ socialLinks: string[];
110
+ avatarImage: SingleItem;
111
+ emailVerifiedAt: Date | null;
112
+ translations: (BaseTranslation & {
113
+ name: string | null;
114
+ authorName: string | null;
115
+ description: string | null;
116
+ jobTitle: string | null;
117
+ url: string | null;
118
+ worksFor: string | null;
119
+ knowsAbout: string[];
120
+ homeLocation: string | null;
121
+ nationality: string | null;
122
+ })[];
123
+ }
124
+
125
+ declare function createAdminCommandRepository(prisma: any): {
126
+ create: ({ avatarImage, translations, ...params }: CreateParams$4) => Promise<Admin>;
127
+ update: ({ id, avatarImage, translations, ...params }: UpdateParams$3) => Promise<Admin>;
128
+ delete: ({ id }: {
129
+ id: string;
130
+ }) => Promise<Admin>;
131
+ };
132
+
133
+ interface FindListCardsParams$3 {
134
+ locale: string;
135
+ searchString?: string;
136
+ role?: AdminRole;
137
+ adminIds?: string[];
138
+ page?: number;
139
+ pageSize?: number;
140
+ }
141
+ interface FindParams$2 {
142
+ id?: string;
143
+ email?: string;
144
+ }
145
+
146
+ declare function createAdminQueryRepository(prisma: any): {
147
+ findListCards: ({ locale, searchString, role, adminIds, page, pageSize, }: FindListCardsParams$3) => Promise<{
148
+ items: AdminFull[];
149
+ total: number;
150
+ }>;
151
+ find: (params: FindParams$2) => Promise<AdminSafe | null>;
152
+ findFull: (params: FindParams$2) => Promise<AdminFull | null>;
153
+ findWithPasswordHash: (params: FindParams$2) => Promise<Admin | null>;
154
+ };
155
+
156
+ interface CreateParams$3 {
157
+ tokenHash: string;
158
+ email: string;
159
+ ip: string;
160
+ deviceInfo?: DeviceInfo;
161
+ adminId: string;
162
+ expiresAt: Date;
163
+ }
164
+ interface DeleteParams {
165
+ id?: string;
166
+ tokenHash?: string;
167
+ }
168
+
169
+ declare function createAdminRefreshTokenCommandRepository(prisma: any): {
170
+ create: ({ adminId, ...params }: CreateParams$3) => Promise<AdminRefreshToken>;
171
+ delete: ({ id, tokenHash }: DeleteParams) => Promise<void>;
172
+ deleteManyByExpired: () => Promise<number>;
173
+ };
174
+
175
+ declare function createAdminRefreshTokenQueryRepository(prisma: any): {
176
+ findManyByAdminId: ({ adminId, }: {
177
+ adminId: string;
178
+ }) => Promise<AdminRefreshToken[]>;
179
+ findByToken: ({ tokenHash, }: {
180
+ tokenHash: string;
181
+ }) => Promise<AdminRefreshToken | null>;
182
+ };
183
+
184
+ interface CreateParams$2 {
185
+ key: string;
186
+ checksum: string;
187
+ fileMeta: {
188
+ type?: string;
189
+ size?: number;
190
+ name?: string;
191
+ };
192
+ width?: number | null;
193
+ height?: number | null;
194
+ duration?: number | null;
195
+ folder?: SingleItem;
196
+ translations: (BaseTranslation & {
197
+ name: string | null;
198
+ alt: string | null;
199
+ })[];
200
+ }
201
+ interface UpdateParams$2 {
202
+ id: string;
203
+ file: File;
204
+ key: string;
205
+ checksum: string;
206
+ fileMeta: {
207
+ type?: string;
208
+ size?: number;
209
+ name?: string;
210
+ };
211
+ width?: number | null;
212
+ height?: number | null;
213
+ duration?: number | null;
214
+ folder?: SingleItem;
215
+ translations: (BaseTranslation & {
216
+ name: string | null;
217
+ alt: string | null;
218
+ })[];
219
+ }
220
+
221
+ declare function createFileCommandRepository(prisma: any): {
222
+ create: ({ fileMeta, folder, translations, ...params }: CreateParams$2) => Promise<FileFull>;
223
+ update: ({ file, id, fileMeta, folder, translations, ...params }: UpdateParams$2) => Promise<File>;
224
+ softDelete: ({ id }: {
225
+ id: string;
226
+ }) => Promise<File>;
227
+ softDeleteMany: ({ ids }: {
228
+ ids: string[];
229
+ }) => Promise<number>;
230
+ restoreMany: ({ ids }: {
231
+ ids: string[];
232
+ }) => Promise<number>;
233
+ delete: ({ id }: {
234
+ id: string;
235
+ }) => Promise<File>;
236
+ };
237
+
238
+ interface FindListCardsParams$2 {
239
+ locale: string;
240
+ searchString?: string;
241
+ type?: FileType | null;
242
+ isDeleted?: boolean;
243
+ isLocked?: boolean | null;
244
+ folderId?: string;
245
+ fileIds?: string[];
246
+ page?: number;
247
+ pageSize?: number;
248
+ }
249
+
250
+ declare function createFileQueryRepository(prisma: any): {
251
+ findListCards: ({ locale, page, pageSize, searchString, type, folderId, isLocked, isDeleted, fileIds, }: FindListCardsParams$2) => Promise<{
252
+ items: FileFull[];
253
+ total: number;
254
+ }>;
255
+ findManyByIds: ({ ids, }: {
256
+ ids: string[];
257
+ }) => Promise<FileFull[]>;
258
+ findFull: ({ id }: {
259
+ id: string;
260
+ }) => Promise<FileFull | null>;
261
+ };
262
+
263
+ interface CreateParams$1 {
264
+ key: string;
265
+ name: string;
266
+ parentFolder: Folder | null;
267
+ }
268
+ interface UpdateParams$1 {
269
+ id: string;
270
+ key: string;
271
+ name: string;
272
+ parentFolder: Folder | null;
273
+ }
274
+
275
+ declare function createFolderCommandRepository(prisma: any): {
276
+ create: ({ parentFolder, ...params }: CreateParams$1) => Promise<Folder>;
277
+ update: ({ id, parentFolder, ...params }: UpdateParams$1) => Promise<Folder>;
278
+ delete: ({ id }: {
279
+ id: string;
280
+ }) => Promise<Folder>;
281
+ };
282
+
283
+ interface FindListCardsParams$1 {
284
+ searchString?: string;
285
+ parentFolderId?: string;
286
+ folderIds?: string[];
287
+ page?: number;
288
+ pageSize?: number;
289
+ }
290
+ interface FindParams$1 {
291
+ id?: string;
292
+ key?: string;
293
+ }
294
+
295
+ declare function createFolderQueryRepository(prisma: any): {
296
+ findListCards: ({ searchString, parentFolderId, folderIds, page, pageSize, }: FindListCardsParams$1) => Promise<{
297
+ items: FolderFull[];
298
+ total: number;
299
+ }>;
300
+ findFull: (params: FindParams$1) => Promise<FolderFull | null>;
301
+ };
302
+
303
+ interface CreateParams {
304
+ type: PostType;
305
+ isLocked: boolean;
306
+ isActive: boolean;
307
+ isIndexActive: boolean;
308
+ index: number | null;
309
+ isSlugActive: boolean;
310
+ slug: string | null;
311
+ isFeatured: boolean;
312
+ isShownOnHome: boolean;
313
+ author: SingleItem;
314
+ topicId: string | null;
315
+ parents: MultiItems;
316
+ tags: MultiItems;
317
+ relatedPosts: MultiItems;
318
+ coverImage: SingleItem;
319
+ contentImageIds: string[];
320
+ state1: boolean;
321
+ state2: boolean;
322
+ state3: boolean;
323
+ state4: boolean;
324
+ state5: boolean;
325
+ state6: boolean;
326
+ state7: boolean;
327
+ state8: boolean;
328
+ state9: boolean;
329
+ state10: boolean;
330
+ images1: MultiItems;
331
+ images2: MultiItems;
332
+ image1: SingleItem;
333
+ image2: SingleItem;
334
+ image3: SingleItem;
335
+ image4: SingleItem;
336
+ text1: string | null;
337
+ text2: string | null;
338
+ text3: string | null;
339
+ text4: string | null;
340
+ text5: string | null;
341
+ text6: string | null;
342
+ text7: string | null;
343
+ text8: string | null;
344
+ text9: string | null;
345
+ text10: string | null;
346
+ data1: any[];
347
+ data2: any[];
348
+ data3: any[];
349
+ data4: any[];
350
+ translations: (BaseTranslation & {
351
+ title: string | null;
352
+ subtitle: string | null;
353
+ summary: string | null;
354
+ description: string | null;
355
+ content: string | null;
356
+ externalLinks: ExternalLink[];
357
+ faq: Faq[];
358
+ toc: TocItem[];
359
+ readTime: number | null;
360
+ wordCount: number;
361
+ text1: string | null;
362
+ text2: string | null;
363
+ text3: string | null;
364
+ text4: string | null;
365
+ text5: string | null;
366
+ text6: string | null;
367
+ text7: string | null;
368
+ text8: string | null;
369
+ text9: string | null;
370
+ text10: string | null;
371
+ data1: any[];
372
+ data2: any[];
373
+ data3: any[];
374
+ data4: any[];
375
+ })[];
376
+ }
377
+ interface UpdateParams {
378
+ id: string;
379
+ type: PostType;
380
+ isLocked: boolean;
381
+ isActive: boolean;
382
+ isIndexActive: boolean;
383
+ index: number | null;
384
+ isSlugActive: boolean;
385
+ slug: string | null;
386
+ isFeatured: boolean;
387
+ isShownOnHome: boolean;
388
+ author: SingleItem;
389
+ topicId: string | null;
390
+ parents: MultiItems;
391
+ tags: MultiItems;
392
+ relatedPosts: MultiItems;
393
+ coverImage: SingleItem;
394
+ contentImageIds: string[];
395
+ state1: boolean;
396
+ state2: boolean;
397
+ state3: boolean;
398
+ state4: boolean;
399
+ state5: boolean;
400
+ state6: boolean;
401
+ state7: boolean;
402
+ state8: boolean;
403
+ state9: boolean;
404
+ state10: boolean;
405
+ images1: MultiItems;
406
+ images2: MultiItems;
407
+ image1: SingleItem;
408
+ image2: SingleItem;
409
+ image3: SingleItem;
410
+ image4: SingleItem;
411
+ text1: string | null;
412
+ text2: string | null;
413
+ text3: string | null;
414
+ text4: string | null;
415
+ text5: string | null;
416
+ text6: string | null;
417
+ text7: string | null;
418
+ text8: string | null;
419
+ text9: string | null;
420
+ text10: string | null;
421
+ data1: any[];
422
+ data2: any[];
423
+ data3: any[];
424
+ data4: any[];
425
+ translations: (BaseTranslation & {
426
+ title: string | null;
427
+ subtitle: string | null;
428
+ summary: string | null;
429
+ description: string | null;
430
+ content: string | null;
431
+ externalLinks: ExternalLink[];
432
+ faq: Faq[];
433
+ toc: TocItem[];
434
+ readTime: number | null;
435
+ wordCount: number;
436
+ text1: string | null;
437
+ text2: string | null;
438
+ text3: string | null;
439
+ text4: string | null;
440
+ text5: string | null;
441
+ text6: string | null;
442
+ text7: string | null;
443
+ text8: string | null;
444
+ text9: string | null;
445
+ text10: string | null;
446
+ data1: any[];
447
+ data2: any[];
448
+ data3: any[];
449
+ data4: any[];
450
+ })[];
451
+ }
452
+
453
+ declare function createPostCommandRepository(prisma: any): {
454
+ create: ({ slug, author, topicId, parents, tags, relatedPosts, coverImage, contentImageIds, images1, images2, image1, image2, image3, image4, translations, ...params }: CreateParams) => Promise<Post>;
455
+ update: ({ id, slug, author, topicId, parents, tags, relatedPosts, coverImage, contentImageIds, images1, images2, image1, image2, image3, image4, translations, ...params }: UpdateParams) => Promise<Post>;
456
+ delete: ({ id }: {
457
+ id: string;
458
+ }) => Promise<Post>;
459
+ };
460
+
461
+ interface FindListCardsParams {
462
+ locale: string;
463
+ type: PostType | null;
464
+ page?: number;
465
+ pageSize?: number;
466
+ searchString?: string;
467
+ topicId?: string;
468
+ postIds?: string[];
469
+ isActive?: boolean;
470
+ isIndexActive?: boolean;
471
+ isSlugActive?: boolean;
472
+ isFeatured?: boolean;
473
+ isShownOnHome?: boolean;
474
+ }
475
+ interface FindParams {
476
+ id?: string;
477
+ type?: PostType;
478
+ slug?: string;
479
+ }
480
+ interface FindManyParams {
481
+ type: PostType;
482
+ topicId?: string;
483
+ }
484
+
485
+ declare function createPostQueryRepository(prisma: any): {
486
+ findListCards: ({ locale, searchString, type, topicId, postIds, isActive, isIndexActive, isSlugActive, isFeatured, isShownOnHome, page, pageSize, }: FindListCardsParams) => Promise<{
487
+ items: PostListCard[];
488
+ total: number;
489
+ }>;
490
+ findMany: ({ type, topicId, }: FindManyParams) => Promise<(Post & {
491
+ translations: PostTranslation[];
492
+ })[]>;
493
+ find: (params: FindParams) => Promise<(Post & {
494
+ translations: PostTranslation[];
495
+ }) | null>;
496
+ findFull: (params: FindParams) => Promise<PostFull | null>;
497
+ findWithSeoMetadata: (params: FindParams) => Promise<(Post & {
498
+ translations: PostTranslation[];
499
+ seoMetadatas: SeoMetadata[];
500
+ }) | null>;
501
+ };
502
+
503
+ interface UpsertParams {
504
+ postId: string;
505
+ translations: (BaseTranslation & {
506
+ title: string | null;
507
+ description: string | null;
508
+ author: string | null;
509
+ canonical: string | null;
510
+ alternate: Alternate[];
511
+ robots: string | null;
512
+ ogTitle: string | null;
513
+ ogDescription: string | null;
514
+ ogUrl: string | null;
515
+ ogType: string | null;
516
+ ogSiteName: string | null;
517
+ ogImage: string | null;
518
+ ogImageAlt: string | null;
519
+ ogImageType: string | null;
520
+ ogImageWidth: number | null;
521
+ ogImageHeight: number | null;
522
+ ogLocale: string | null;
523
+ ogLocaleAlternate: string[];
524
+ ogArticlePublishedTime: string | null;
525
+ ogArticleModifiedTime: string | null;
526
+ ogArticleAuthor: string | null;
527
+ ogArticleSection: string | null;
528
+ ogArticleTag: string[];
529
+ twitterCard: string | null;
530
+ twitterSite: string | null;
531
+ twitterCreator: string | null;
532
+ jsonLd: object[];
533
+ })[];
534
+ }
535
+
536
+ declare function createSeoMetadataCommandRepository(prisma: any): {
537
+ upsert: ({ postId, translations, }: UpsertParams) => Promise<void>;
538
+ };
539
+
540
+ declare const ORDER_BY: readonly [{
541
+ readonly updatedAt: "desc";
542
+ }, {
543
+ readonly createdAt: "desc";
544
+ }, {
545
+ readonly id: "asc";
546
+ }];
547
+ declare const ADMIN_ORDER_BY: ({
548
+ readonly updatedAt: "desc";
549
+ } | {
550
+ readonly createdAt: "desc";
551
+ } | {
552
+ readonly id: "asc";
553
+ } | {
554
+ role: "asc";
555
+ })[];
556
+ declare const POST_ORDER_BY: ({
557
+ readonly updatedAt: "desc";
558
+ } | {
559
+ readonly createdAt: "desc";
560
+ } | {
561
+ readonly id: "asc";
562
+ } | {
563
+ index: "asc";
564
+ })[];
565
+
566
+ export { ADMIN_ORDER_BY, ORDER_BY, POST_ORDER_BY, createAdminCommandRepository, createAdminQueryRepository, createAdminRefreshTokenCommandRepository, createAdminRefreshTokenQueryRepository, createArgon2Service, createCookieService, createCryptoService, createFileCommandRepository, createFileQueryRepository, createFolderCommandRepository, createFolderQueryRepository, createJwtService, createPostCommandRepository, createPostQueryRepository, createSeoMetadataCommandRepository };