@ph-cms/client-sdk-admin 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/dist/client.d.ts +17 -0
  3. package/dist/client.js +22 -0
  4. package/dist/context.d.ts +10 -0
  5. package/dist/context.js +53 -0
  6. package/dist/errors.d.ts +1 -0
  7. package/dist/errors.js +7 -0
  8. package/dist/hooks/useDashboard.d.ts +16 -0
  9. package/dist/hooks/useDashboard.js +13 -0
  10. package/dist/hooks/useHierarchy.d.ts +34 -0
  11. package/dist/hooks/useHierarchy.js +31 -0
  12. package/dist/hooks/usePolicy.d.ts +23 -0
  13. package/dist/hooks/usePolicy.js +19 -0
  14. package/dist/hooks/useSystem.d.ts +17 -0
  15. package/dist/hooks/useSystem.js +29 -0
  16. package/dist/hooks/useTerms.d.ts +26 -0
  17. package/dist/hooks/useTerms.js +19 -0
  18. package/dist/hooks/useUser.d.ts +108 -0
  19. package/dist/hooks/useUser.js +66 -0
  20. package/dist/index.d.ts +15 -0
  21. package/dist/index.js +35 -0
  22. package/dist/modules/dashboard.d.ts +7 -0
  23. package/dist/modules/dashboard.js +12 -0
  24. package/dist/modules/hierarchy.d.ts +14 -0
  25. package/dist/modules/hierarchy.js +33 -0
  26. package/dist/modules/policy.d.ts +11 -0
  27. package/dist/modules/policy.js +24 -0
  28. package/dist/modules/system.d.ts +21 -0
  29. package/dist/modules/system.js +24 -0
  30. package/dist/modules/terms.d.ts +11 -0
  31. package/dist/modules/terms.js +21 -0
  32. package/dist/modules/user.d.ts +11 -0
  33. package/dist/modules/user.js +44 -0
  34. package/package.json +42 -0
  35. package/src/client.ts +28 -0
  36. package/src/context.tsx +35 -0
  37. package/src/errors.ts +1 -0
  38. package/src/hooks/useDashboard.ts +10 -0
  39. package/src/hooks/useHierarchy.ts +30 -0
  40. package/src/hooks/usePolicy.ts +18 -0
  41. package/src/hooks/useSystem.ts +26 -0
  42. package/src/hooks/useTerms.ts +18 -0
  43. package/src/hooks/useUser.ts +69 -0
  44. package/src/index.ts +17 -0
  45. package/src/modules/dashboard.ts +10 -0
  46. package/src/modules/hierarchy.ts +38 -0
  47. package/src/modules/policy.ts +26 -0
  48. package/src/modules/system.ts +23 -0
  49. package/src/modules/terms.ts +23 -0
  50. package/src/modules/user.ts +47 -0
  51. package/tsconfig.json +15 -0
@@ -0,0 +1,47 @@
1
+ import { AxiosInstance } from "axios";
2
+ import {
3
+ ListUserQuerySchema, ListUserQuery,
4
+ CreateUserSchema, CreateUserRequest,
5
+ UpdateUserSchema, UpdateUserRequest,
6
+ UserDto, PagedUserListResponse
7
+ } from "@ph-cms/api-contract-admin";
8
+ import { ValidationError } from "../errors";
9
+
10
+ export class UserModule {
11
+ constructor(private client: AxiosInstance) {}
12
+
13
+ async list(params: ListUserQuery): Promise<PagedUserListResponse> {
14
+ const validation = ListUserQuerySchema.safeParse(params);
15
+ if (!validation.success) {
16
+ throw new ValidationError("Invalid list user params", validation.error.errors);
17
+ }
18
+ return this.client.get<any, PagedUserListResponse>('/api/users', { params }) as Promise<PagedUserListResponse>;
19
+ }
20
+
21
+ async get(uid: string): Promise<UserDto> {
22
+ if (!uid) throw new ValidationError("UID is required", []);
23
+ return this.client.get<any, UserDto>(`/api/users/${uid}`) as Promise<UserDto>;
24
+ }
25
+
26
+ async create(data: CreateUserRequest): Promise<UserDto> {
27
+ const validation = CreateUserSchema.safeParse(data);
28
+ if (!validation.success) {
29
+ throw new ValidationError("Invalid create user data", validation.error.errors);
30
+ }
31
+ return this.client.post<any, UserDto>('/api/users', data) as Promise<UserDto>;
32
+ }
33
+
34
+ async update(uid: string, data: UpdateUserRequest): Promise<UserDto> {
35
+ if (!uid) throw new ValidationError("UID is required", []);
36
+ const validation = UpdateUserSchema.safeParse(data);
37
+ if (!validation.success) {
38
+ throw new ValidationError("Invalid update user data", validation.error.errors);
39
+ }
40
+ return this.client.patch<any, UserDto>(`/api/users/${uid}`, data) as Promise<UserDto>;
41
+ }
42
+
43
+ async delete(uid: string): Promise<void> {
44
+ if (!uid) throw new ValidationError("UID is required", []);
45
+ return this.client.delete(`/api/users/${uid}`) as Promise<void>;
46
+ }
47
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "CommonJS",
5
+ "declaration": true,
6
+ "outDir": "./dist",
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "jsx": "react",
12
+ "resolveJsonModule": true
13
+ },
14
+ "include": ["src/**/*"]
15
+ }