@goweekdays/layer-common 0.0.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 (48) hide show
  1. package/.changeset/README.md +8 -0
  2. package/.changeset/config.json +11 -0
  3. package/.editorconfig +12 -0
  4. package/.github/workflows/main.yml +17 -0
  5. package/.github/workflows/publish.yml +39 -0
  6. package/.nuxtrc +1 -0
  7. package/.playground/app.vue +37 -0
  8. package/.playground/nuxt.config.ts +21 -0
  9. package/CHANGELOG.md +7 -0
  10. package/README.md +73 -0
  11. package/app.vue +3 -0
  12. package/components/BtnUploadFile.vue +139 -0
  13. package/components/Input/Date.vue +177 -0
  14. package/components/Input/Number.vue +102 -0
  15. package/components/Input/Password.vue +35 -0
  16. package/components/InputLabel.vue +18 -0
  17. package/components/Layout/Header.vue +271 -0
  18. package/components/Layout/NavigationDrawer.vue +24 -0
  19. package/components/ListItem.vue +35 -0
  20. package/components/LocalPagination.vue +31 -0
  21. package/components/NavigationItem.vue +59 -0
  22. package/components/PlaceholderComponent.vue +34 -0
  23. package/components/Snackbar.vue +23 -0
  24. package/components/SpecificAttr.vue +57 -0
  25. package/composables/useAddress.ts +107 -0
  26. package/composables/useLocal.ts +53 -0
  27. package/composables/useLocalAuth.ts +117 -0
  28. package/composables/useOrg.ts +73 -0
  29. package/composables/usePaymentMethod.ts +69 -0
  30. package/composables/usePermission.ts +54 -0
  31. package/composables/useRecapPermission.ts +26 -0
  32. package/composables/useRole.ts +73 -0
  33. package/composables/useSubscription.ts +94 -0
  34. package/composables/useUser.ts +95 -0
  35. package/composables/useUtils.ts +150 -0
  36. package/composables/useVerification.ts +18 -0
  37. package/eslint.config.js +3 -0
  38. package/nuxt.config.ts +46 -0
  39. package/package.json +30 -0
  40. package/plugins/API.ts +42 -0
  41. package/plugins/vuetify.ts +44 -0
  42. package/tsconfig.json +3 -0
  43. package/types/address.d.ts +13 -0
  44. package/types/local.d.ts +43 -0
  45. package/types/org.d.ts +12 -0
  46. package/types/permission.d.ts +24 -0
  47. package/types/role.d.ts +11 -0
  48. package/types/subscription.d.ts +9 -0
@@ -0,0 +1,53 @@
1
+ export default function useLocal() {
2
+ const appConfig = useRuntimeConfig().public;
3
+
4
+ const { cookieConfig } = appConfig;
5
+
6
+ function getUserFromCookie() {
7
+ return useCookie("user", cookieConfig).value;
8
+ }
9
+
10
+ const drawer = useState("drawer", () => true);
11
+
12
+ const { APP_INVENTORY, APP_ASSET, APP_BOOK_KEEPING } = appConfig;
13
+
14
+ const apps = computed(() => {
15
+ return [
16
+ {
17
+ title: "Inventory Management",
18
+ icon: "mdi-warehouse",
19
+ link: APP_INVENTORY as string,
20
+ landingPage: "home",
21
+ },
22
+ {
23
+ title: "Asset Management",
24
+ icon: "mdi-package-variant-closed",
25
+ link: APP_ASSET as string,
26
+ landingPage: "home",
27
+ },
28
+ {
29
+ title: "Bookkeeping Management",
30
+ icon: "mdi-file-document-multiple",
31
+ link: APP_BOOK_KEEPING as string,
32
+ landingPage: "home",
33
+ },
34
+ ];
35
+ });
36
+
37
+ function redirect(link: string, page?: string) {
38
+ const href = page ? `${link}/${page}` : link;
39
+
40
+ window.location.href = href;
41
+ }
42
+
43
+ const headerSearch = useState("headerSearch", () => "");
44
+
45
+ return {
46
+ cookieConfig,
47
+ getUserFromCookie,
48
+ drawer,
49
+ apps,
50
+ redirect,
51
+ headerSearch,
52
+ };
53
+ }
@@ -0,0 +1,117 @@
1
+ export default function useLocalAuth() {
2
+ const { cookieConfig } = useRuntimeConfig().public;
3
+
4
+ async function login({ email = "", password = "", role = "" }) {
5
+ return useNuxtApp().$api<TKeyValuePair>("/api/auth/login", {
6
+ method: "POST",
7
+ body: JSON.stringify({ email, password, role }),
8
+ });
9
+ }
10
+
11
+ function setToken({
12
+ refreshToken = "",
13
+ accessToken = "",
14
+ user = "",
15
+ org = "",
16
+ }) {
17
+ useCookie("accessToken", cookieConfig).value = accessToken;
18
+ useCookie("refreshToken", cookieConfig).value = refreshToken;
19
+ useCookie("user", cookieConfig).value = user;
20
+ useCookie("org", cookieConfig).value = org;
21
+ }
22
+
23
+ function clearCookies() {
24
+ useCookie("accessToken", cookieConfig).value = null;
25
+ useCookie("refreshToken", cookieConfig).value = null;
26
+ useCookie("user", cookieConfig).value = null;
27
+ useCookie("organization", cookieConfig).value = null;
28
+ }
29
+
30
+ async function logout() {
31
+ const refreshToken = useCookie("refreshToken", cookieConfig).value;
32
+ if (refreshToken) {
33
+ try {
34
+ await useNuxtApp().$api(`/api/auth/logout/${refreshToken}`, {
35
+ method: "DELETE",
36
+ });
37
+
38
+ clearCookies();
39
+ } catch (error) {
40
+ console.error("Logout failed:", error);
41
+ }
42
+ }
43
+ }
44
+
45
+ const currentUser = useState((): TUser | null => null);
46
+
47
+ async function getCurrentUser() {
48
+ const user = useCookie("user", cookieConfig).value;
49
+ if (!user) return null;
50
+ const _user = await useNuxtApp().$api<TUser>(`/api/users/id/${user}`, {
51
+ method: "GET",
52
+ });
53
+ currentUser.value = _user;
54
+ return _user;
55
+ }
56
+
57
+ async function forgotPassword(email: string) {
58
+ if (!email) {
59
+ throw new Error("Email is required for password reset request.");
60
+ }
61
+
62
+ try {
63
+ const response = await useNuxtApp().$api("/api/auth/forget-password", {
64
+ method: "POST",
65
+ body: JSON.stringify({ email }),
66
+ headers: { "Content-Type": "application/json" },
67
+ });
68
+ return response;
69
+ } catch (error) {
70
+ console.error("Error in password reset request:", error);
71
+ throw error;
72
+ }
73
+ }
74
+
75
+ async function resetPassword(
76
+ otp: string,
77
+ newPassword: string,
78
+ passwordConfirmation: string
79
+ ) {
80
+ try {
81
+ return await useNuxtApp().$api("/api/auth/reset-password", {
82
+ method: "POST",
83
+ body: JSON.stringify({ otp, newPassword, passwordConfirmation }),
84
+ headers: { "Content-Type": "application/json" },
85
+ });
86
+ } catch (error) {
87
+ console.error("Error resetting password:", error);
88
+ throw error;
89
+ }
90
+ }
91
+
92
+ function verify(id: string) {
93
+ return useNuxtApp().$api<TKeyValuePair>(`/api/auth/verify/${id}`, {
94
+ method: "GET",
95
+ });
96
+ }
97
+
98
+ function signUp(email: string, referral: string) {
99
+ return useNuxtApp().$api<TKeyValuePair>("/api/auth/sign-up", {
100
+ method: "POST",
101
+ body: { email, referral },
102
+ });
103
+ }
104
+
105
+ return {
106
+ login,
107
+ logout,
108
+ clearCookies,
109
+ getCurrentUser,
110
+ setToken,
111
+ forgotPassword,
112
+ resetPassword,
113
+ currentUser,
114
+ verify,
115
+ signUp,
116
+ };
117
+ }
@@ -0,0 +1,73 @@
1
+ export default function useOrg() {
2
+ function getOrgs({ page = 1, search = "", user = "" } = {}) {
3
+ return useNuxtApp().$api<Array<TOrg>>("/api/organizations", {
4
+ method: "GET",
5
+ query: {
6
+ page,
7
+ search,
8
+ user,
9
+ },
10
+ });
11
+ }
12
+
13
+ const org = useState("org", (): TOrg => {
14
+ return {
15
+ _id: "",
16
+ name: "",
17
+ email: "",
18
+ contact: "",
19
+ busInst: "",
20
+ type: "",
21
+ status: "",
22
+ };
23
+ });
24
+
25
+ function reset() {
26
+ org.value._id = "";
27
+ org.value.name = "";
28
+ org.value.email = "";
29
+ org.value.contact = "";
30
+ org.value.busInst = "";
31
+ org.value.type = "";
32
+ org.value.status = "";
33
+ }
34
+
35
+ function set({
36
+ _id = "",
37
+ name = "",
38
+ email = "",
39
+ contact = "",
40
+ busInst = "",
41
+ type = "",
42
+ status = "",
43
+ } = {}) {
44
+ org.value._id = _id;
45
+ org.value.name = name;
46
+ org.value.email = email;
47
+ org.value.contact = contact;
48
+ org.value.busInst = busInst;
49
+ org.value.type = type;
50
+ org.value.status = status;
51
+ }
52
+
53
+ const perSeatPrice = 300;
54
+ const seats = useState("seats", () => 0);
55
+ const total = computed(() => seats.value * perSeatPrice);
56
+
57
+ function getByName(name = "") {
58
+ return useNuxtApp().$api<TOrg>(`/api/organizations/name/${name}`, {
59
+ method: "GET",
60
+ });
61
+ }
62
+
63
+ return {
64
+ org,
65
+ getOrgs,
66
+ reset,
67
+ set,
68
+ perSeatPrice,
69
+ seats,
70
+ total,
71
+ getByName,
72
+ };
73
+ }
@@ -0,0 +1,69 @@
1
+ export default function usePaymentMethod() {
2
+ function linkEWallet({
3
+ mobile_number = "",
4
+ type = "GCASH",
5
+ success_return_url = "",
6
+ failure_return_url = "",
7
+ cancel_return_url = "",
8
+ subscriptionData = {},
9
+ } = {}) {
10
+ return useNuxtApp().$api<Record<string, any>>(
11
+ "/api/payment-methods/e-wallet",
12
+ {
13
+ method: "POST",
14
+ body: {
15
+ mobile_number,
16
+ type,
17
+ success_return_url,
18
+ failure_return_url,
19
+ cancel_return_url,
20
+ subscriptionData,
21
+ },
22
+ }
23
+ );
24
+ }
25
+
26
+ function linkCard({
27
+ cardType = "",
28
+ cardNumber = "",
29
+ expiryMonth = "",
30
+ expiryYear = "",
31
+ cvv = "",
32
+ cardholderName = "",
33
+ currency = "",
34
+ success_return_url = "",
35
+ failure_return_url = "",
36
+ subscriptionData = {},
37
+ } = {}) {
38
+ return useNuxtApp().$api<Record<string, any>>("/api/payment-methods/card", {
39
+ method: "POST",
40
+ body: {
41
+ cardType,
42
+ cardNumber,
43
+ expiryMonth,
44
+ expiryYear,
45
+ cvv,
46
+ cardholderName,
47
+ currency,
48
+ success_return_url,
49
+ failure_return_url,
50
+ subscriptionData,
51
+ },
52
+ });
53
+ }
54
+
55
+ function getByUser() {
56
+ return useNuxtApp().$api<Array<Record<string, any>>>(
57
+ "/api/payment-methods",
58
+ {
59
+ method: "GET",
60
+ }
61
+ );
62
+ }
63
+
64
+ return {
65
+ linkEWallet,
66
+ linkCard,
67
+ getByUser,
68
+ };
69
+ }
@@ -0,0 +1,54 @@
1
+ export default function usePermission() {
2
+ // Permission-Based Access Control with Dynamic Role Creation
3
+
4
+ // Utility to list all resources and their actions
5
+ function listPermissions(permissions: TPermissions): {
6
+ resource: string;
7
+ actions: { title: string; description: string }[];
8
+ }[] {
9
+ return Object.entries(permissions).map(([resource, actions]) => ({
10
+ resource,
11
+ actions: Object.entries(actions).map(([action, { description }]) => ({
12
+ title: action,
13
+ description,
14
+ })),
15
+ }));
16
+ }
17
+
18
+ // Utility to check if a user has permission
19
+ function hasPermission(
20
+ user: TRole,
21
+ permissions: TPermissions,
22
+ resource: string,
23
+ action: string,
24
+ data?: any
25
+ ): boolean {
26
+ const permissionKey = `${resource}:${action}`;
27
+
28
+ // Check if the permission exists in the user's permission array
29
+ if (!user.permissions?.includes(permissionKey)) {
30
+ return false;
31
+ }
32
+
33
+ const resourcePermissions = permissions[resource];
34
+ if (!resourcePermissions || !resourcePermissions[action]) {
35
+ return false;
36
+ }
37
+
38
+ const permissionCheck = resourcePermissions[action].check;
39
+
40
+ // Evaluate the permission check
41
+ if (typeof permissionCheck === "boolean") {
42
+ return permissionCheck;
43
+ } else if (typeof permissionCheck === "function") {
44
+ return permissionCheck(user, data);
45
+ }
46
+
47
+ return false;
48
+ }
49
+
50
+ return {
51
+ listPermissions,
52
+ hasPermission,
53
+ };
54
+ }
@@ -0,0 +1,26 @@
1
+ export default function useRecapPermission() {
2
+ const permissions: TPermissions = {
3
+ request: {
4
+ "create-request": {
5
+ check: true,
6
+ description: "Create a new request.",
7
+ },
8
+ "review-request": {
9
+ check: true,
10
+ description: "Review a request.",
11
+ },
12
+ "approve-request": {
13
+ check: true,
14
+ description: "Approve a request.",
15
+ },
16
+ "delete-request": {
17
+ check: true,
18
+ description: "Delete authored request.",
19
+ },
20
+ },
21
+ };
22
+
23
+ return {
24
+ permissions,
25
+ };
26
+ }
@@ -0,0 +1,73 @@
1
+ export default function useRole() {
2
+ function createRole(
3
+ { name, permissions, type } = {} as {
4
+ name: string;
5
+ permissions: Array<string>;
6
+ type: string;
7
+ }
8
+ ) {
9
+ return useNuxtApp().$api("/api/roles", {
10
+ method: "POST",
11
+ body: { name, permissions, type },
12
+ });
13
+ }
14
+
15
+ function getRoles({ search = "", page = 1, limit = 20, type = "" } = {}) {
16
+ return useNuxtApp().$api<TKeyValuePair>("/api/roles", {
17
+ method: "GET",
18
+ query: { search, page, limit, type },
19
+ });
20
+ }
21
+
22
+ function getRoleById(id: string) {
23
+ return useNuxtApp().$api<TKeyValuePair>(`/api/roles/id/${id}`, {
24
+ method: "GET",
25
+ });
26
+ }
27
+
28
+ function updateRoleById(
29
+ _id: string,
30
+ name?: string,
31
+ permissions?: Array<string>
32
+ ) {
33
+ return useNuxtApp().$api(`/api/roles/id/${_id}`, {
34
+ method: "PATCH",
35
+ body: { name, permissions },
36
+ });
37
+ }
38
+
39
+ function updateRoleFieldById(_id: string, field: string, value: string) {
40
+ return useNuxtApp().$api(`/api/roles/${_id}`, {
41
+ method: "PATCH",
42
+ body: { field, value },
43
+ });
44
+ }
45
+
46
+ function deleteRole(_id: string) {
47
+ return useNuxtApp().$api(`/api/roles/${_id}`, {
48
+ method: "DELETE",
49
+ });
50
+ }
51
+
52
+ const role = useState<TRole>("userRole", () => {
53
+ return {
54
+ _id: "",
55
+ name: "",
56
+ permissions: [],
57
+ description: "",
58
+ createdAt: "",
59
+ updatedAt: "",
60
+ deletedAt: "",
61
+ };
62
+ });
63
+
64
+ return {
65
+ role,
66
+ createRole,
67
+ getRoles,
68
+ getRoleById,
69
+ updateRoleById,
70
+ updateRoleFieldById,
71
+ deleteRole,
72
+ };
73
+ }
@@ -0,0 +1,94 @@
1
+ export default function useSubscription() {
2
+ function add(subscriptionId: string, user: string) {
3
+ return useNuxtApp().$api("/api/subscriptions", {
4
+ method: "POST",
5
+ body: {
6
+ subscriptionId,
7
+ user,
8
+ },
9
+ });
10
+ }
11
+
12
+ function getById(id: string) {
13
+ return useNuxtApp().$api<TSubscription>(`/api/subscriptions/id/${id}`);
14
+ }
15
+
16
+ function getSubscriptions() {
17
+ return useNuxtApp().$api("/api/subscriptions");
18
+ }
19
+
20
+ function getSubscriptionStatusById(id: string) {
21
+ return useNuxtApp().$api<Record<string, string>>(
22
+ `/api/subscriptions/status/${id}`
23
+ );
24
+ }
25
+
26
+ function cancelSubscription(id: string) {
27
+ return useNuxtApp().$api(`/api/subscriptions/cancel/${id}`, {
28
+ method: "DELETE",
29
+ });
30
+ }
31
+
32
+ const affiliateSubscription = useState(
33
+ "affiliateSubscription",
34
+ () => "inactive"
35
+ );
36
+
37
+ async function checkSubscription() {
38
+ const { currentUser } = useLocalAuth();
39
+
40
+ if (currentUser.value && currentUser.value._id) {
41
+ try {
42
+ const result = await getSubscriptionStatusById(currentUser.value._id);
43
+ affiliateSubscription.value = result.status;
44
+ } catch (error) {
45
+ console.error("failed to get the subscription", error);
46
+ }
47
+ }
48
+ }
49
+
50
+ function initAffiliateSubscription(
51
+ customer_id: string,
52
+ amount: number,
53
+ payment_method_id: string,
54
+ currency?: string
55
+ ) {
56
+ return useNuxtApp().$api("/api/subscriptions/affiliate", {
57
+ method: "POST",
58
+ body: {
59
+ customer_id,
60
+ amount,
61
+ payment_method_id,
62
+ currency,
63
+ },
64
+ });
65
+ }
66
+
67
+ type TOrgSubscription = {
68
+ customer_id: string;
69
+ amount: number;
70
+ payment_method_id: string;
71
+ currency?: string;
72
+ organization: TOrg;
73
+ billingAddress: TAddress;
74
+ };
75
+
76
+ function initOrgSubscription(value: TOrgSubscription) {
77
+ return useNuxtApp().$api("/api/subscriptions/organization", {
78
+ method: "POST",
79
+ body: value,
80
+ });
81
+ }
82
+
83
+ return {
84
+ add,
85
+ getById,
86
+ getSubscriptions,
87
+ affiliateSubscription,
88
+ checkSubscription,
89
+ getSubscriptionStatusById,
90
+ cancelSubscription,
91
+ initAffiliateSubscription,
92
+ initOrgSubscription,
93
+ };
94
+ }
@@ -0,0 +1,95 @@
1
+ export default function useUser() {
2
+ function inviteUser({ email = "", app = "", role = "", name = "" } = {}) {
3
+ return useNuxtApp().$api<TKeyValuePair>("/api/auth/invite", {
4
+ method: "POST",
5
+ body: { email, app, role, name },
6
+ });
7
+ }
8
+
9
+ function updateName({ firstName = "", lastName = "" } = {}) {
10
+ return useNuxtApp().$api<TKeyValuePair>("/api/users/name", {
11
+ method: "PUT",
12
+ body: { firstName, lastName },
13
+ });
14
+ }
15
+
16
+ function updateBirthday({ month = "", day = 0, year = 0 } = {}) {
17
+ return useNuxtApp().$api<TKeyValuePair>("/api/users/birthday", {
18
+ method: "PUT",
19
+ body: { month, day, year },
20
+ });
21
+ }
22
+
23
+ function updateGender(gender = "") {
24
+ return useNuxtApp().$api<TKeyValuePair>("/api/users/gender", {
25
+ method: "PUT",
26
+ body: { gender },
27
+ });
28
+ }
29
+
30
+ function updateEmail(email = "") {
31
+ return useNuxtApp().$api<TKeyValuePair>("/api/users/email", {
32
+ method: "PUT",
33
+ body: { email },
34
+ });
35
+ }
36
+
37
+ function updateContact(contact = "") {
38
+ return useNuxtApp().$api<TKeyValuePair>("/api/users/contact", {
39
+ method: "PUT",
40
+ body: { contact },
41
+ });
42
+ }
43
+
44
+ function updateUserFieldById(id = "", field = "", value = "") {
45
+ return useNuxtApp().$api<TKeyValuePair>(`/api/users/field/${id}`, {
46
+ method: "PATCH",
47
+ body: { field, value },
48
+ });
49
+ }
50
+
51
+ function getUsers({
52
+ status = "active",
53
+ type = "",
54
+ search = "",
55
+ page = 1,
56
+ } = {}) {
57
+ return useNuxtApp().$api<TKeyValuePair>("/api/users", {
58
+ method: "GET",
59
+ query: { status, search, page, type },
60
+ });
61
+ }
62
+
63
+ function getById(id = "") {
64
+ return useNuxtApp().$api<TKeyValuePair>(`/api/users/id/${id}`, {
65
+ method: "GET",
66
+ });
67
+ }
68
+
69
+ function createUserByVerification({
70
+ firstName = "",
71
+ lastName = "",
72
+ password = "",
73
+ id = "",
74
+ referralCode = "",
75
+ type = "",
76
+ } = {}) {
77
+ return useNuxtApp().$api<TKeyValuePair>(`/api/users/invite/${id}`, {
78
+ method: "POST",
79
+ body: { firstName, lastName, password, referralCode, type },
80
+ });
81
+ }
82
+
83
+ return {
84
+ inviteUser,
85
+ updateName,
86
+ updateBirthday,
87
+ updateGender,
88
+ updateEmail,
89
+ updateContact,
90
+ updateUserFieldById,
91
+ getUsers,
92
+ createUserByVerification,
93
+ getById,
94
+ };
95
+ }