@yimingliao/cms 0.0.53 → 0.0.54
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.
- package/dist/server/index.d.ts +142 -1
- package/dist/server/index.js +316 -1
- package/package.json +1 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -879,6 +879,7 @@ interface ActionContext {
|
|
|
879
879
|
repositories: {
|
|
880
880
|
adminQueryRepository: ReturnType<typeof createAdminQueryRepository>;
|
|
881
881
|
adminCommandRepository: ReturnType<typeof createAdminCommandRepository>;
|
|
882
|
+
adminRefreshTokenQueryRepository: ReturnType<typeof createAdminRefreshTokenQueryRepository>;
|
|
882
883
|
adminRefreshTokenCommandRepository: ReturnType<typeof createAdminRefreshTokenCommandRepository>;
|
|
883
884
|
};
|
|
884
885
|
useCases: {
|
|
@@ -976,6 +977,146 @@ declare function createResetPasswordAction(ctx: ActionContext): ({ formData, }:
|
|
|
976
977
|
formData: ResetPasswordFormData;
|
|
977
978
|
}) => Promise<Result<void>>;
|
|
978
979
|
|
|
980
|
+
declare const adminCreateValidator: (schemas: ReturnType<typeof createSchemas>) => zod.ZodObject<{
|
|
981
|
+
role: zod.ZodEnum<{
|
|
982
|
+
SUPER_ADMIN: "SUPER_ADMIN";
|
|
983
|
+
ADMIN: "ADMIN";
|
|
984
|
+
EDITOR: "EDITOR";
|
|
985
|
+
}>;
|
|
986
|
+
email: zod.ZodEmail;
|
|
987
|
+
password: zod.ZodString;
|
|
988
|
+
avatarImage: zod.ZodNullable<zod.ZodObject<{
|
|
989
|
+
id: zod.ZodString;
|
|
990
|
+
}, zod_v4_core.$strip>>;
|
|
991
|
+
socialLinks: zod.ZodPipe<zod.ZodArray<zod.ZodPipe<zod.ZodTransform<{} | null | undefined, unknown>, zod.ZodNullable<zod.ZodURL>>>, zod.ZodTransform<string[], (string | null)[]>>;
|
|
992
|
+
translations: zod.ZodPipe<zod.ZodArray<zod.ZodObject<{
|
|
993
|
+
locale: zod.ZodString;
|
|
994
|
+
name: zod.ZodNullable<zod.ZodString>;
|
|
995
|
+
authorName: zod.ZodNullable<zod.ZodString>;
|
|
996
|
+
description: zod.ZodNullable<zod.ZodString>;
|
|
997
|
+
jobTitle: zod.ZodNullable<zod.ZodString>;
|
|
998
|
+
url: zod.ZodNullable<zod.ZodPipe<zod.ZodTransform<{} | null | undefined, unknown>, zod.ZodNullable<zod.ZodURL>>>;
|
|
999
|
+
worksFor: zod.ZodNullable<zod.ZodString>;
|
|
1000
|
+
knowsAbout: zod.ZodPipe<zod.ZodArray<zod.ZodString>, zod.ZodTransform<string[], string[]>>;
|
|
1001
|
+
homeLocation: zod.ZodNullable<zod.ZodString>;
|
|
1002
|
+
nationality: zod.ZodNullable<zod.ZodString>;
|
|
1003
|
+
}, zod_v4_core.$strip>>, zod.ZodTransform<{
|
|
1004
|
+
locale: string;
|
|
1005
|
+
name: string | null;
|
|
1006
|
+
authorName: string | null;
|
|
1007
|
+
description: string | null;
|
|
1008
|
+
jobTitle: string | null;
|
|
1009
|
+
url: string | null;
|
|
1010
|
+
worksFor: string | null;
|
|
1011
|
+
knowsAbout: string[];
|
|
1012
|
+
homeLocation: string | null;
|
|
1013
|
+
nationality: string | null;
|
|
1014
|
+
}[], {
|
|
1015
|
+
locale: string;
|
|
1016
|
+
name: string | null;
|
|
1017
|
+
authorName: string | null;
|
|
1018
|
+
description: string | null;
|
|
1019
|
+
jobTitle: string | null;
|
|
1020
|
+
url: string | null;
|
|
1021
|
+
worksFor: string | null;
|
|
1022
|
+
knowsAbout: string[];
|
|
1023
|
+
homeLocation: string | null;
|
|
1024
|
+
nationality: string | null;
|
|
1025
|
+
}[]>>;
|
|
1026
|
+
}, zod_v4_core.$strip>;
|
|
1027
|
+
|
|
1028
|
+
type AdminCreateFormData = zod__default.infer<ReturnType<typeof adminCreateValidator>>;
|
|
1029
|
+
declare function createAdminCreateAction(ctx: ActionContext): ({ formData, }: {
|
|
1030
|
+
formData: AdminCreateFormData;
|
|
1031
|
+
}) => Promise<Result<{
|
|
1032
|
+
admin: Admin;
|
|
1033
|
+
}>>;
|
|
1034
|
+
|
|
1035
|
+
declare const adminUpdateValidator: (schemas: ReturnType<typeof createSchemas>, id: string) => zod.ZodObject<{
|
|
1036
|
+
role: zod.ZodEnum<{
|
|
1037
|
+
SUPER_ADMIN: "SUPER_ADMIN";
|
|
1038
|
+
ADMIN: "ADMIN";
|
|
1039
|
+
EDITOR: "EDITOR";
|
|
1040
|
+
}>;
|
|
1041
|
+
email: zod.ZodOptional<zod.ZodEmail>;
|
|
1042
|
+
avatarImage: zod.ZodNullable<zod.ZodObject<{
|
|
1043
|
+
id: zod.ZodString;
|
|
1044
|
+
}, zod_v4_core.$strip>>;
|
|
1045
|
+
socialLinks: zod.ZodPipe<zod.ZodArray<zod.ZodPipe<zod.ZodTransform<{} | null | undefined, unknown>, zod.ZodNullable<zod.ZodURL>>>, zod.ZodTransform<string[], (string | null)[]>>;
|
|
1046
|
+
translations: zod.ZodPipe<zod.ZodArray<zod.ZodObject<{
|
|
1047
|
+
locale: zod.ZodString;
|
|
1048
|
+
name: zod.ZodNullable<zod.ZodString>;
|
|
1049
|
+
authorName: zod.ZodNullable<zod.ZodString>;
|
|
1050
|
+
description: zod.ZodNullable<zod.ZodString>;
|
|
1051
|
+
jobTitle: zod.ZodNullable<zod.ZodString>;
|
|
1052
|
+
url: zod.ZodNullable<zod.ZodPipe<zod.ZodTransform<{} | null | undefined, unknown>, zod.ZodNullable<zod.ZodURL>>>;
|
|
1053
|
+
worksFor: zod.ZodNullable<zod.ZodString>;
|
|
1054
|
+
knowsAbout: zod.ZodPipe<zod.ZodArray<zod.ZodString>, zod.ZodTransform<string[], string[]>>;
|
|
1055
|
+
homeLocation: zod.ZodNullable<zod.ZodString>;
|
|
1056
|
+
nationality: zod.ZodNullable<zod.ZodString>;
|
|
1057
|
+
}, zod_v4_core.$strip>>, zod.ZodTransform<{
|
|
1058
|
+
locale: string;
|
|
1059
|
+
name: string | null;
|
|
1060
|
+
authorName: string | null;
|
|
1061
|
+
description: string | null;
|
|
1062
|
+
jobTitle: string | null;
|
|
1063
|
+
url: string | null;
|
|
1064
|
+
worksFor: string | null;
|
|
1065
|
+
knowsAbout: string[];
|
|
1066
|
+
homeLocation: string | null;
|
|
1067
|
+
nationality: string | null;
|
|
1068
|
+
}[], {
|
|
1069
|
+
locale: string;
|
|
1070
|
+
name: string | null;
|
|
1071
|
+
authorName: string | null;
|
|
1072
|
+
description: string | null;
|
|
1073
|
+
jobTitle: string | null;
|
|
1074
|
+
url: string | null;
|
|
1075
|
+
worksFor: string | null;
|
|
1076
|
+
knowsAbout: string[];
|
|
1077
|
+
homeLocation: string | null;
|
|
1078
|
+
nationality: string | null;
|
|
1079
|
+
}[]>>;
|
|
1080
|
+
}, zod_v4_core.$strip>;
|
|
1081
|
+
|
|
1082
|
+
type AdminUpdateFormData = zod__default.infer<ReturnType<typeof adminUpdateValidator>>;
|
|
1083
|
+
declare function createAdminUpdateAction(ctx: ActionContext): ({ id, formData, }: {
|
|
1084
|
+
id: string;
|
|
1085
|
+
formData: AdminUpdateFormData;
|
|
1086
|
+
}) => Promise<Result<{
|
|
1087
|
+
admin: Admin;
|
|
1088
|
+
}>>;
|
|
1089
|
+
|
|
1090
|
+
declare function createAdminDeleteAction(ctx: ActionContext): ({ targetId }: {
|
|
1091
|
+
targetId: string;
|
|
1092
|
+
}) => Promise<Result<void>>;
|
|
1093
|
+
|
|
1094
|
+
declare function createAdminFindFullAction(ctx: ActionContext): (params: {
|
|
1095
|
+
id?: string;
|
|
1096
|
+
email?: string;
|
|
1097
|
+
}) => Promise<Result<{
|
|
1098
|
+
admin: AdminFull;
|
|
1099
|
+
}>>;
|
|
1100
|
+
|
|
1101
|
+
declare function createAdminFindListCardsAction(ctx: ActionContext): (params: {
|
|
1102
|
+
searchString?: string;
|
|
1103
|
+
adminIds?: string[];
|
|
1104
|
+
page: number;
|
|
1105
|
+
pageSize: number;
|
|
1106
|
+
}) => Promise<Result<{
|
|
1107
|
+
items: AdminFull[];
|
|
1108
|
+
total: number;
|
|
1109
|
+
}>>;
|
|
1110
|
+
|
|
1111
|
+
declare function createAdminRefreshTokenDeleteAction(ctx: ActionContext): (tokenHash: string) => Promise<Result<void>>;
|
|
1112
|
+
|
|
1113
|
+
declare function createAdminRefreshTokenFindManyAction(ctx: ActionContext): ({ adminId, }: {
|
|
1114
|
+
adminId: string;
|
|
1115
|
+
}) => Promise<Result<{
|
|
1116
|
+
adminRefreshTokens: AdminRefreshToken[];
|
|
1117
|
+
currentToken: AdminRefreshToken;
|
|
1118
|
+
}>>;
|
|
1119
|
+
|
|
979
1120
|
declare class ServerError extends Error {
|
|
980
1121
|
readonly i18nKey?: string;
|
|
981
1122
|
readonly statusCode?: number;
|
|
@@ -994,4 +1135,4 @@ declare class ServerError extends Error {
|
|
|
994
1135
|
static internalServerError(): ServerError;
|
|
995
1136
|
}
|
|
996
1137
|
|
|
997
|
-
export { ADMIN_ORDER_BY, type ActionContext, type ChangePasswordFormData, type EmailUnverifiedFormData, type ForgotPasswordFormData, ORDER_BY, POST_ORDER_BY, type RawCacheKey, type ResetPasswordFormData, ServerError, type SignInFormData, type VerifyEmailFormData, createAdminCommandRepository, createAdminQueryRepository, createAdminRefreshTokenCommandRepository, createAdminRefreshTokenQueryRepository, createArgon2Service, createAuthMiddleware, createAuthUseCases, createCache, createCacheResult, createChangePasswordAction, createCookieService, createCryptoService, createEmailUnverifiedAction, createEmailVerificationEmail, createExecuteAction, createExecuteApi, createExist, createFileCommandRepository, createFileQueryRepository, createFileSchema, createFolderCommandRepository, createFolderQueryRepository, createForgotPasswordAction, createForgotPasswordEmail, createIpRateLimiter, createJwtService, createMultiFileSchema, createPostCommandRepository, createPostQueryRepository, createRenderEmailTemplate, createResetPasswordAction, createSchemas, createSendEmail, createSeoMetadataCommandRepository, createSignInAction, createSignOutAction, createTocItemSchema, createTransporter, createUnique, createVerifyAccessToken, createVerifyAction, createVerifyEmailAction, createVerifyRefreshToken, createZod, normalizeCacheKey };
|
|
1138
|
+
export { ADMIN_ORDER_BY, type ActionContext, type AdminCreateFormData, type AdminUpdateFormData, type ChangePasswordFormData, type EmailUnverifiedFormData, type ForgotPasswordFormData, ORDER_BY, POST_ORDER_BY, type RawCacheKey, type ResetPasswordFormData, ServerError, type SignInFormData, type VerifyEmailFormData, createAdminCommandRepository, createAdminCreateAction, createAdminDeleteAction, createAdminFindFullAction, createAdminFindListCardsAction, createAdminQueryRepository, createAdminRefreshTokenCommandRepository, createAdminRefreshTokenDeleteAction, createAdminRefreshTokenFindManyAction, createAdminRefreshTokenQueryRepository, createAdminUpdateAction, createArgon2Service, createAuthMiddleware, createAuthUseCases, createCache, createCacheResult, createChangePasswordAction, createCookieService, createCryptoService, createEmailUnverifiedAction, createEmailVerificationEmail, createExecuteAction, createExecuteApi, createExist, createFileCommandRepository, createFileQueryRepository, createFileSchema, createFolderCommandRepository, createFolderQueryRepository, createForgotPasswordAction, createForgotPasswordEmail, createIpRateLimiter, createJwtService, createMultiFileSchema, createPostCommandRepository, createPostQueryRepository, createRenderEmailTemplate, createResetPasswordAction, createSchemas, createSendEmail, createSeoMetadataCommandRepository, createSignInAction, createSignOutAction, createTocItemSchema, createTransporter, createUnique, createVerifyAccessToken, createVerifyAction, createVerifyEmailAction, createVerifyRefreshToken, createZod, normalizeCacheKey };
|
package/dist/server/index.js
CHANGED
|
@@ -2310,6 +2310,321 @@ function createResetPasswordAction(ctx) {
|
|
|
2310
2310
|
};
|
|
2311
2311
|
}
|
|
2312
2312
|
|
|
2313
|
+
// src/server/interfaces/actions/resources/admin/commands/create/admin-create-validator.ts
|
|
2314
|
+
var adminCreateValidator = (schemas) => schemas.z.object({
|
|
2315
|
+
// core
|
|
2316
|
+
role: schemas.z.enum(Object.values(ADMIN_ROLES)),
|
|
2317
|
+
email: schemas.email().unique({ table: "admins", column: "email" }),
|
|
2318
|
+
password: schemas.password(),
|
|
2319
|
+
// ----------------------------------------------------------------------------
|
|
2320
|
+
// relations
|
|
2321
|
+
// ----------------------------------------------------------------------------
|
|
2322
|
+
// File
|
|
2323
|
+
avatarImage: schemas.z.object({ id: schemas.id().exist({ table: "files" }) }).nullable(),
|
|
2324
|
+
// better seo
|
|
2325
|
+
socialLinks: schemas.array(schemas.url()),
|
|
2326
|
+
// ----------------------------------------------------------------------------
|
|
2327
|
+
// translation
|
|
2328
|
+
// ----------------------------------------------------------------------------
|
|
2329
|
+
translations: schemas.array(
|
|
2330
|
+
schemas.z.object({
|
|
2331
|
+
// core
|
|
2332
|
+
locale: schemas.locale(),
|
|
2333
|
+
// text
|
|
2334
|
+
name: schemas.text().nullable(),
|
|
2335
|
+
// better seo
|
|
2336
|
+
authorName: schemas.text().nullable(),
|
|
2337
|
+
description: schemas.text().nullable(),
|
|
2338
|
+
jobTitle: schemas.text().nullable(),
|
|
2339
|
+
url: schemas.url().nullable(),
|
|
2340
|
+
worksFor: schemas.text().nullable(),
|
|
2341
|
+
knowsAbout: schemas.array(schemas.text()),
|
|
2342
|
+
homeLocation: schemas.text().nullable(),
|
|
2343
|
+
nationality: schemas.text().nullable()
|
|
2344
|
+
})
|
|
2345
|
+
)
|
|
2346
|
+
});
|
|
2347
|
+
|
|
2348
|
+
// src/server/interfaces/actions/resources/admin/commands/create/create-admin-create-action.ts
|
|
2349
|
+
function createAdminCreateAction(ctx) {
|
|
2350
|
+
const {
|
|
2351
|
+
services: { argon2Service },
|
|
2352
|
+
repositories: { adminCommandRepository },
|
|
2353
|
+
middlewares: { authMiddleware },
|
|
2354
|
+
action: { executeAction },
|
|
2355
|
+
emails: { emailVerificationEmail },
|
|
2356
|
+
schemas
|
|
2357
|
+
} = ctx;
|
|
2358
|
+
return async function adminCreateAction({
|
|
2359
|
+
formData
|
|
2360
|
+
}) {
|
|
2361
|
+
return executeAction(
|
|
2362
|
+
async (translator) => {
|
|
2363
|
+
await authMiddleware.authenticate();
|
|
2364
|
+
const { password, ...rest } = await adminCreateValidator(schemas).parseAsync(formData);
|
|
2365
|
+
const passwordHash = await argon2Service.hash(password);
|
|
2366
|
+
const created = await adminCommandRepository.create({
|
|
2367
|
+
...rest,
|
|
2368
|
+
passwordHash
|
|
2369
|
+
});
|
|
2370
|
+
void emailVerificationEmail.send({ translator, admin: created });
|
|
2371
|
+
return {
|
|
2372
|
+
i18nKey: "ok.admins-store-ok",
|
|
2373
|
+
data: { admin: created }
|
|
2374
|
+
};
|
|
2375
|
+
},
|
|
2376
|
+
{ type: "command" }
|
|
2377
|
+
);
|
|
2378
|
+
};
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2381
|
+
// src/server/interfaces/actions/resources/admin/commands/update/admin-update-validator.ts
|
|
2382
|
+
var adminUpdateValidator = (schemas, id) => schemas.z.object({
|
|
2383
|
+
// core
|
|
2384
|
+
role: schemas.z.enum(Object.values(ADMIN_ROLES)),
|
|
2385
|
+
email: schemas.email().unique({
|
|
2386
|
+
table: "admins",
|
|
2387
|
+
column: "email",
|
|
2388
|
+
excludeSelf: { name: "id", value: id }
|
|
2389
|
+
}).optional(),
|
|
2390
|
+
// ----------------------------------------------------------------------------
|
|
2391
|
+
// relations
|
|
2392
|
+
// ----------------------------------------------------------------------------
|
|
2393
|
+
// File
|
|
2394
|
+
avatarImage: schemas.z.object({ id: schemas.id().exist({ table: "files" }) }).nullable(),
|
|
2395
|
+
// better seo
|
|
2396
|
+
socialLinks: schemas.array(schemas.url()),
|
|
2397
|
+
// ----------------------------------------------------------------------------
|
|
2398
|
+
// translation
|
|
2399
|
+
// ----------------------------------------------------------------------------
|
|
2400
|
+
translations: schemas.array(
|
|
2401
|
+
schemas.z.object({
|
|
2402
|
+
// core
|
|
2403
|
+
locale: schemas.locale(),
|
|
2404
|
+
// text
|
|
2405
|
+
name: schemas.text().nullable(),
|
|
2406
|
+
// better seo
|
|
2407
|
+
authorName: schemas.text().nullable(),
|
|
2408
|
+
description: schemas.text().nullable(),
|
|
2409
|
+
jobTitle: schemas.text().nullable(),
|
|
2410
|
+
url: schemas.url().nullable(),
|
|
2411
|
+
worksFor: schemas.text().nullable(),
|
|
2412
|
+
knowsAbout: schemas.array(schemas.text()),
|
|
2413
|
+
homeLocation: schemas.text().nullable(),
|
|
2414
|
+
nationality: schemas.text().nullable()
|
|
2415
|
+
})
|
|
2416
|
+
)
|
|
2417
|
+
});
|
|
2418
|
+
|
|
2419
|
+
// src/server/interfaces/actions/resources/admin/commands/update/create-admin-update-action.ts
|
|
2420
|
+
function createAdminUpdateAction(ctx) {
|
|
2421
|
+
const {
|
|
2422
|
+
repositories: { adminQueryRepository, adminCommandRepository },
|
|
2423
|
+
middlewares: { authMiddleware },
|
|
2424
|
+
action: { executeAction },
|
|
2425
|
+
emails: { emailVerificationEmail },
|
|
2426
|
+
schemas
|
|
2427
|
+
} = ctx;
|
|
2428
|
+
return async function adminUpdateAction({
|
|
2429
|
+
id,
|
|
2430
|
+
formData
|
|
2431
|
+
}) {
|
|
2432
|
+
return executeAction(
|
|
2433
|
+
async (translator) => {
|
|
2434
|
+
const currentAdmin = await authMiddleware.authenticate();
|
|
2435
|
+
const targetAdmin = await adminQueryRepository.findFull({ id });
|
|
2436
|
+
if (!targetAdmin) throw ServerError.notFound();
|
|
2437
|
+
const isSelf = currentAdmin.id === targetAdmin.id;
|
|
2438
|
+
const canModifyOthers = currentAdmin.role === ADMIN_ROLES.SUPER_ADMIN;
|
|
2439
|
+
if (!isSelf && !canModifyOthers) throw ServerError.forbidden();
|
|
2440
|
+
const { email, ...validatedPayload } = await adminUpdateValidator(
|
|
2441
|
+
schemas,
|
|
2442
|
+
targetAdmin.id
|
|
2443
|
+
).parseAsync(formData);
|
|
2444
|
+
const isUpdatingEmail = email !== targetAdmin.email;
|
|
2445
|
+
if (isUpdatingEmail) {
|
|
2446
|
+
void emailVerificationEmail.send({
|
|
2447
|
+
translator,
|
|
2448
|
+
admin: targetAdmin,
|
|
2449
|
+
...email ? { newEmail: email } : {}
|
|
2450
|
+
});
|
|
2451
|
+
}
|
|
2452
|
+
const updatedAdmin = await adminCommandRepository.update({
|
|
2453
|
+
id: targetAdmin.id,
|
|
2454
|
+
...validatedPayload,
|
|
2455
|
+
...email ? { email } : {},
|
|
2456
|
+
emailVerifiedAt: !isUpdatingEmail ? targetAdmin.emailVerifiedAt : null
|
|
2457
|
+
// Clear emailVerifiedAt if updating a new email
|
|
2458
|
+
});
|
|
2459
|
+
return {
|
|
2460
|
+
i18nKey: !isUpdatingEmail ? "ok.update-ok" : "ok.admins-update-email-ok",
|
|
2461
|
+
data: { admin: updatedAdmin }
|
|
2462
|
+
};
|
|
2463
|
+
},
|
|
2464
|
+
{ type: "command" }
|
|
2465
|
+
);
|
|
2466
|
+
};
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
// src/server/interfaces/actions/resources/admin/commands/delete/create-admin-delete-action.ts
|
|
2470
|
+
function createAdminDeleteAction(ctx) {
|
|
2471
|
+
const {
|
|
2472
|
+
repositories: { adminQueryRepository, adminCommandRepository },
|
|
2473
|
+
middlewares: { authMiddleware },
|
|
2474
|
+
action: { executeAction }
|
|
2475
|
+
} = ctx;
|
|
2476
|
+
return async function adminDeleteAction({ targetId }) {
|
|
2477
|
+
return executeAction(
|
|
2478
|
+
async () => {
|
|
2479
|
+
await authMiddleware.authenticate();
|
|
2480
|
+
const targetAdmin = await adminQueryRepository.findFull({
|
|
2481
|
+
id: targetId
|
|
2482
|
+
});
|
|
2483
|
+
if (!targetAdmin) throw ServerError.notFound();
|
|
2484
|
+
if (targetAdmin.role === ADMIN_ROLES.SUPER_ADMIN) {
|
|
2485
|
+
throw new ServerError({ i18nKey: "error.admins-destroy-forbidden" });
|
|
2486
|
+
}
|
|
2487
|
+
await adminCommandRepository.delete({ id: targetId });
|
|
2488
|
+
return {
|
|
2489
|
+
i18nKey: "ok.destroy-ok"
|
|
2490
|
+
};
|
|
2491
|
+
},
|
|
2492
|
+
{ type: "command" }
|
|
2493
|
+
);
|
|
2494
|
+
};
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
// src/server/interfaces/actions/resources/admin/queries/create-admin-find-full-action.ts
|
|
2498
|
+
function createAdminFindFullAction(ctx) {
|
|
2499
|
+
const {
|
|
2500
|
+
repositories: { adminQueryRepository },
|
|
2501
|
+
action: { executeAction }
|
|
2502
|
+
} = ctx;
|
|
2503
|
+
return async function adminFindFullAction(params) {
|
|
2504
|
+
return executeAction(
|
|
2505
|
+
async () => {
|
|
2506
|
+
const admin = await adminQueryRepository.findFull(params);
|
|
2507
|
+
if (!admin) throw ServerError.notFound();
|
|
2508
|
+
return {
|
|
2509
|
+
data: { admin }
|
|
2510
|
+
};
|
|
2511
|
+
},
|
|
2512
|
+
{
|
|
2513
|
+
type: "query",
|
|
2514
|
+
key: ["admin", "findFullAction", params.id, params.email]
|
|
2515
|
+
}
|
|
2516
|
+
);
|
|
2517
|
+
};
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
// src/server/interfaces/actions/resources/admin/queries/create-admin-find-list-cards-action.ts
|
|
2521
|
+
function createAdminFindListCardsAction(ctx) {
|
|
2522
|
+
const {
|
|
2523
|
+
repositories: { adminQueryRepository },
|
|
2524
|
+
middlewares: { authMiddleware },
|
|
2525
|
+
action: { executeAction }
|
|
2526
|
+
} = ctx;
|
|
2527
|
+
return async function adminFindFullAction(params) {
|
|
2528
|
+
return executeAction(
|
|
2529
|
+
async ({ locale }) => {
|
|
2530
|
+
const { role } = await authMiddleware.authenticate();
|
|
2531
|
+
const { items, total } = await adminQueryRepository.findListCards({
|
|
2532
|
+
...params,
|
|
2533
|
+
locale,
|
|
2534
|
+
role
|
|
2535
|
+
});
|
|
2536
|
+
return {
|
|
2537
|
+
data: { items, total }
|
|
2538
|
+
};
|
|
2539
|
+
},
|
|
2540
|
+
{
|
|
2541
|
+
type: "query",
|
|
2542
|
+
key: [
|
|
2543
|
+
"admin",
|
|
2544
|
+
"findListCardsAction",
|
|
2545
|
+
params.searchString,
|
|
2546
|
+
...params.adminIds ?? [],
|
|
2547
|
+
params.page,
|
|
2548
|
+
params.pageSize
|
|
2549
|
+
]
|
|
2550
|
+
}
|
|
2551
|
+
);
|
|
2552
|
+
};
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
// src/server/interfaces/actions/resources/admin-refresh-token/commands/delete/create-admin-refresh-token-delete-action.ts
|
|
2556
|
+
function createAdminRefreshTokenDeleteAction(ctx) {
|
|
2557
|
+
const {
|
|
2558
|
+
repositories: {
|
|
2559
|
+
adminRefreshTokenQueryRepository,
|
|
2560
|
+
adminRefreshTokenCommandRepository
|
|
2561
|
+
},
|
|
2562
|
+
middlewares: { authMiddleware },
|
|
2563
|
+
action: { executeAction }
|
|
2564
|
+
} = ctx;
|
|
2565
|
+
return async function adminRefreshTokenDeleteAction(tokenHash) {
|
|
2566
|
+
return executeAction(
|
|
2567
|
+
async () => {
|
|
2568
|
+
const currentAdmin = await authMiddleware.authenticate();
|
|
2569
|
+
const targetAdminRefreshToken = await adminRefreshTokenQueryRepository.findByToken({
|
|
2570
|
+
tokenHash
|
|
2571
|
+
});
|
|
2572
|
+
if (!targetAdminRefreshToken) throw ServerError.notFound();
|
|
2573
|
+
const isSelf = currentAdmin.id === targetAdminRefreshToken.adminId;
|
|
2574
|
+
const canModifyOthers = currentAdmin.role === ADMIN_ROLES.SUPER_ADMIN;
|
|
2575
|
+
if (!isSelf && !canModifyOthers) throw ServerError.forbidden();
|
|
2576
|
+
await adminRefreshTokenCommandRepository.delete({
|
|
2577
|
+
id: targetAdminRefreshToken.id
|
|
2578
|
+
});
|
|
2579
|
+
return {
|
|
2580
|
+
i18nKey: "ok.destroy-ok"
|
|
2581
|
+
};
|
|
2582
|
+
},
|
|
2583
|
+
{ type: "command" }
|
|
2584
|
+
);
|
|
2585
|
+
};
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
// src/server/interfaces/actions/resources/admin-refresh-token/queries/create-admin-refresh-token-find-full-action.ts
|
|
2589
|
+
function createAdminRefreshTokenFindManyAction(ctx) {
|
|
2590
|
+
const {
|
|
2591
|
+
services: { cryptoService, cookieService },
|
|
2592
|
+
repositories: { adminRefreshTokenQueryRepository },
|
|
2593
|
+
middlewares: { authMiddleware },
|
|
2594
|
+
action: { executeAction },
|
|
2595
|
+
config: { refreshTokenName }
|
|
2596
|
+
} = ctx;
|
|
2597
|
+
return async function adminRefreshTokenFindManyAction({
|
|
2598
|
+
adminId
|
|
2599
|
+
}) {
|
|
2600
|
+
return executeAction(
|
|
2601
|
+
async () => {
|
|
2602
|
+
await authMiddleware.authenticate();
|
|
2603
|
+
const token = await cookieService.getSignedCookie({
|
|
2604
|
+
name: refreshTokenName
|
|
2605
|
+
});
|
|
2606
|
+
const currentToken = await adminRefreshTokenQueryRepository.findByToken(
|
|
2607
|
+
{ tokenHash: cryptoService.hash(token) }
|
|
2608
|
+
);
|
|
2609
|
+
if (!currentToken) throw ServerError.notFound();
|
|
2610
|
+
const adminRefreshTokens = await adminRefreshTokenQueryRepository.findManyByAdminId({
|
|
2611
|
+
adminId
|
|
2612
|
+
});
|
|
2613
|
+
return {
|
|
2614
|
+
data: {
|
|
2615
|
+
adminRefreshTokens,
|
|
2616
|
+
currentToken
|
|
2617
|
+
}
|
|
2618
|
+
};
|
|
2619
|
+
},
|
|
2620
|
+
{
|
|
2621
|
+
type: "query",
|
|
2622
|
+
key: ["admin-refresh-token", "findManyAction", adminId]
|
|
2623
|
+
}
|
|
2624
|
+
);
|
|
2625
|
+
};
|
|
2626
|
+
}
|
|
2627
|
+
|
|
2313
2628
|
// src/server/applications/auth/create-auth-use-cases.ts
|
|
2314
2629
|
function createAuthUseCases({
|
|
2315
2630
|
prisma,
|
|
@@ -2489,4 +2804,4 @@ function createForgotPasswordEmail({
|
|
|
2489
2804
|
};
|
|
2490
2805
|
}
|
|
2491
2806
|
|
|
2492
|
-
export { ADMIN_ORDER_BY, ORDER_BY, POST_ORDER_BY, ServerError, createAdminCommandRepository, createAdminQueryRepository, createAdminRefreshTokenCommandRepository, createAdminRefreshTokenQueryRepository, createArgon2Service, createAuthMiddleware, createAuthUseCases, createCache, createCacheResult, createChangePasswordAction, createCookieService, createCryptoService, createEmailUnverifiedAction, createEmailVerificationEmail, createExecuteAction, createExecuteApi, createExist, createFileCommandRepository, createFileQueryRepository, createFileSchema, createFolderCommandRepository, createFolderQueryRepository, createForgotPasswordAction, createForgotPasswordEmail, createIpRateLimiter, createJwtService, createMultiFileSchema, createPostCommandRepository, createPostQueryRepository, createRenderEmailTemplate, createResetPasswordAction, createSchemas, createSendEmail, createSeoMetadataCommandRepository, createSignInAction, createSignOutAction, createTocItemSchema, createTransporter, createUnique, createVerifyAccessToken, createVerifyAction, createVerifyEmailAction, createVerifyRefreshToken, createZod, normalizeCacheKey };
|
|
2807
|
+
export { ADMIN_ORDER_BY, ORDER_BY, POST_ORDER_BY, ServerError, createAdminCommandRepository, createAdminCreateAction, createAdminDeleteAction, createAdminFindFullAction, createAdminFindListCardsAction, createAdminQueryRepository, createAdminRefreshTokenCommandRepository, createAdminRefreshTokenDeleteAction, createAdminRefreshTokenFindManyAction, createAdminRefreshTokenQueryRepository, createAdminUpdateAction, createArgon2Service, createAuthMiddleware, createAuthUseCases, createCache, createCacheResult, createChangePasswordAction, createCookieService, createCryptoService, createEmailUnverifiedAction, createEmailVerificationEmail, createExecuteAction, createExecuteApi, createExist, createFileCommandRepository, createFileQueryRepository, createFileSchema, createFolderCommandRepository, createFolderQueryRepository, createForgotPasswordAction, createForgotPasswordEmail, createIpRateLimiter, createJwtService, createMultiFileSchema, createPostCommandRepository, createPostQueryRepository, createRenderEmailTemplate, createResetPasswordAction, createSchemas, createSendEmail, createSeoMetadataCommandRepository, createSignInAction, createSignOutAction, createTocItemSchema, createTransporter, createUnique, createVerifyAccessToken, createVerifyAction, createVerifyEmailAction, createVerifyRefreshToken, createZod, normalizeCacheKey };
|