[FEAT] updat front back-api
This commit is contained in:
parent
81ad9f842c
commit
ef304bc1fe
@ -6,6 +6,7 @@
|
||||
"all": "npm run build && npm run test",
|
||||
"ng": "ng",
|
||||
"dev": "ng serve karso --configuration=develop --watch --port 4200",
|
||||
"dev-hot-update": "ng serve karso --configuration=develop --watch --hmr --port 4200",
|
||||
"dev_edge": "ng serve karso-edge --configuration=develop --watch --port 4199",
|
||||
"build": "ng build karso --prod",
|
||||
"test": "ng test karso",
|
||||
|
@ -27,7 +27,7 @@ import {
|
||||
ApplicationEditScene,
|
||||
} from 'base/scene';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { AdminUserService, ApplicationService, ApplicationTokenService } from 'base/service';
|
||||
import { AdminUserService, ApplicationService, ApplicationTokenService, SettingsService } from 'base/service';
|
||||
import { KarCWModule } from '@kangaroo-and-rabbit/kar-cw';
|
||||
import { environment } from 'environments/environment';
|
||||
|
||||
@ -66,7 +66,7 @@ import { environment } from 'environments/environment';
|
||||
AdminUserService,
|
||||
ApplicationService,
|
||||
ApplicationTokenService,
|
||||
|
||||
SettingsService,
|
||||
],
|
||||
exports: [
|
||||
AppComponent,
|
||||
|
@ -30,7 +30,7 @@ import {
|
||||
} from 'base/scene';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import { AdminUserService, ApplicationService, ApplicationTokenService } from 'base/service';
|
||||
import { AdminUserService, ApplicationService, ApplicationTokenService, SettingsService } from 'base/service';
|
||||
import { environment } from 'environments/environment';
|
||||
import { KarCWModule } from '@kangaroo-and-rabbit/kar-cw';
|
||||
|
||||
@ -72,6 +72,7 @@ import { KarCWModule } from '@kangaroo-and-rabbit/kar-cw';
|
||||
AdminUserService,
|
||||
ApplicationService,
|
||||
ApplicationTokenService,
|
||||
SettingsService,
|
||||
|
||||
],
|
||||
exports: [
|
||||
|
@ -12,39 +12,60 @@ import {
|
||||
RESTRequestVoid
|
||||
} from "./rest-tools"
|
||||
import {
|
||||
Application,
|
||||
RightDescription,
|
||||
Long,
|
||||
ClientToken,
|
||||
ApplicationSmall,
|
||||
AddUserData,
|
||||
isApplication,
|
||||
Application,
|
||||
ApplicationSmall,
|
||||
ClientToken,
|
||||
Long,
|
||||
RightDescription,
|
||||
isRightDescription,
|
||||
isApplication,
|
||||
isLong,
|
||||
isClientToken,
|
||||
isApplicationSmall,
|
||||
isClientToken,
|
||||
} from "./model"
|
||||
export namespace ApplicationResource {
|
||||
|
||||
export function remove({
|
||||
export function addUser({
|
||||
restConfig,
|
||||
params,
|
||||
data,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
params: {
|
||||
id: Long,
|
||||
},
|
||||
data: AddUserData,
|
||||
}): Promise<void> {
|
||||
return RESTRequestVoid({
|
||||
restModel: {
|
||||
endPoint: "/application/{id}",
|
||||
requestType: HTTPRequestModel.DELETE,
|
||||
contentType: HTTPMimeType.TEXT_PLAIN,
|
||||
endPoint: "/application/{id}/users",
|
||||
requestType: HTTPRequestModel.POST,
|
||||
contentType: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
data,
|
||||
});
|
||||
};
|
||||
export function create({
|
||||
restConfig,
|
||||
data,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
data: Application,
|
||||
}): Promise<Application> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/application",
|
||||
requestType: HTTPRequestModel.POST,
|
||||
contentType: HTTPMimeType.JSON,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
data,
|
||||
}, isApplication);
|
||||
};
|
||||
export function get({
|
||||
restConfig,
|
||||
params,
|
||||
@ -64,60 +85,6 @@ export namespace ApplicationResource {
|
||||
params,
|
||||
}, isApplication);
|
||||
};
|
||||
export function create({
|
||||
restConfig,
|
||||
data,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
data: Application,
|
||||
}): Promise<Application> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/application",
|
||||
requestType: HTTPRequestModel.POST,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
data,
|
||||
}, isApplication);
|
||||
};
|
||||
export function patch({
|
||||
restConfig,
|
||||
params,
|
||||
data,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
params: {
|
||||
id: Long,
|
||||
},
|
||||
data: Application,
|
||||
}): Promise<Application> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/application/{id}",
|
||||
requestType: HTTPRequestModel.PATCH,
|
||||
contentType: HTTPMimeType.JSON,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
data,
|
||||
}, isApplication);
|
||||
};
|
||||
export function gets({
|
||||
restConfig,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
}): Promise<Application[]> {
|
||||
return RESTRequestJsonArray({
|
||||
restModel: {
|
||||
endPoint: "/application",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
}, isApplication);
|
||||
};
|
||||
export function getApplicationUsers({
|
||||
restConfig,
|
||||
params,
|
||||
@ -151,7 +118,78 @@ export namespace ApplicationResource {
|
||||
restConfig,
|
||||
}, isApplicationSmall);
|
||||
};
|
||||
export function addUser({
|
||||
export function getClientToken({
|
||||
restConfig,
|
||||
queries,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
queries: {
|
||||
application?: string,
|
||||
},
|
||||
}): Promise<ClientToken> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/application/get_token",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
queries,
|
||||
}, isClientToken);
|
||||
};
|
||||
export function getRightsDescription({
|
||||
restConfig,
|
||||
params,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
params: {
|
||||
id: Long,
|
||||
},
|
||||
}): Promise<RightDescription[]> {
|
||||
return RESTRequestJsonArray({
|
||||
restModel: {
|
||||
endPoint: "/application/{id}/rights",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
}, isRightDescription);
|
||||
};
|
||||
export function gets({
|
||||
restConfig,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
}): Promise<Application[]> {
|
||||
return RESTRequestJsonArray({
|
||||
restModel: {
|
||||
endPoint: "/application",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
}, isApplication);
|
||||
};
|
||||
export function logOut({
|
||||
restConfig,
|
||||
queries,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
queries: {
|
||||
application?: string,
|
||||
},
|
||||
}): Promise<string> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/application/return",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
queries,
|
||||
}, null);
|
||||
};
|
||||
export function patch({
|
||||
restConfig,
|
||||
params,
|
||||
data,
|
||||
@ -160,16 +198,37 @@ export namespace ApplicationResource {
|
||||
params: {
|
||||
id: Long,
|
||||
},
|
||||
data: AddUserData,
|
||||
}): Promise<void> {
|
||||
return RESTRequestVoid({
|
||||
data: Application,
|
||||
}): Promise<Application> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/application/{id}/users",
|
||||
requestType: HTTPRequestModel.POST,
|
||||
endPoint: "/application/{id}",
|
||||
requestType: HTTPRequestModel.PATCH,
|
||||
contentType: HTTPMimeType.JSON,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
data,
|
||||
}, isApplication);
|
||||
};
|
||||
export function remove({
|
||||
restConfig,
|
||||
params,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
params: {
|
||||
id: Long,
|
||||
},
|
||||
}): Promise<void> {
|
||||
return RESTRequestVoid({
|
||||
restModel: {
|
||||
endPoint: "/application/{id}",
|
||||
requestType: HTTPRequestModel.DELETE,
|
||||
contentType: HTTPMimeType.TEXT_PLAIN,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
});
|
||||
};
|
||||
export function removeUser({
|
||||
@ -192,61 +251,4 @@ export namespace ApplicationResource {
|
||||
params,
|
||||
});
|
||||
};
|
||||
export function getRightsDescription({
|
||||
restConfig,
|
||||
params,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
params: {
|
||||
id: Long,
|
||||
},
|
||||
}): Promise<RightDescription[]> {
|
||||
return RESTRequestJsonArray({
|
||||
restModel: {
|
||||
endPoint: "/application/{id}/rights",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
}, isRightDescription);
|
||||
};
|
||||
export function getClientToken({
|
||||
restConfig,
|
||||
queries,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
queries: {
|
||||
application?: string,
|
||||
},
|
||||
}): Promise<ClientToken> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/application/get_token",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
queries,
|
||||
}, isClientToken);
|
||||
};
|
||||
export function logOut({
|
||||
restConfig,
|
||||
queries,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
queries: {
|
||||
application?: string,
|
||||
},
|
||||
}): Promise<string> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/application/return",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
queries,
|
||||
}, null);
|
||||
};
|
||||
}
|
||||
|
@ -13,33 +13,13 @@ import {
|
||||
} from "./rest-tools"
|
||||
import {
|
||||
ApplicationToken,
|
||||
CreateTokenRequest,
|
||||
Integer,
|
||||
Long,
|
||||
CreateRequest,
|
||||
isApplicationToken,
|
||||
} from "./model"
|
||||
export namespace ApplicationTokenResource {
|
||||
|
||||
export function remove({
|
||||
restConfig,
|
||||
params,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
params: {
|
||||
tokenId: Integer,
|
||||
applicationId: Long,
|
||||
},
|
||||
}): Promise<void> {
|
||||
return RESTRequestVoid({
|
||||
restModel: {
|
||||
endPoint: "/application_token/{applicationId}/{tokenId}",
|
||||
requestType: HTTPRequestModel.DELETE,
|
||||
contentType: HTTPMimeType.TEXT_PLAIN,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
});
|
||||
};
|
||||
export function create({
|
||||
restConfig,
|
||||
params,
|
||||
@ -49,12 +29,13 @@ export namespace ApplicationTokenResource {
|
||||
params: {
|
||||
applicationId: Long,
|
||||
},
|
||||
data: CreateRequest,
|
||||
data: CreateTokenRequest,
|
||||
}): Promise<ApplicationToken> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/application_token//{applicationId}/create",
|
||||
endPoint: "/application_token/{applicationId}/create",
|
||||
requestType: HTTPRequestModel.POST,
|
||||
contentType: HTTPMimeType.JSON,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
@ -81,4 +62,24 @@ export namespace ApplicationTokenResource {
|
||||
params,
|
||||
}, isApplicationToken);
|
||||
};
|
||||
export function remove({
|
||||
restConfig,
|
||||
params,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
params: {
|
||||
tokenId: Integer,
|
||||
applicationId: Long,
|
||||
},
|
||||
}): Promise<void> {
|
||||
return RESTRequestVoid({
|
||||
restModel: {
|
||||
endPoint: "/application_token/{applicationId}/{tokenId}",
|
||||
requestType: HTTPRequestModel.DELETE,
|
||||
contentType: HTTPMimeType.TEXT_PLAIN,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -16,36 +16,6 @@ import {
|
||||
} from "./model"
|
||||
export namespace DataResource {
|
||||
|
||||
/**
|
||||
* Get a thumbnail of from the data environment (if resize is possible)
|
||||
*/
|
||||
// TODO: unmanaged "Response" type: please specify @AsyncType or considered as 'void'.
|
||||
export function retrieveDataThumbnailId({
|
||||
restConfig,
|
||||
queries,
|
||||
params,
|
||||
data,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
queries: {
|
||||
Authorization?: string,
|
||||
},
|
||||
params: {
|
||||
uuid: UUID,
|
||||
},
|
||||
data: string,
|
||||
}): Promise<void> {
|
||||
return RESTRequestVoid({
|
||||
restModel: {
|
||||
endPoint: "/data/thumbnail/{uuid}",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
queries,
|
||||
data,
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Get back some data from the data environment (with a beautiful name (permit download with basic name)
|
||||
*/
|
||||
@ -77,28 +47,6 @@ export namespace DataResource {
|
||||
data,
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Insert a new data in the data environment
|
||||
*/
|
||||
export function uploadFile({
|
||||
restConfig,
|
||||
data,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
data: {
|
||||
file: File,
|
||||
},
|
||||
}): Promise<void> {
|
||||
return RESTRequestVoid({
|
||||
restModel: {
|
||||
endPoint: "/data//upload/",
|
||||
requestType: HTTPRequestModel.POST,
|
||||
contentType: HTTPMimeType.MULTIPART,
|
||||
},
|
||||
restConfig,
|
||||
data,
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Get back some data from the data environment
|
||||
*/
|
||||
@ -129,4 +77,56 @@ export namespace DataResource {
|
||||
data,
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Get a thumbnail of from the data environment (if resize is possible)
|
||||
*/
|
||||
// TODO: unmanaged "Response" type: please specify @AsyncType or considered as 'void'.
|
||||
export function retrieveDataThumbnailId({
|
||||
restConfig,
|
||||
queries,
|
||||
params,
|
||||
data,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
queries: {
|
||||
Authorization?: string,
|
||||
},
|
||||
params: {
|
||||
uuid: UUID,
|
||||
},
|
||||
data: string,
|
||||
}): Promise<void> {
|
||||
return RESTRequestVoid({
|
||||
restModel: {
|
||||
endPoint: "/data/thumbnail/{uuid}",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
queries,
|
||||
data,
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Insert a new data in the data environment
|
||||
*/
|
||||
export function uploadFile({
|
||||
restConfig,
|
||||
data,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
data: {
|
||||
file: File,
|
||||
},
|
||||
}): Promise<void> {
|
||||
return RESTRequestVoid({
|
||||
restModel: {
|
||||
endPoint: "/data//upload/",
|
||||
requestType: HTTPRequestModel.POST,
|
||||
contentType: HTTPMimeType.MULTIPART,
|
||||
},
|
||||
restConfig,
|
||||
data,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ export function isInstant(data: any): data is Instant {
|
||||
}
|
||||
|
||||
|
||||
export const ZodDate = zod.date();
|
||||
export const ZodDate = zod.string().datetime({ precision: 3 });
|
||||
export type Date = zod.infer<typeof ZodDate>;
|
||||
export function isDate(data: any): data is Date {
|
||||
try {
|
||||
@ -81,7 +81,7 @@ export function isDate(data: any): data is Date {
|
||||
}
|
||||
|
||||
|
||||
export const ZodTimestamp = zod.date();
|
||||
export const ZodTimestamp = zod.string().datetime({ precision: 3 });
|
||||
export type Timestamp = zod.infer<typeof ZodTimestamp>;
|
||||
export function isTimestamp(data: any): data is Timestamp {
|
||||
try {
|
||||
@ -94,7 +94,7 @@ export function isTimestamp(data: any): data is Timestamp {
|
||||
}
|
||||
|
||||
|
||||
export const ZodLocalDate = zod.date();
|
||||
export const ZodLocalDate = zod.string().date();
|
||||
export type LocalDate = zod.infer<typeof ZodLocalDate>;
|
||||
export function isLocalDate(data: any): data is LocalDate {
|
||||
try {
|
||||
@ -107,7 +107,7 @@ export function isLocalDate(data: any): data is LocalDate {
|
||||
}
|
||||
|
||||
|
||||
export const ZodLocalTime = zod.date();
|
||||
export const ZodLocalTime = zod.string().time();
|
||||
export type LocalTime = zod.infer<typeof ZodLocalTime>;
|
||||
export function isLocalTime(data: any): data is LocalTime {
|
||||
try {
|
||||
@ -140,6 +140,21 @@ export function isRestErrorResponse(data: any): data is RestErrorResponse {
|
||||
}
|
||||
|
||||
|
||||
export const ZodAddUserData = zod.object({
|
||||
userId: ZodLong.optional()
|
||||
});
|
||||
export type AddUserData = zod.infer<typeof ZodAddUserData>;
|
||||
export function isAddUserData(data: any): data is AddUserData {
|
||||
try {
|
||||
ZodAddUserData.parse(data);
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
console.log(`Fail to parse data ${e}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const ZodGenericTiming = zod.object({
|
||||
// Create time of the object
|
||||
createdAt: ZodDate.readonly().optional(),
|
||||
@ -231,13 +246,14 @@ export function isApplicationSmall(data: any): data is ApplicationSmall {
|
||||
}
|
||||
|
||||
|
||||
export const ZodAddUserData = zod.object({
|
||||
userId: ZodLong
|
||||
export const ZodClientToken = zod.object({
|
||||
url: zod.string().max(255).optional(),
|
||||
jwt: zod.string().max(255).optional()
|
||||
});
|
||||
export type AddUserData = zod.infer<typeof ZodAddUserData>;
|
||||
export function isAddUserData(data: any): data is AddUserData {
|
||||
export type ClientToken = zod.infer<typeof ZodClientToken>;
|
||||
export function isClientToken(data: any): data is ClientToken {
|
||||
try {
|
||||
ZodAddUserData.parse(data);
|
||||
ZodClientToken.parse(data);
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
console.log(`Fail to parse data ${e}`);
|
||||
@ -272,22 +288,6 @@ export function isRightDescription(data: any): data is RightDescription {
|
||||
}
|
||||
|
||||
|
||||
export const ZodClientToken = zod.object({
|
||||
url: zod.string().max(255).optional(),
|
||||
jwt: zod.string().max(255).optional()
|
||||
});
|
||||
export type ClientToken = zod.infer<typeof ZodClientToken>;
|
||||
export function isClientToken(data: any): data is ClientToken {
|
||||
try {
|
||||
ZodClientToken.parse(data);
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
console.log(`Fail to parse data ${e}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const ZodGenericToken = ZodGenericDataSoftDelete.extend({
|
||||
parentId: ZodLong.optional(),
|
||||
name: zod.string().optional(),
|
||||
@ -320,14 +320,14 @@ export function isApplicationToken(data: any): data is ApplicationToken {
|
||||
}
|
||||
|
||||
|
||||
export const ZodCreateRequest = zod.object({
|
||||
export const ZodCreateTokenRequest = zod.object({
|
||||
name: zod.string().max(255).optional(),
|
||||
validity: ZodInteger.optional()
|
||||
});
|
||||
export type CreateRequest = zod.infer<typeof ZodCreateRequest>;
|
||||
export function isCreateRequest(data: any): data is CreateRequest {
|
||||
export type CreateTokenRequest = zod.infer<typeof ZodCreateTokenRequest>;
|
||||
export function isCreateTokenRequest(data: any): data is CreateTokenRequest {
|
||||
try {
|
||||
ZodCreateRequest.parse(data);
|
||||
ZodCreateTokenRequest.parse(data);
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
console.log(`Fail to parse data ${e}`);
|
||||
@ -373,6 +373,25 @@ export function isRight(data: any): data is Right {
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
});
|
||||
export type ChangePassword = zod.infer<typeof ZodChangePassword>;
|
||||
export function isChangePassword(data: any): data is ChangePassword {
|
||||
try {
|
||||
ZodChangePassword.parse(data);
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
console.log(`Fail to parse data ${e}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const ZodUser = ZodGenericDataSoftDelete.extend({
|
||||
login: zod.string().max(128).optional(),
|
||||
lastConnection: ZodTimestamp.optional(),
|
||||
@ -426,27 +445,6 @@ export function isUserCreate(data: any): data is UserCreate {
|
||||
}
|
||||
|
||||
|
||||
export const ZodUserAuth = ZodUser.extend({
|
||||
password: zod.string().max(128).optional(),
|
||||
email: zod.string().max(512).optional(),
|
||||
emailValidate: ZodTimestamp.optional(),
|
||||
newEmail: zod.string().max(512).optional(),
|
||||
avatar: zod.boolean().optional(),
|
||||
// List of accessible application (if not set the application is not available)
|
||||
applications: zod.array(ZodLong).optional()
|
||||
});
|
||||
export type UserAuth = zod.infer<typeof ZodUserAuth>;
|
||||
export function isUserAuth(data: any): data is UserAuth {
|
||||
try {
|
||||
ZodUserAuth.parse(data);
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
console.log(`Fail to parse data ${e}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const ZodUserOut = zod.object({
|
||||
id: ZodLong,
|
||||
login: zod.string().max(255).optional()
|
||||
@ -463,25 +461,6 @@ export function isUserOut(data: any): data is UserOut {
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
});
|
||||
export type ChangePassword = zod.infer<typeof ZodChangePassword>;
|
||||
export function isChangePassword(data: any): data is ChangePassword {
|
||||
try {
|
||||
ZodChangePassword.parse(data);
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
console.log(`Fail to parse data ${e}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const ZodGetToken = zod.object({
|
||||
jwt: zod.string().optional()
|
||||
});
|
||||
@ -511,6 +490,27 @@ export function isDataGetToken(data: any): data is DataGetToken {
|
||||
}
|
||||
|
||||
|
||||
export const ZodUserAuth = ZodUser.extend({
|
||||
password: zod.string().max(128).optional(),
|
||||
email: zod.string().max(512).optional(),
|
||||
emailValidate: ZodTimestamp.optional(),
|
||||
newEmail: zod.string().max(512).optional(),
|
||||
avatar: zod.boolean().optional(),
|
||||
// List of accessible application (if not set the application is not available)
|
||||
applications: zod.array(ZodLong).optional()
|
||||
});
|
||||
export type UserAuth = zod.infer<typeof ZodUserAuth>;
|
||||
export function isUserAuth(data: any): data is UserAuth {
|
||||
try {
|
||||
ZodUserAuth.parse(data);
|
||||
return true;
|
||||
} catch (e: any) {
|
||||
console.log(`Fail to parse data ${e}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const ZodGetSignUpAvailable = zod.object({
|
||||
signup: zod.boolean()
|
||||
});
|
||||
|
@ -95,6 +95,10 @@ export interface RESTRequestType {
|
||||
callback?: RESTCallbacks,
|
||||
};
|
||||
|
||||
function replaceAll(input, searchValue, replaceValue) {
|
||||
return input.split(searchValue).join(replaceValue);
|
||||
}
|
||||
|
||||
function removeTrailingSlashes(input: string): string {
|
||||
if (isNullOrUndefined(input)) {
|
||||
return "undefined";
|
||||
@ -113,7 +117,7 @@ export function RESTUrl({ restModel, restConfig, params, queries }: RESTRequestT
|
||||
let generateUrl = `${removeTrailingSlashes(restConfig.server)}/${removeLeadingSlashes(restModel.endPoint)}`;
|
||||
if (params !== undefined) {
|
||||
for (let key of Object.keys(params)) {
|
||||
generateUrl = generateUrl.replaceAll(`{${key}}`, `${params[key]}`);
|
||||
generateUrl = replaceAll(generateUrl, `{${key}}`, `${params[key]}`);
|
||||
}
|
||||
}
|
||||
if (queries === undefined && (restConfig.token === undefined || restModel.tokenInUrl !== true)) {
|
||||
@ -199,7 +203,7 @@ export function fetchProgress(generateUrl: string, { method, headers, body }: {
|
||||
status: xhr.io.status,
|
||||
statusText: xhr.io.statusText
|
||||
});
|
||||
const headersArray = xhr.io.getAllResponseHeaders().trim().replaceAll("\r\n", "\n").split('\n');
|
||||
const headersArray = replaceAll(xhr.io.getAllResponseHeaders().trim(), "\r\n", "\n").split('\n');
|
||||
headersArray.forEach(function (header) {
|
||||
const firstColonIndex = header.indexOf(':');
|
||||
if (firstColonIndex !== -1) {
|
||||
@ -273,7 +277,7 @@ export function RESTRequest({ restModel, restConfig, data, params, queries, call
|
||||
action.then((response: Response) => {
|
||||
if (response.status >= 200 && response.status <= 299) {
|
||||
const contentType = response.headers.get('Content-Type');
|
||||
if (restModel.accept !== contentType) {
|
||||
if (!isNullOrUndefined(restModel.accept) && restModel.accept !== contentType) {
|
||||
reject({
|
||||
time: Date().toString(),
|
||||
status: 901,
|
||||
@ -326,7 +330,10 @@ export function RESTRequest({ restModel, restConfig, data, params, queries, call
|
||||
export function RESTRequestJson<TYPE>(request: RESTRequestType, checker: (data: any) => data is TYPE): Promise<TYPE> {
|
||||
return new Promise((resolve, reject) => {
|
||||
RESTRequest(request).then((value: ModelResponseHttp) => {
|
||||
if (checker(value.data)) {
|
||||
if (isNullOrUndefined(checker)) {
|
||||
console.log(`Have no check of MODEL in API: ${RESTUrl(request)}`);
|
||||
resolve(value.data);
|
||||
} else if (checker(value.data)) {
|
||||
resolve(value.data);
|
||||
} else {
|
||||
reject({
|
||||
|
@ -12,31 +12,12 @@ import {
|
||||
RESTRequestVoid
|
||||
} from "./rest-tools"
|
||||
import {
|
||||
Right,
|
||||
Long,
|
||||
Right,
|
||||
isRight,
|
||||
} from "./model"
|
||||
export namespace RightResource {
|
||||
|
||||
export function remove({
|
||||
restConfig,
|
||||
params,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
params: {
|
||||
id: Long,
|
||||
},
|
||||
}): Promise<void> {
|
||||
return RESTRequestVoid({
|
||||
restModel: {
|
||||
endPoint: "/right/{id}",
|
||||
requestType: HTTPRequestModel.DELETE,
|
||||
contentType: HTTPMimeType.TEXT_PLAIN,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
});
|
||||
};
|
||||
export function get({
|
||||
restConfig,
|
||||
params,
|
||||
@ -56,6 +37,20 @@ export namespace RightResource {
|
||||
params,
|
||||
}, isRight);
|
||||
};
|
||||
export function gets({
|
||||
restConfig,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
}): Promise<Right[]> {
|
||||
return RESTRequestJsonArray({
|
||||
restModel: {
|
||||
endPoint: "/right",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
}, isRight);
|
||||
};
|
||||
export function patch({
|
||||
restConfig,
|
||||
params,
|
||||
@ -97,18 +92,23 @@ export namespace RightResource {
|
||||
data,
|
||||
}, isRight);
|
||||
};
|
||||
export function gets({
|
||||
export function remove({
|
||||
restConfig,
|
||||
params,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
}): Promise<Right[]> {
|
||||
return RESTRequestJsonArray({
|
||||
params: {
|
||||
id: Long,
|
||||
},
|
||||
}): Promise<void> {
|
||||
return RESTRequestVoid({
|
||||
restModel: {
|
||||
endPoint: "/right",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
endPoint: "/right/{id}",
|
||||
requestType: HTTPRequestModel.DELETE,
|
||||
contentType: HTTPMimeType.TEXT_PLAIN,
|
||||
},
|
||||
restConfig,
|
||||
}, isRight);
|
||||
params,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -12,21 +12,38 @@ import {
|
||||
RESTRequestVoid
|
||||
} from "./rest-tools"
|
||||
import {
|
||||
ChangePassword,
|
||||
DataGetToken,
|
||||
GetToken,
|
||||
Long,
|
||||
UserOut,
|
||||
UserAuthGet,
|
||||
DataGetToken,
|
||||
UserCreate,
|
||||
ChangePassword,
|
||||
UserAuth,
|
||||
UserAuthGet,
|
||||
UserCreate,
|
||||
UserOut,
|
||||
isUserAuth,
|
||||
isGetToken,
|
||||
isUserOut,
|
||||
isUserAuthGet,
|
||||
isUserAuth,
|
||||
} from "./model"
|
||||
export namespace UserResource {
|
||||
|
||||
export function changePassword({
|
||||
restConfig,
|
||||
data,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
data: ChangePassword,
|
||||
}): Promise<void> {
|
||||
return RESTRequestVoid({
|
||||
restModel: {
|
||||
endPoint: "/users/password",
|
||||
requestType: HTTPRequestModel.POST,
|
||||
contentType: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
data,
|
||||
});
|
||||
};
|
||||
export function create({
|
||||
restConfig,
|
||||
data,
|
||||
@ -45,19 +62,57 @@ export namespace UserResource {
|
||||
data,
|
||||
}, isUserAuthGet);
|
||||
};
|
||||
export function getUsers({
|
||||
export function getApplicationRight({
|
||||
restConfig,
|
||||
params,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
}): Promise<UserAuthGet[]> {
|
||||
return RESTRequestJsonArray({
|
||||
params: {
|
||||
applicationId: Long,
|
||||
userId: Long,
|
||||
},
|
||||
}): Promise<any> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/users",
|
||||
endPoint: "/users/{userId}/application/{applicationId}/rights",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
}, isUserAuthGet);
|
||||
params,
|
||||
}, null);
|
||||
};
|
||||
export function getMe({
|
||||
restConfig,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
}): Promise<UserOut> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/users/me",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
}, isUserOut);
|
||||
};
|
||||
export function getToken({
|
||||
restConfig,
|
||||
data,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
data: DataGetToken,
|
||||
}): Promise<GetToken> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/users/get_token",
|
||||
requestType: HTTPRequestModel.POST,
|
||||
contentType: HTTPMimeType.JSON,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
data,
|
||||
}, isGetToken);
|
||||
};
|
||||
export function getUser({
|
||||
restConfig,
|
||||
@ -78,6 +133,58 @@ export namespace UserResource {
|
||||
params,
|
||||
}, isUserAuthGet);
|
||||
};
|
||||
export function getUsers({
|
||||
restConfig,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
}): Promise<UserAuthGet[]> {
|
||||
return RESTRequestJsonArray({
|
||||
restModel: {
|
||||
endPoint: "/users",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
}, isUserAuthGet);
|
||||
};
|
||||
export function isEmailExist({
|
||||
restConfig,
|
||||
queries,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
queries: {
|
||||
email?: string,
|
||||
},
|
||||
}): Promise<boolean> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/users/is_email_exist",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
queries,
|
||||
}, null);
|
||||
};
|
||||
export function isLoginExist({
|
||||
restConfig,
|
||||
queries,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
queries: {
|
||||
login?: string,
|
||||
},
|
||||
}): Promise<boolean> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/users/is_login_exist",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
queries,
|
||||
}, null);
|
||||
};
|
||||
export function linkApplication({
|
||||
restConfig,
|
||||
params,
|
||||
@ -101,26 +208,6 @@ export namespace UserResource {
|
||||
data,
|
||||
}, isUserAuth);
|
||||
};
|
||||
export function getApplicationRight({
|
||||
restConfig,
|
||||
params,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
params: {
|
||||
applicationId: Long,
|
||||
userId: Long,
|
||||
},
|
||||
}): Promise<any> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/users/{userId}/application/{applicationId}/rights",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
params,
|
||||
}, null);
|
||||
};
|
||||
export function patchApplicationRight({
|
||||
restConfig,
|
||||
params,
|
||||
@ -189,91 +276,4 @@ export namespace UserResource {
|
||||
data,
|
||||
});
|
||||
};
|
||||
export function getMe({
|
||||
restConfig,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
}): Promise<UserOut> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/users/me",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
}, isUserOut);
|
||||
};
|
||||
export function changePassword({
|
||||
restConfig,
|
||||
data,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
data: ChangePassword,
|
||||
}): Promise<void> {
|
||||
return RESTRequestVoid({
|
||||
restModel: {
|
||||
endPoint: "/users/password",
|
||||
requestType: HTTPRequestModel.POST,
|
||||
contentType: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
data,
|
||||
});
|
||||
};
|
||||
export function isLoginExist({
|
||||
restConfig,
|
||||
queries,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
queries: {
|
||||
login?: string,
|
||||
},
|
||||
}): Promise<boolean> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/users/is_login_exist",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
queries,
|
||||
}, null);
|
||||
};
|
||||
export function isEmailExist({
|
||||
restConfig,
|
||||
queries,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
queries: {
|
||||
email?: string,
|
||||
},
|
||||
}): Promise<boolean> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/users/is_email_exist",
|
||||
requestType: HTTPRequestModel.GET,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
queries,
|
||||
}, null);
|
||||
};
|
||||
export function getToken({
|
||||
restConfig,
|
||||
data,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
data: DataGetToken,
|
||||
}): Promise<GetToken> {
|
||||
return RESTRequestJson({
|
||||
restModel: {
|
||||
endPoint: "/users/get_token",
|
||||
requestType: HTTPRequestModel.POST,
|
||||
contentType: HTTPMimeType.JSON,
|
||||
accept: HTTPMimeType.JSON,
|
||||
},
|
||||
restConfig,
|
||||
data,
|
||||
}, isGetToken);
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user