[FEAT] update back with new archidata
This commit is contained in:
parent
396455d611
commit
83e019c8fa
@ -290,11 +290,15 @@ public class ApplicationResource {
|
||||
// If the USER is not override, the system add by default USER
|
||||
applicationRight.put("USER", PartRight.READ_WRITE);
|
||||
}
|
||||
final Map<String, Integer> rightForFront = new HashMap<>();
|
||||
for (final Map.Entry<String, PartRight> entry : applicationRight.entrySet()) {
|
||||
rightForFront.put(entry.getKey(), entry.getValue().getValue());
|
||||
}
|
||||
final Map<String, Object> outRight = new HashMap<>();
|
||||
// we set the right in the under map to manage multiple application group right.
|
||||
// and in some application user can see other user or all user of the
|
||||
// application
|
||||
outRight.put(applicationName, applicationRight);
|
||||
outRight.put(applicationName, rightForFront);
|
||||
final String ret = JWTWrapper.generateJWToken(gc.userByToken.id, gc.userByToken.name, "KarAuth",
|
||||
applicationName, outRight, -appl.ttl);
|
||||
// logger.debug(" ==> generate token: {}", ret);
|
||||
|
@ -82,25 +82,26 @@ public class UserResource {
|
||||
|
||||
@GET
|
||||
@RolesAllowed("ADMIN")
|
||||
public List<UserAuth> gets() throws Exception {
|
||||
return DataAccess.gets(UserAuth.class);
|
||||
public List<UserAuthGet> gets() throws Exception {
|
||||
final List<UserAuthGet> out = DataAccess.gets(UserAuthGet.class);
|
||||
return out;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed({ "ADMIN", "USER" })
|
||||
public UserAuth get(@Context final SecurityContext sc, @PathParam("id") final long id) throws Exception {
|
||||
public UserAuthGet get(@Context final SecurityContext sc, @PathParam("id") final long id) throws Exception {
|
||||
if (!sc.isUserInRole("ADMIN")) {
|
||||
// in case of user we need to check if it get his own id parameters:
|
||||
final UserAuth ret = DataAccess.get(UserAuth.class, id, new AccessDeletedItems());
|
||||
final UserAuthGet ret = DataAccess.get(UserAuthGet.class, id, new AccessDeletedItems());
|
||||
return ret;
|
||||
}
|
||||
final UserAuth ret = DataAccess.get(UserAuth.class, id);
|
||||
final UserAuthGet ret = DataAccess.get(UserAuthGet.class, id);
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
// Find element in deleted
|
||||
return DataAccess.get(UserAuth.class, id, new AccessDeletedItems(), new ReadAllColumn());
|
||||
return DataAccess.get(UserAuthGet.class, id, new AccessDeletedItems(), new ReadAllColumn());
|
||||
}
|
||||
|
||||
@POST
|
||||
@ -329,10 +330,14 @@ public class UserResource {
|
||||
// If the USER is not override, the system add by default USER
|
||||
ssoRight.put("USER", PartRight.READ_WRITE);
|
||||
}
|
||||
final Map<String, Integer> rightForFront = new HashMap<>();
|
||||
for (final Map.Entry<String, PartRight> entry : ssoRight.entrySet()) {
|
||||
rightForFront.put(entry.getKey(), entry.getValue().getValue());
|
||||
}
|
||||
LOGGER.debug("Get new token with right: {}", ssoRight);
|
||||
final Map<String, Object> outRight = new HashMap<>();
|
||||
// we set the right in the under map to manage multiple application group right. and in some application user can see other user or all user of the application
|
||||
outRight.put(UserResource.APPLICATION, ssoRight);
|
||||
outRight.put(UserResource.APPLICATION, rightForFront);
|
||||
// TODO: maybe correct this get of TTL...
|
||||
final String ret = JWTWrapper.generateJWToken(user.id, user.login, "KarAuth", UserResource.APPLICATION,
|
||||
outRight, expirationTimeInMinutes);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.kar.karso.model;
|
||||
|
||||
import org.kar.archidata.annotation.DataIfNotExists;
|
||||
import org.kar.archidata.annotation.DataJson;
|
||||
import org.kar.archidata.filter.PartRight;
|
||||
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||
|
||||
@ -30,5 +31,6 @@ public class Right extends GenericDataSoftDelete {
|
||||
public Long rightDescriptionId;
|
||||
@Column(length = 1024, nullable = false)
|
||||
@Schema(description = "Value of the right")
|
||||
@DataJson
|
||||
public PartRight value;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import org.kar.archidata.model.User;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.annotation.Nullable;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.Table;
|
||||
@ -24,6 +25,7 @@ public class UserAuth extends User {
|
||||
@Column(length = 128, nullable = false)
|
||||
@Size(min = 128, max = 128)
|
||||
@Pattern(regexp = "^[a-zA-Z0-9]{128}$")
|
||||
@Nullable
|
||||
public String password;
|
||||
/*
|
||||
@Column(length = 128)
|
||||
|
@ -16,7 +16,7 @@ import org.kar.archidata.model.GetToken;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.RESTApi;
|
||||
import org.kar.karso.model.DataGetToken;
|
||||
import org.kar.karso.model.UserAuth;
|
||||
import org.kar.karso.model.UserAuthGet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -57,7 +57,7 @@ public class TestUsers {
|
||||
@Order(1)
|
||||
@Test
|
||||
public void getsValue() throws RESTErrorResponseException, IOException, InterruptedException {
|
||||
final List<UserAuth> listUsers = api.gets(UserAuth.class, TestUsers.ENDPOINT_NAME);
|
||||
final List<UserAuthGet> listUsers = api.gets(UserAuthGet.class, TestUsers.ENDPOINT_NAME);
|
||||
Assertions.assertNotNull(listUsers);
|
||||
Assertions.assertEquals(1, listUsers.size());
|
||||
Assertions.assertEquals(1, listUsers.get(0).id);
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
} from "../rest-tools";
|
||||
|
||||
import {
|
||||
UUID,
|
||||
ObjectId,
|
||||
} from "../model";
|
||||
|
||||
export namespace DataResource {
|
||||
@ -30,13 +30,13 @@ export namespace DataResource {
|
||||
},
|
||||
params: {
|
||||
name: string,
|
||||
uuid: UUID,
|
||||
oid: ObjectId,
|
||||
},
|
||||
data: string,
|
||||
}): Promise<object> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/data/{uuid}/{name}",
|
||||
endPoint: "/data/{oid}/{name}",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
},
|
||||
restConfig,
|
||||
@ -59,13 +59,13 @@ export namespace DataResource {
|
||||
Authorization?: string,
|
||||
},
|
||||
params: {
|
||||
uuid: UUID,
|
||||
oid: ObjectId,
|
||||
},
|
||||
data: string,
|
||||
}): Promise<object> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/data/{uuid}",
|
||||
endPoint: "/data/{oid}",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
},
|
||||
restConfig,
|
||||
@ -88,13 +88,13 @@ export namespace DataResource {
|
||||
Authorization?: string,
|
||||
},
|
||||
params: {
|
||||
uuid: UUID,
|
||||
oid: ObjectId,
|
||||
},
|
||||
data: string,
|
||||
}): Promise<object> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/data/thumbnail/{uuid}",
|
||||
endPoint: "/data/thumbnail/{oid}",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
},
|
||||
restConfig,
|
||||
|
@ -15,10 +15,12 @@ import {
|
||||
DataGetTokenWrite,
|
||||
GetToken,
|
||||
Long,
|
||||
PartRight,
|
||||
UserAuth,
|
||||
UserAuthGet,
|
||||
UserCreateWrite,
|
||||
UserOut,
|
||||
ZodPartRight,
|
||||
ZodUserAuthGet,
|
||||
isGetToken,
|
||||
isUserAuth,
|
||||
@ -63,8 +65,27 @@ export namespace UserResource {
|
||||
data,
|
||||
}, isUserAuthGet);
|
||||
};
|
||||
export function get({
|
||||
restConfig,
|
||||
params,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
params: {
|
||||
id: Long,
|
||||
},
|
||||
}): Promise<UserAuthGet> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/users/{id}",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
}, isUserAuthGet);
|
||||
};
|
||||
|
||||
export const ZodGetApplicationRightTypeReturn = zod.record(zod.string(), zod.any());
|
||||
export const ZodGetApplicationRightTypeReturn = zod.record(zod.string(), ZodPartRight);
|
||||
export type GetApplicationRightTypeReturn = zod.infer<typeof ZodGetApplicationRightTypeReturn>;
|
||||
|
||||
export function isGetApplicationRightTypeReturn(data: any): data is GetApplicationRightTypeReturn {
|
||||
@ -129,44 +150,25 @@ export namespace UserResource {
|
||||
data,
|
||||
}, isGetToken);
|
||||
};
|
||||
export function getUser({
|
||||
restConfig,
|
||||
params,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
params: {
|
||||
id: Long,
|
||||
},
|
||||
}): Promise<UserAuthGet> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/users/{id}",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
}, isUserAuthGet);
|
||||
};
|
||||
|
||||
export const ZodGetUsersTypeReturn = zod.array(ZodUserAuthGet);
|
||||
export type GetUsersTypeReturn = zod.infer<typeof ZodGetUsersTypeReturn>;
|
||||
export const ZodGetsTypeReturn = zod.array(ZodUserAuthGet);
|
||||
export type GetsTypeReturn = zod.infer<typeof ZodGetsTypeReturn>;
|
||||
|
||||
export function isGetUsersTypeReturn(data: any): data is GetUsersTypeReturn {
|
||||
export function isGetsTypeReturn(data: any): data is GetsTypeReturn {
|
||||
try {
|
||||
ZodGetUsersTypeReturn.parse(data);
|
||||
ZodGetsTypeReturn.parse(data);
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
console.log(`Fail to parse data type='ZodGetUsersTypeReturn' error=${e}`);
|
||||
console.log(`Fail to parse data type='ZodGetsTypeReturn' error=${e}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function getUsers({
|
||||
export function gets({
|
||||
restConfig,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
}): Promise<GetUsersTypeReturn> {
|
||||
}): Promise<GetsTypeReturn> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/users/",
|
||||
@ -174,7 +176,7 @@ export namespace UserResource {
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
}, isGetUsersTypeReturn);
|
||||
}, isGetsTypeReturn);
|
||||
};
|
||||
export function isEmailExist({
|
||||
restConfig,
|
||||
@ -238,7 +240,7 @@ export namespace UserResource {
|
||||
}, isUserAuth);
|
||||
};
|
||||
|
||||
export const ZodPatchApplicationRightTypeReturn = zod.record(zod.string(), zod.any());
|
||||
export const ZodPatchApplicationRightTypeReturn = zod.record(zod.string(), ZodPartRight);
|
||||
export type PatchApplicationRightTypeReturn = zod.infer<typeof ZodPatchApplicationRightTypeReturn>;
|
||||
|
||||
export function isPatchApplicationRightTypeReturn(data: any): data is PatchApplicationRightTypeReturn {
|
||||
@ -261,7 +263,7 @@ export namespace UserResource {
|
||||
applicationId: Long,
|
||||
userId: Long,
|
||||
},
|
||||
data: {[key: string]: object;},
|
||||
data: {[key: string]: PartRight;},
|
||||
}): Promise<PatchApplicationRightTypeReturn> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
|
@ -21,8 +21,10 @@ export function isAddUserData(data: any): data is AddUserData {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodAddUserDataWrite = zod.object({
|
||||
userId: ZodLong.nullable().optional(),
|
||||
|
||||
export const ZodAddUserDataWrite = ZodAddUserData.partial();
|
||||
});
|
||||
|
||||
export type AddUserDataWrite = zod.infer<typeof ZodAddUserDataWrite>;
|
||||
|
||||
|
@ -24,8 +24,13 @@ export function isApplicationSmall(data: any): data is ApplicationSmall {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodApplicationSmallWrite = zod.object({
|
||||
id: ZodLong.nullable().optional(),
|
||||
name: zod.string().max(255).nullable().optional(),
|
||||
description: zod.string().max(255).nullable().optional(),
|
||||
redirect: zod.string().max(255).nullable().optional(),
|
||||
|
||||
export const ZodApplicationSmallWrite = ZodApplicationSmall.partial();
|
||||
});
|
||||
|
||||
export type ApplicationSmallWrite = zod.infer<typeof ZodApplicationSmallWrite>;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
*/
|
||||
import { z as zod } from "zod";
|
||||
|
||||
import {ZodGenericToken} from "./generic-token";
|
||||
import {ZodGenericToken, ZodGenericTokenWrite } from "./generic-token";
|
||||
|
||||
export const ZodApplicationToken = ZodGenericToken.extend({
|
||||
|
||||
@ -20,14 +20,9 @@ export function isApplicationToken(data: any): data is ApplicationToken {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodApplicationTokenWrite = ZodGenericTokenWrite.extend({
|
||||
|
||||
export const ZodApplicationTokenWrite = ZodApplicationToken.omit({
|
||||
deleted: true,
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
|
||||
}).partial();
|
||||
});
|
||||
|
||||
export type ApplicationTokenWrite = zod.infer<typeof ZodApplicationTokenWrite>;
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
import { z as zod } from "zod";
|
||||
|
||||
import {ZodInteger} from "./integer";
|
||||
import {ZodGenericDataSoftDelete} from "./generic-data-soft-delete";
|
||||
import {ZodGenericDataSoftDelete, ZodGenericDataSoftDeleteWrite } from "./generic-data-soft-delete";
|
||||
|
||||
export const ZodApplication = ZodGenericDataSoftDelete.extend({
|
||||
name: zod.string().max(256).optional(),
|
||||
@ -34,14 +34,22 @@ export function isApplication(data: any): data is Application {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodApplicationWrite = ZodGenericDataSoftDeleteWrite.extend({
|
||||
name: zod.string().max(256).nullable().optional(),
|
||||
description: zod.string().max(2048).nullable().optional(),
|
||||
redirect: zod.string().max(2048).optional(),
|
||||
redirectDev: zod.string().max(2048).nullable().optional(),
|
||||
notification: zod.string().max(2048).nullable().optional(),
|
||||
/**
|
||||
* Expiration time
|
||||
*/
|
||||
ttl: ZodInteger.optional(),
|
||||
/**
|
||||
* Right is manage with Karso
|
||||
*/
|
||||
manageRight: zod.boolean().optional(),
|
||||
|
||||
export const ZodApplicationWrite = ZodApplication.omit({
|
||||
deleted: true,
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
|
||||
}).partial();
|
||||
});
|
||||
|
||||
export type ApplicationWrite = zod.infer<typeof ZodApplicationWrite>;
|
||||
|
||||
|
@ -5,11 +5,11 @@ import { z as zod } from "zod";
|
||||
|
||||
|
||||
export const ZodChangePassword = zod.object({
|
||||
method: zod.string().max(32).optional(),
|
||||
login: zod.string().max(512).optional(),
|
||||
time: zod.string().max(64).optional(),
|
||||
password: zod.string().max(128).optional(),
|
||||
newPassword: zod.string().max(128).optional(),
|
||||
method: zod.string().min(2).max(2),
|
||||
login: zod.string().min(3).max(128),
|
||||
time: zod.string().min(20).max(64),
|
||||
password: zod.string().min(128).max(128),
|
||||
newPassword: zod.string().min(128).max(128),
|
||||
|
||||
});
|
||||
|
||||
@ -24,8 +24,14 @@ export function isChangePassword(data: any): data is ChangePassword {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodChangePasswordWrite = zod.object({
|
||||
method: zod.string().min(2).max(2).optional(),
|
||||
login: zod.string().min(3).max(128).optional(),
|
||||
time: zod.string().min(20).max(64).optional(),
|
||||
password: zod.string().min(128).max(128).optional(),
|
||||
newPassword: zod.string().min(128).max(128).optional(),
|
||||
|
||||
export const ZodChangePasswordWrite = ZodChangePassword.partial();
|
||||
});
|
||||
|
||||
export type ChangePasswordWrite = zod.infer<typeof ZodChangePasswordWrite>;
|
||||
|
||||
|
@ -21,8 +21,11 @@ export function isClientToken(data: any): data is ClientToken {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodClientTokenWrite = zod.object({
|
||||
url: zod.string().max(1024).nullable().optional(),
|
||||
jwt: zod.string().nullable().optional(),
|
||||
|
||||
export const ZodClientTokenWrite = ZodClientToken.partial();
|
||||
});
|
||||
|
||||
export type ClientTokenWrite = zod.infer<typeof ZodClientTokenWrite>;
|
||||
|
||||
|
@ -22,8 +22,11 @@ export function isCreateTokenRequest(data: any): data is CreateTokenRequest {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodCreateTokenRequestWrite = zod.object({
|
||||
name: zod.string().max(255).nullable().optional(),
|
||||
validity: ZodInteger.nullable().optional(),
|
||||
|
||||
export const ZodCreateTokenRequestWrite = ZodCreateTokenRequest.partial();
|
||||
});
|
||||
|
||||
export type CreateTokenRequestWrite = zod.infer<typeof ZodCreateTokenRequestWrite>;
|
||||
|
||||
|
@ -5,6 +5,10 @@ import { z as zod } from "zod";
|
||||
|
||||
|
||||
export const ZodDataGetToken = zod.object({
|
||||
login: zod.string().min(3).max(128),
|
||||
method: zod.string().min(2).max(2),
|
||||
time: zod.string().min(20).max(64),
|
||||
password: zod.string().min(128).max(128),
|
||||
|
||||
});
|
||||
|
||||
@ -19,8 +23,13 @@ export function isDataGetToken(data: any): data is DataGetToken {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodDataGetTokenWrite = zod.object({
|
||||
login: zod.string().min(3).max(128).optional(),
|
||||
method: zod.string().min(2).max(2).optional(),
|
||||
time: zod.string().min(20).max(64).optional(),
|
||||
password: zod.string().min(128).max(128).optional(),
|
||||
|
||||
export const ZodDataGetTokenWrite = ZodDataGetToken.partial();
|
||||
});
|
||||
|
||||
export type DataGetTokenWrite = zod.infer<typeof ZodDataGetTokenWrite>;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
*/
|
||||
import { z as zod } from "zod";
|
||||
|
||||
import {ZodGenericData} from "./generic-data";
|
||||
import {ZodGenericData, ZodGenericDataWrite } from "./generic-data";
|
||||
|
||||
export const ZodGenericDataSoftDelete = ZodGenericData.extend({
|
||||
/**
|
||||
@ -24,14 +24,9 @@ export function isGenericDataSoftDelete(data: any): data is GenericDataSoftDelet
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodGenericDataSoftDeleteWrite = ZodGenericDataWrite.extend({
|
||||
|
||||
export const ZodGenericDataSoftDeleteWrite = ZodGenericDataSoftDelete.omit({
|
||||
deleted: true,
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
|
||||
}).partial();
|
||||
});
|
||||
|
||||
export type GenericDataSoftDeleteWrite = zod.infer<typeof ZodGenericDataSoftDeleteWrite>;
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
import { z as zod } from "zod";
|
||||
|
||||
import {ZodLong} from "./long";
|
||||
import {ZodGenericTiming} from "./generic-timing";
|
||||
import {ZodGenericTiming, ZodGenericTimingWrite } from "./generic-timing";
|
||||
|
||||
export const ZodGenericData = ZodGenericTiming.extend({
|
||||
/**
|
||||
@ -25,13 +25,9 @@ export function isGenericData(data: any): data is GenericData {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodGenericDataWrite = ZodGenericTimingWrite.extend({
|
||||
|
||||
export const ZodGenericDataWrite = ZodGenericData.omit({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
|
||||
}).partial();
|
||||
});
|
||||
|
||||
export type GenericDataWrite = zod.infer<typeof ZodGenericDataWrite>;
|
||||
|
||||
|
@ -28,12 +28,9 @@ export function isGenericTiming(data: any): data is GenericTiming {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodGenericTimingWrite = zod.object({
|
||||
|
||||
export const ZodGenericTimingWrite = ZodGenericTiming.omit({
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
|
||||
}).partial();
|
||||
});
|
||||
|
||||
export type GenericTimingWrite = zod.infer<typeof ZodGenericTimingWrite>;
|
||||
|
||||
|
@ -5,7 +5,7 @@ import { z as zod } from "zod";
|
||||
|
||||
import {ZodLong} from "./long";
|
||||
import {ZodTimestamp} from "./timestamp";
|
||||
import {ZodGenericDataSoftDelete} from "./generic-data-soft-delete";
|
||||
import {ZodGenericDataSoftDelete, ZodGenericDataSoftDeleteWrite } from "./generic-data-soft-delete";
|
||||
|
||||
export const ZodGenericToken = ZodGenericDataSoftDelete.extend({
|
||||
parentId: ZodLong,
|
||||
@ -26,14 +26,13 @@ export function isGenericToken(data: any): data is GenericToken {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodGenericTokenWrite = ZodGenericDataSoftDeleteWrite.extend({
|
||||
parentId: ZodLong.optional(),
|
||||
name: zod.string().optional(),
|
||||
endValidityTime: ZodTimestamp.optional(),
|
||||
token: zod.string().optional(),
|
||||
|
||||
export const ZodGenericTokenWrite = ZodGenericToken.omit({
|
||||
deleted: true,
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
|
||||
}).partial();
|
||||
});
|
||||
|
||||
export type GenericTokenWrite = zod.infer<typeof ZodGenericTokenWrite>;
|
||||
|
||||
|
@ -20,8 +20,10 @@ export function isGetSignUpAvailable(data: any): data is GetSignUpAvailable {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodGetSignUpAvailableWrite = zod.object({
|
||||
signup: zod.boolean(),
|
||||
|
||||
export const ZodGetSignUpAvailableWrite = ZodGetSignUpAvailable.partial();
|
||||
});
|
||||
|
||||
export type GetSignUpAvailableWrite = zod.infer<typeof ZodGetSignUpAvailableWrite>;
|
||||
|
||||
|
@ -20,8 +20,10 @@ export function isGetToken(data: any): data is GetToken {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodGetTokenWrite = zod.object({
|
||||
jwt: zod.string().optional(),
|
||||
|
||||
export const ZodGetTokenWrite = ZodGetToken.partial();
|
||||
});
|
||||
|
||||
export type GetTokenWrite = zod.infer<typeof ZodGetTokenWrite>;
|
||||
|
||||
|
@ -15,10 +15,11 @@ export * from "./generic-timing"
|
||||
export * from "./generic-token"
|
||||
export * from "./get-sign-up-available"
|
||||
export * from "./get-token"
|
||||
export * from "./int"
|
||||
export * from "./integer"
|
||||
export * from "./iso-date"
|
||||
export * from "./long"
|
||||
export * from "./object-id"
|
||||
export * from "./part-right"
|
||||
export * from "./public-key"
|
||||
export * from "./rest-error-response"
|
||||
export * from "./right"
|
||||
|
8
front/src/back-api/model/object-id.ts
Normal file
8
front/src/back-api/model/object-id.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Interface of the server (auto-generated code)
|
||||
*/
|
||||
import { z as zod } from "zod";
|
||||
|
||||
|
||||
export const ZodObjectId = zod.string().length(24, "Invalid ObjectId length").regex(/^[a-fA-F0-9]{24}$/, "Invalid ObjectId format");
|
||||
export type ObjectId = zod.infer<typeof ZodObjectId>;
|
24
front/src/back-api/model/part-right.ts
Normal file
24
front/src/back-api/model/part-right.ts
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Interface of the server (auto-generated code)
|
||||
*/
|
||||
import { z as zod } from "zod";
|
||||
|
||||
|
||||
export enum PartRight {
|
||||
READ = 1,
|
||||
NONE = 0,
|
||||
WRITE = 2,
|
||||
READ_WRITE = 3,
|
||||
};
|
||||
|
||||
export const ZodPartRight = zod.nativeEnum(PartRight);
|
||||
|
||||
export function isPartRight(data: any): data is PartRight {
|
||||
try {
|
||||
ZodPartRight.parse(data);
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
console.log(`Fail to parse data type='ZodPartRight' error=${e}`);
|
||||
return false;
|
||||
}
|
||||
}
|
@ -20,8 +20,10 @@ export function isPublicKey(data: any): data is PublicKey {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodPublicKeyWrite = zod.object({
|
||||
key: zod.string().max(255).nullable().optional(),
|
||||
|
||||
export const ZodPublicKeyWrite = ZodPublicKey.partial();
|
||||
});
|
||||
|
||||
export type PublicKeyWrite = zod.infer<typeof ZodPublicKeyWrite>;
|
||||
|
||||
|
@ -3,15 +3,15 @@
|
||||
*/
|
||||
import { z as zod } from "zod";
|
||||
|
||||
import {ZodUUID} from "./uuid";
|
||||
import {Zodint} from "./int";
|
||||
import {ZodObjectId} from "./object-id";
|
||||
import {ZodInteger} from "./integer";
|
||||
|
||||
export const ZodRestErrorResponse = zod.object({
|
||||
uuid: ZodUUID.optional(),
|
||||
oid: ZodObjectId.optional(),
|
||||
name: zod.string(),
|
||||
message: zod.string(),
|
||||
time: zod.string(),
|
||||
status: Zodint,
|
||||
status: ZodInteger,
|
||||
statusMessage: zod.string(),
|
||||
|
||||
});
|
||||
@ -27,17 +27,3 @@ export function isRestErrorResponse(data: any): data is RestErrorResponse {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export const ZodRestErrorResponseWrite = ZodRestErrorResponse.partial();
|
||||
|
||||
export type RestErrorResponseWrite = zod.infer<typeof ZodRestErrorResponseWrite>;
|
||||
|
||||
export function isRestErrorResponseWrite(data: any): data is RestErrorResponseWrite {
|
||||
try {
|
||||
ZodRestErrorResponseWrite.parse(data);
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
console.log(`Fail to parse data type='ZodRestErrorResponseWrite' error=${e}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
import { z as zod } from "zod";
|
||||
|
||||
import {ZodLong} from "./long";
|
||||
import {ZodGenericDataSoftDelete} from "./generic-data-soft-delete";
|
||||
import {ZodGenericDataSoftDelete, ZodGenericDataSoftDeleteWrite } from "./generic-data-soft-delete";
|
||||
|
||||
export const ZodRightDescription = ZodGenericDataSoftDelete.extend({
|
||||
/**
|
||||
@ -23,14 +23,6 @@ export const ZodRightDescription = ZodGenericDataSoftDelete.extend({
|
||||
* Description of the right
|
||||
*/
|
||||
description: zod.string().max(1024),
|
||||
/**
|
||||
* default value if Never set
|
||||
*/
|
||||
defaultValue: zod.string().max(1024).optional(),
|
||||
/**
|
||||
* Type of the property
|
||||
*/
|
||||
type: zod.string().max(16),
|
||||
|
||||
});
|
||||
|
||||
@ -45,14 +37,25 @@ export function isRightDescription(data: any): data is RightDescription {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodRightDescriptionWrite = ZodGenericDataSoftDeleteWrite.extend({
|
||||
/**
|
||||
* Application id that have the reference of the right
|
||||
*/
|
||||
applicationId: ZodLong.optional(),
|
||||
/**
|
||||
* Key of the property
|
||||
*/
|
||||
key: zod.string().max(64).optional(),
|
||||
/**
|
||||
* Title of the right
|
||||
*/
|
||||
title: zod.string().max(1024).optional(),
|
||||
/**
|
||||
* Description of the right
|
||||
*/
|
||||
description: zod.string().max(1024).optional(),
|
||||
|
||||
export const ZodRightDescriptionWrite = ZodRightDescription.omit({
|
||||
deleted: true,
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
|
||||
}).partial();
|
||||
});
|
||||
|
||||
export type RightDescriptionWrite = zod.infer<typeof ZodRightDescriptionWrite>;
|
||||
|
||||
|
@ -4,7 +4,8 @@
|
||||
import { z as zod } from "zod";
|
||||
|
||||
import {ZodLong} from "./long";
|
||||
import {ZodGenericDataSoftDelete} from "./generic-data-soft-delete";
|
||||
import {ZodPartRight} from "./part-right";
|
||||
import {ZodGenericDataSoftDelete, ZodGenericDataSoftDeleteWrite } from "./generic-data-soft-delete";
|
||||
|
||||
export const ZodRight = ZodGenericDataSoftDelete.extend({
|
||||
/**
|
||||
@ -22,7 +23,7 @@ export const ZodRight = ZodGenericDataSoftDelete.extend({
|
||||
/**
|
||||
* Value of the right
|
||||
*/
|
||||
value: zod.string().max(1024),
|
||||
value: ZodPartRight,
|
||||
|
||||
});
|
||||
|
||||
@ -37,14 +38,25 @@ export function isRight(data: any): data is Right {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodRightWrite = ZodGenericDataSoftDeleteWrite.extend({
|
||||
/**
|
||||
* application-ID that have the reference of the right
|
||||
*/
|
||||
applicationId: ZodLong.optional(),
|
||||
/**
|
||||
* user-ID
|
||||
*/
|
||||
userId: ZodLong.optional(),
|
||||
/**
|
||||
* rightDescription-ID of the right description
|
||||
*/
|
||||
rightDescriptionId: ZodLong.optional(),
|
||||
/**
|
||||
* Value of the right
|
||||
*/
|
||||
value: ZodPartRight.optional(),
|
||||
|
||||
export const ZodRightWrite = ZodRight.omit({
|
||||
deleted: true,
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
|
||||
}).partial();
|
||||
});
|
||||
|
||||
export type RightWrite = zod.infer<typeof ZodRightWrite>;
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
*/
|
||||
import { z as zod } from "zod";
|
||||
|
||||
import {ZodUser} from "./user";
|
||||
import {ZodUser, ZodUserWrite } from "./user";
|
||||
|
||||
export const ZodUserAuthGet = ZodUser.extend({
|
||||
email: zod.string().max(512),
|
||||
@ -22,14 +22,11 @@ export function isUserAuthGet(data: any): data is UserAuthGet {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodUserAuthGetWrite = ZodUserWrite.extend({
|
||||
email: zod.string().max(512).optional(),
|
||||
avatar: zod.boolean().optional(),
|
||||
|
||||
export const ZodUserAuthGetWrite = ZodUserAuthGet.omit({
|
||||
deleted: true,
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
|
||||
}).partial();
|
||||
});
|
||||
|
||||
export type UserAuthGetWrite = zod.infer<typeof ZodUserAuthGetWrite>;
|
||||
|
||||
|
@ -5,13 +5,13 @@ import { z as zod } from "zod";
|
||||
|
||||
import {ZodTimestamp} from "./timestamp";
|
||||
import {ZodLong} from "./long";
|
||||
import {ZodUser} from "./user";
|
||||
import {ZodUser, ZodUserWrite } from "./user";
|
||||
|
||||
export const ZodUserAuth = ZodUser.extend({
|
||||
password: zod.string().max(128),
|
||||
email: zod.string().max(512),
|
||||
password: zod.string().min(128).max(128).optional(),
|
||||
email: zod.string().min(5).max(128),
|
||||
emailValidate: ZodTimestamp.optional(),
|
||||
newEmail: zod.string().max(512).optional(),
|
||||
newEmail: zod.string().min(5).max(128).optional(),
|
||||
avatar: zod.boolean(),
|
||||
/**
|
||||
* List of accessible application (if not set the application is not available)
|
||||
@ -31,14 +31,18 @@ export function isUserAuth(data: any): data is UserAuth {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodUserAuthWrite = ZodUserWrite.extend({
|
||||
password: zod.string().min(128).max(128).nullable().optional(),
|
||||
email: zod.string().min(5).max(128).optional(),
|
||||
emailValidate: ZodTimestamp.nullable().optional(),
|
||||
newEmail: zod.string().min(5).max(128).nullable().optional(),
|
||||
avatar: zod.boolean().optional(),
|
||||
/**
|
||||
* List of accessible application (if not set the application is not available)
|
||||
*/
|
||||
applications: zod.array(ZodLong).optional(),
|
||||
|
||||
export const ZodUserAuthWrite = ZodUserAuth.omit({
|
||||
deleted: true,
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
|
||||
}).partial();
|
||||
});
|
||||
|
||||
export type UserAuthWrite = zod.infer<typeof ZodUserAuthWrite>;
|
||||
|
||||
|
@ -5,9 +5,9 @@ import { z as zod } from "zod";
|
||||
|
||||
|
||||
export const ZodUserCreate = zod.object({
|
||||
login: zod.string().max(255).optional(),
|
||||
email: zod.string().max(255).optional(),
|
||||
password: zod.string().max(255).optional(),
|
||||
login: zod.string().min(3).max(128),
|
||||
email: zod.string().min(5).max(128),
|
||||
password: zod.string().min(128).max(128),
|
||||
|
||||
});
|
||||
|
||||
@ -22,8 +22,12 @@ export function isUserCreate(data: any): data is UserCreate {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodUserCreateWrite = zod.object({
|
||||
login: zod.string().min(3).max(128).optional(),
|
||||
email: zod.string().min(5).max(128).optional(),
|
||||
password: zod.string().min(128).max(128).optional(),
|
||||
|
||||
export const ZodUserCreateWrite = ZodUserCreate.partial();
|
||||
});
|
||||
|
||||
export type UserCreateWrite = zod.infer<typeof ZodUserCreateWrite>;
|
||||
|
||||
|
@ -22,8 +22,11 @@ export function isUserOut(data: any): data is UserOut {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodUserOutWrite = zod.object({
|
||||
id: ZodLong,
|
||||
login: zod.string().max(255).nullable().optional(),
|
||||
|
||||
export const ZodUserOutWrite = ZodUserOut.partial();
|
||||
});
|
||||
|
||||
export type UserOutWrite = zod.infer<typeof ZodUserOutWrite>;
|
||||
|
||||
|
@ -5,14 +5,13 @@ import { z as zod } from "zod";
|
||||
|
||||
import {ZodTimestamp} from "./timestamp";
|
||||
import {ZodUUID} from "./uuid";
|
||||
import {ZodGenericDataSoftDelete} from "./generic-data-soft-delete";
|
||||
import {ZodGenericDataSoftDelete, ZodGenericDataSoftDeleteWrite } from "./generic-data-soft-delete";
|
||||
|
||||
export const ZodUser = ZodGenericDataSoftDelete.extend({
|
||||
login: zod.string().max(128).optional(),
|
||||
login: zod.string().min(3).max(128),
|
||||
lastConnection: ZodTimestamp.optional(),
|
||||
admin: zod.boolean(),
|
||||
blocked: zod.boolean(),
|
||||
removed: zod.boolean(),
|
||||
blocked: zod.boolean().optional(),
|
||||
blockedReason: zod.string().max(512).optional(),
|
||||
/**
|
||||
* List of Id of the specific covers
|
||||
*/
|
||||
@ -31,14 +30,17 @@ export function isUser(data: any): data is User {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export const ZodUserWrite = ZodGenericDataSoftDeleteWrite.extend({
|
||||
login: zod.string().min(3).max(128).optional(),
|
||||
lastConnection: ZodTimestamp.nullable().optional(),
|
||||
blocked: zod.boolean().nullable().optional(),
|
||||
blockedReason: zod.string().max(512).nullable().optional(),
|
||||
/**
|
||||
* List of Id of the specific covers
|
||||
*/
|
||||
covers: zod.array(ZodUUID).nullable().optional(),
|
||||
|
||||
export const ZodUserWrite = ZodUser.omit({
|
||||
deleted: true,
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
|
||||
}).partial();
|
||||
});
|
||||
|
||||
export type UserWrite = zod.infer<typeof ZodUserWrite>;
|
||||
|
||||
|
@ -7,11 +7,15 @@
|
||||
import { RestErrorResponse, isRestErrorResponse } from "./model";
|
||||
|
||||
export enum HTTPRequestModel {
|
||||
ARCHIVE = "ARCHIVE",
|
||||
DELETE = "DELETE",
|
||||
HEAD = "HEAD",
|
||||
GET = "GET",
|
||||
OPTION = "OPTION",
|
||||
PATCH = "PATCH",
|
||||
POST = "POST",
|
||||
PUT = "PUT",
|
||||
RESTORE = "RESTORE",
|
||||
}
|
||||
export enum HTTPMimeType {
|
||||
ALL = "*/*",
|
||||
@ -74,7 +78,7 @@ export interface RESTRequestType {
|
||||
data?: any;
|
||||
params?: object;
|
||||
queries?: object;
|
||||
callback?: RESTCallbacks;
|
||||
callbacks?: RESTCallbacks;
|
||||
}
|
||||
|
||||
function replaceAll(input, searchValue, replaceValue) {
|
||||
@ -237,7 +241,7 @@ export function RESTRequest({
|
||||
data,
|
||||
params,
|
||||
queries,
|
||||
callback,
|
||||
callbacks,
|
||||
}: RESTRequestType): Promise<ModelResponseHttp> {
|
||||
// Create the URL PATH:
|
||||
let generateUrl = RESTUrl({ restModel, restConfig, data, params, queries });
|
||||
@ -248,9 +252,14 @@ export function RESTRequest({
|
||||
if (restModel.accept !== undefined) {
|
||||
headers["Accept"] = restModel.accept;
|
||||
}
|
||||
if (restModel.requestType !== HTTPRequestModel.GET) {
|
||||
if (restModel.requestType !== HTTPRequestModel.GET &&
|
||||
restModel.requestType !== HTTPRequestModel.ARCHIVE &&
|
||||
restModel.requestType !== HTTPRequestModel.RESTORE
|
||||
) {
|
||||
// if Get we have not a content type, the body is empty
|
||||
if (restModel.contentType !== HTTPMimeType.MULTIPART) {
|
||||
if (restModel.contentType !== HTTPMimeType.MULTIPART &&
|
||||
restModel.contentType !== undefined
|
||||
) {
|
||||
// special case of multi-part ==> no content type otherwise the browser does not set the ";bundary=--****"
|
||||
headers["Content-Type"] = restModel.contentType;
|
||||
}
|
||||
@ -268,10 +277,10 @@ export function RESTRequest({
|
||||
return new Promise((resolve, reject) => {
|
||||
let action: undefined | Promise<Response> = undefined;
|
||||
if (
|
||||
isNullOrUndefined(callback) ||
|
||||
(isNullOrUndefined(callback.progressDownload) &&
|
||||
isNullOrUndefined(callback.progressUpload) &&
|
||||
isNullOrUndefined(callback.abortHandle))
|
||||
isNullOrUndefined(callbacks) ||
|
||||
(isNullOrUndefined(callbacks.progressDownload) &&
|
||||
isNullOrUndefined(callbacks.progressUpload) &&
|
||||
isNullOrUndefined(callbacks.abortHandle))
|
||||
) {
|
||||
// No information needed: call the generic fetch interface
|
||||
action = fetch(generateUrl, {
|
||||
@ -288,7 +297,7 @@ export function RESTRequest({
|
||||
headers,
|
||||
body,
|
||||
},
|
||||
callback
|
||||
callbacks
|
||||
);
|
||||
}
|
||||
action
|
||||
|
Loading…
x
Reference in New Issue
Block a user