@goweekdays/layer-common 0.0.9 → 0.0.11

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 (38) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/components/AddPaymentMethod.vue +171 -0
  3. package/components/Container/Standard.vue +33 -0
  4. package/components/Input/ListGroupSelection.vue +93 -0
  5. package/components/SwitchOrg.vue +10 -1
  6. package/components/TableList.vue +128 -0
  7. package/composables/useAdminPermission.ts +127 -0
  8. package/composables/useFile.ts +29 -0
  9. package/composables/useInvoice.ts +38 -0
  10. package/composables/useLocalAuth.ts +2 -0
  11. package/composables/useMember.ts +86 -0
  12. package/composables/usePaymentMethod.ts +78 -0
  13. package/composables/usePrice.ts +15 -0
  14. package/composables/usePromoCode.ts +8 -1
  15. package/composables/useRole.ts +20 -6
  16. package/composables/useSubscription.ts +41 -6
  17. package/composables/useUtils.ts +21 -6
  18. package/middleware/{auth.ts → 01.auth.ts} +0 -2
  19. package/nuxt.config.ts +1 -0
  20. package/package.json +1 -1
  21. package/plugins/API.ts +56 -38
  22. package/plugins/client.ts +30 -0
  23. package/public/bdo-logo.svg +4 -0
  24. package/public/bpi-logo.svg +74 -0
  25. package/public/chinabank-logo.svg +120 -0
  26. package/public/gcash-logo.svg +65 -0
  27. package/public/grabpay-logo.svg +99 -0
  28. package/public/paymaya-logo.svg +25 -0
  29. package/public/qrph-c567ff0f-ab6d-4662-86bf-24c6c731d8a8-logo.svg +20 -0
  30. package/public/rcbc-logo.svg +15 -0
  31. package/public/shopeepay-logo.svg +89 -0
  32. package/public/ubp-logo.svg +88 -0
  33. package/types/member.d.ts +12 -0
  34. package/types/payment.d.ts +18 -0
  35. package/types/permission.d.ts +0 -10
  36. package/types/price.d.ts +17 -0
  37. package/types/role.d.ts +1 -0
  38. package/types/subscription.d.ts +16 -2
@@ -0,0 +1,86 @@
1
+ export default function useMember() {
2
+ const member = useState("member", (): TMember => {
3
+ return {
4
+ _id: "",
5
+ name: "",
6
+ user: "",
7
+ role: "",
8
+ status: "",
9
+ createdAt: "",
10
+ updatedAt: "",
11
+ deletedAt: "",
12
+ };
13
+ });
14
+
15
+ function setMember(value?: Partial<TMember>) {
16
+ member.value._id = value?._id ?? "";
17
+ member.value.user = value?.user ?? "";
18
+ member.value.role = value?.role ?? "";
19
+ member.value.status = value?.status ?? "";
20
+ member.value.createdAt = value?.createdAt ?? "";
21
+ member.value.updatedAt = value?.updatedAt ?? "";
22
+ member.value.deletedAt = value?.deletedAt ?? "";
23
+ }
24
+
25
+ function inviteMember(value: Partial<TMember>) {
26
+ delete value.createdAt;
27
+ delete value.updatedAt;
28
+ delete value._id;
29
+ delete value.status;
30
+
31
+ return useNuxtApp().$api("/api/members", {
32
+ method: "POST",
33
+ body: JSON.stringify(value),
34
+ });
35
+ }
36
+
37
+ function getAll({
38
+ search = "",
39
+ page = 1,
40
+ org = "",
41
+ user = "",
42
+ type = "main",
43
+ limit = 10,
44
+ status = "active",
45
+ } = {}) {
46
+ return useNuxtApp().$api<TKeyValuePair>("/api/members", {
47
+ method: "GET",
48
+ query: { search, page, org, user, type, limit, status },
49
+ });
50
+ }
51
+
52
+ const page = useState("memberPage", () => 1);
53
+ const pages = useState("memberPages", () => 0);
54
+ const pageRange = useState("memberPageRange", () => "0-0 of 0");
55
+
56
+ function getMemberById(id = "") {
57
+ return useNuxtApp().$api<TMember>(`/api/members/id/${id}`, {
58
+ method: "GET",
59
+ });
60
+ }
61
+
62
+ function getByUserId(id = "") {
63
+ return useNuxtApp().$api<TMember>(`/api/members/user/${id}`, {
64
+ method: "GET",
65
+ });
66
+ }
67
+
68
+ function getOrgMember(id = "") {
69
+ return useNuxtApp().$api<TKeyValuePair>(`/api/members/org/${id}/main`, {
70
+ method: "GET",
71
+ });
72
+ }
73
+
74
+ return {
75
+ member,
76
+ setMember,
77
+ inviteMember,
78
+ getAll,
79
+ page,
80
+ pages,
81
+ pageRange,
82
+ getMemberById,
83
+ getOrgMember,
84
+ getByUserId,
85
+ };
86
+ }
@@ -70,6 +70,15 @@ export default function usePaymentMethod() {
70
70
  );
71
71
  }
72
72
 
73
+ function getById(id = "") {
74
+ return useNuxtApp().$api<Record<string, any>>(
75
+ `/api/payment-methods/id/${id}`,
76
+ {
77
+ method: "GET",
78
+ }
79
+ );
80
+ }
81
+
73
82
  const eWalletNumber = useState("eWalletNumber", () => "");
74
83
  const cardNumber = useState("cardNumber", () => "");
75
84
  const cardExpiration = useState("cardExpiration", () => "");
@@ -85,6 +94,72 @@ export default function usePaymentMethod() {
85
94
  cardholderName.value = "";
86
95
  }
87
96
 
97
+ function linkOnly(value: Record<string, any>) {
98
+ return useNuxtApp().$api<Record<string, any>>(
99
+ "/api/payment-methods/link-only",
100
+ {
101
+ method: "POST",
102
+ body: value,
103
+ }
104
+ );
105
+ }
106
+
107
+ const supportedEwallets = [
108
+ {
109
+ channel: "GCASH",
110
+ logo: "/gcash-logo.svg",
111
+ type: "EWALLET",
112
+ },
113
+ {
114
+ channel: "PAYMAYA",
115
+ logo: "/paymaya-logo.svg",
116
+ type: "EWALLET",
117
+ },
118
+ {
119
+ channel: "GRABPAY",
120
+ logo: "/grabpay-logo.svg",
121
+ type: "EWALLET",
122
+ },
123
+ {
124
+ channel: "SHOPEEPAY",
125
+ logo: "/shopeepay-logo.svg",
126
+ type: "EWALLET",
127
+ },
128
+ ];
129
+
130
+ const supportedDirectDebit = [
131
+ {
132
+ channel: "UBP",
133
+ logo: "/ubp-logo.svg",
134
+ type: "DIRECT_DEBIT",
135
+ },
136
+ {
137
+ channel: "BDO",
138
+ logo: "/bdo-logo.svg",
139
+ type: "DIRECT_DEBIT",
140
+ },
141
+ {
142
+ channel: "BPI",
143
+ logo: "/bpi-logo.svg",
144
+ type: "DIRECT_DEBIT",
145
+ },
146
+ {
147
+ channel: "RCBC",
148
+ logo: "/rcbc-logo.svg",
149
+ type: "DIRECT_DEBIT",
150
+ },
151
+ {
152
+ channel: "Chinabank",
153
+ logo: "/chinabank-logo.svg",
154
+ type: "DIRECT_DEBIT",
155
+ },
156
+ ];
157
+
158
+ const supportedPaymentMethods = [
159
+ ...supportedEwallets,
160
+ ...supportedDirectDebit,
161
+ ];
162
+
88
163
  return {
89
164
  linkEWallet,
90
165
  linkCard,
@@ -97,5 +172,8 @@ export default function usePaymentMethod() {
97
172
  cardholderName,
98
173
  selectedPaymentMethod,
99
174
  reset,
175
+ linkOnly,
176
+ getById,
177
+ supportedPaymentMethods,
100
178
  };
101
179
  }
@@ -0,0 +1,15 @@
1
+ export default function usePrice() {
2
+ function getByNameType(name: string, type: string) {
3
+ return useNuxtApp().$api<Record<string, any>>("/api/prices/price", {
4
+ method: "GET",
5
+ params: {
6
+ name,
7
+ type,
8
+ },
9
+ });
10
+ }
11
+
12
+ return {
13
+ getByNameType,
14
+ };
15
+ }
@@ -18,7 +18,7 @@ export default function usePromoCode() {
18
18
  }
19
19
 
20
20
  function getByCode(code: string, type?: string, assigned?: boolean) {
21
- return useNuxtApp().$api<Record<string, any>>("/api/promo-codes/code", {
21
+ return useNuxtApp().$api<TPromoCode>("/api/promo-codes/code", {
22
22
  method: "GET",
23
23
  params: {
24
24
  code,
@@ -28,9 +28,16 @@ export default function usePromoCode() {
28
28
  });
29
29
  }
30
30
 
31
+ function getById(id: string) {
32
+ return useNuxtApp().$api<TPromoCode>(`/api/promo-codes/id/${id}`, {
33
+ method: "GET",
34
+ });
35
+ }
36
+
31
37
  return {
32
38
  add,
33
39
  getPromoCodes,
34
40
  getByCode,
41
+ getById,
35
42
  };
36
43
  }
@@ -12,15 +12,21 @@ export default function useRole() {
12
12
  });
13
13
  }
14
14
 
15
- function getRoles({ search = "", page = 1, limit = 20, type = "" } = {}) {
16
- return useNuxtApp().$api<TKeyValuePair>("/api/roles", {
15
+ function getRoles({
16
+ search = "",
17
+ page = 1,
18
+ limit = 20,
19
+ type = "",
20
+ org = "",
21
+ } = {}) {
22
+ return useNuxtApp().$api<Record<string, any>>("/api/roles", {
17
23
  method: "GET",
18
- query: { search, page, limit, type },
24
+ query: { search, page, limit, type, org },
19
25
  });
20
26
  }
21
27
 
22
28
  function getRoleById(id: string) {
23
- return useNuxtApp().$api<TKeyValuePair>(`/api/roles/id/${id}`, {
29
+ return useNuxtApp().$api<Record<string, any>>(`/api/roles/id/${id}`, {
24
30
  method: "GET",
25
31
  });
26
32
  }
@@ -36,6 +42,13 @@ export default function useRole() {
36
42
  });
37
43
  }
38
44
 
45
+ function updatePermissionById(_id: string, permissions?: Array<string>) {
46
+ return useNuxtApp().$api(`/api/roles/permissions/id/${_id}`, {
47
+ method: "PATCH",
48
+ body: { permissions },
49
+ });
50
+ }
51
+
39
52
  function updateRoleFieldById(_id: string, field: string, value: string) {
40
53
  return useNuxtApp().$api(`/api/roles/${_id}`, {
41
54
  method: "PATCH",
@@ -49,15 +62,15 @@ export default function useRole() {
49
62
  });
50
63
  }
51
64
 
52
- const role = useState<TRole>("userRole", () => {
65
+ const role = useState("userRole", (): TRole => {
53
66
  return {
54
67
  _id: "",
55
68
  name: "",
56
69
  permissions: [],
57
- description: "",
58
70
  createdAt: "",
59
71
  updatedAt: "",
60
72
  deletedAt: "",
73
+ default: false,
61
74
  };
62
75
  });
63
76
 
@@ -69,5 +82,6 @@ export default function useRole() {
69
82
  updateRoleById,
70
83
  updateRoleFieldById,
71
84
  deleteRole,
85
+ updatePermissionById,
72
86
  };
73
87
  }
@@ -20,9 +20,7 @@ export default function useSubscription() {
20
20
  }
21
21
 
22
22
  function getByOrgId(id: string) {
23
- return useNuxtApp().$api<Record<string, any>>(
24
- `/api/subscriptions/org/${id}`
25
- );
23
+ return useNuxtApp().$api<TSubscription>(`/api/subscriptions/org/${id}`);
26
24
  }
27
25
 
28
26
  function getSubscriptions() {
@@ -46,6 +44,24 @@ export default function useSubscription() {
46
44
  () => "inactive"
47
45
  );
48
46
 
47
+ function updatePromoCodeById(id: string, promoCode: string) {
48
+ return useNuxtApp().$api(`/api/subscriptions/promo-code/${id}`, {
49
+ method: "PUT",
50
+ body: {
51
+ promoCode,
52
+ },
53
+ });
54
+ }
55
+
56
+ function updateStatusById(id: string, status: string) {
57
+ return useNuxtApp().$api(`/api/subscriptions/status/${id}`, {
58
+ method: "PUT",
59
+ body: {
60
+ status,
61
+ },
62
+ });
63
+ }
64
+
49
65
  async function affSubscriptionStatus() {
50
66
  const { currentUser } = useLocalAuth();
51
67
 
@@ -66,8 +82,8 @@ export default function useSubscription() {
66
82
 
67
83
  if (currentOrg.value) {
68
84
  try {
69
- const result = await getByOrgId(currentOrg.value);
70
- orgSubscription.value = result.status as string;
85
+ const data = await getByOrgId(currentOrg.value);
86
+ orgSubscription.value = data?.status as string;
71
87
  } catch (error) {
72
88
  console.error("failed to get the subscription", error);
73
89
  }
@@ -80,7 +96,6 @@ export default function useSubscription() {
80
96
  payment_method_id: string;
81
97
  payment_method_type: string;
82
98
  payment_method_channel: string;
83
- payment_method_number: string;
84
99
  payment_method_expiry_month?: string;
85
100
  payment_method_expiry_year?: string;
86
101
  payment_method_cvv?: string;
@@ -112,6 +127,23 @@ export default function useSubscription() {
112
127
  );
113
128
  }
114
129
 
130
+ function updateSeatsById({
131
+ subscriptionId = "",
132
+ seats = 0,
133
+ amount = 0,
134
+ } = {}) {
135
+ return useNuxtApp().$api<Record<string, any>>(
136
+ `/api/subscriptions/seats/${subscriptionId}`,
137
+ {
138
+ method: "PUT",
139
+ body: {
140
+ seats,
141
+ amount,
142
+ },
143
+ }
144
+ );
145
+ }
146
+
115
147
  return {
116
148
  add,
117
149
  getById,
@@ -126,5 +158,8 @@ export default function useSubscription() {
126
158
  initAffiliateSubscription,
127
159
  initOrgSubscription,
128
160
  getByAffiliateId,
161
+ updateSeatsById,
162
+ updatePromoCodeById,
163
+ updateStatusById,
129
164
  };
130
165
  }
@@ -14,6 +14,10 @@ export default function useUtils() {
14
14
  return true;
15
15
  };
16
16
 
17
+ function requireListRule(value: string[]) {
18
+ return value.length ? "" : "Required";
19
+ }
20
+
17
21
  const minOneMonthAdvance = (value: string): boolean | string => {
18
22
  if (!/^(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/\d{4}$/.test(value)) {
19
23
  return "Invalid date format (MM/DD/YYYY)";
@@ -96,13 +100,16 @@ export default function useUtils() {
96
100
  return ""; // Default fallback for invalid input
97
101
  }
98
102
 
99
- const initials = name
100
- .trim()
101
- .split(/\s+/) // Split by spaces
102
- .map((word) => word[0]?.toUpperCase()) // Take the first letter of each word and capitalize
103
- .join(""); // Combine all initials
103
+ const words = name.trim().split(/\s+/); // Split by spaces
104
+
105
+ if (words.length === 1) {
106
+ return words[0].slice(0, 2).toUpperCase(); // Take first two letters of the single word
107
+ }
104
108
 
105
- return initials.slice(0, 2); // Limit to 2 characters
109
+ return words
110
+ .map((word) => word[0]?.toUpperCase()) // Take the first letter of each word and capitalize
111
+ .join("")
112
+ .slice(0, 2); // Limit to 2 characters
106
113
  }
107
114
 
108
115
  function getDimensions(
@@ -208,6 +215,12 @@ export default function useUtils() {
208
215
  return totalCost;
209
216
  }
210
217
 
218
+ function convertPermissionsToArray(permissions: TPermissions) {
219
+ return Object.entries(permissions).flatMap(([resource, actions]) =>
220
+ Object.keys(actions).map((action) => `${resource}:${action}`)
221
+ );
222
+ }
223
+
211
224
  return {
212
225
  requiredRule,
213
226
  emailRule,
@@ -227,5 +240,7 @@ export default function useUtils() {
227
240
  validateDate,
228
241
  minOneMonthAdvance,
229
242
  computeTieredCost,
243
+ requireListRule,
244
+ convertPermissionsToArray,
230
245
  };
231
246
  }
@@ -17,8 +17,6 @@ export default defineNuxtRouteMiddleware(async () => {
17
17
  try {
18
18
  await getCurrentUser();
19
19
  } catch (error) {
20
- console.log(error);
21
-
22
20
  // Redirect to login page if user authentication fails
23
21
  return navigateTo({ name: "index" });
24
22
  }
package/nuxt.config.ts CHANGED
@@ -8,6 +8,7 @@ export default defineNuxtConfig({
8
8
 
9
9
  runtimeConfig: {
10
10
  public: {
11
+ BASE_URL: process.env.BASE_URL ?? "/",
11
12
  cookieConfig: {
12
13
  domain: (process.env.DOMAIN as string) ?? "localhost",
13
14
  secure: true,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@goweekdays/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "0.0.9",
5
+ "version": "0.0.11",
6
6
  "main": "./nuxt.config.ts",
7
7
  "publishConfig": {
8
8
  "access": "public"
package/plugins/API.ts CHANGED
@@ -1,42 +1,60 @@
1
+ import { useFetch } from "nuxt/app";
2
+ type useFetchType = typeof useFetch;
3
+
1
4
  export default defineNuxtPlugin(() => {
2
- const { cookieConfig } = useRuntimeConfig().public;
3
-
4
- const api = $fetch.create({
5
- baseURL: "/",
6
- retry: 1,
7
- retryStatusCodes: [401],
8
- retryDelay: 500,
9
- onRequest({ options }) {
10
- const accessToken = useCookie("accessToken", cookieConfig).value;
11
- options.headers = accessToken
12
- ? { Authorization: `Bearer ${accessToken}` }
13
- : {};
14
- },
15
-
16
- async onResponseError({ response }) {
17
- if (response.status === 401) {
18
- await $fetch("/api/auth/refresh", {
19
- baseURL: "/",
20
- method: "POST",
21
- server: false,
22
- credentials: "include",
23
- body: JSON.stringify({ token: useCookie("refreshToken", cookieConfig).value }),
24
-
25
- onResponse({ response }) {
26
- if (response.status === 200) {
27
- useCookie("accessToken", cookieConfig).value =
28
- response._data.token;
29
- }
30
- },
31
- });
5
+ const { cookieConfig, BASE_URL } = useRuntimeConfig().public;
6
+
7
+ const api = $fetch.create({
8
+ baseURL: "/",
9
+ retry: 1,
10
+ retryStatusCodes: [401],
11
+ retryDelay: 500,
12
+ onRequest({ options }) {
13
+ const accessToken = useCookie("accessToken", cookieConfig).value;
14
+ options.headers = accessToken
15
+ ? { Authorization: `Bearer ${accessToken}` }
16
+ : {};
17
+ },
18
+
19
+ async onResponseError({ response }) {
20
+ if (response.status === 401) {
21
+ await $fetch("/api/auth/refresh", {
22
+ method: "POST",
23
+ body: JSON.stringify({
24
+ token: useCookie("refreshToken", cookieConfig).value,
25
+ }),
26
+
27
+ onResponse({ response }) {
28
+ if (response.status === 200) {
29
+ useCookie("accessToken", cookieConfig).value =
30
+ response._data.token;
32
31
  }
33
- },
34
- });
35
-
36
- // Expose to useNuxtApp().$api
37
- return {
38
- provide: {
39
- api,
40
- },
32
+ },
33
+ });
34
+ }
35
+ },
36
+ });
37
+
38
+ const useAPI: useFetchType = (path, options = {}) => {
39
+ options.lazy = true;
40
+ options.retry = 1;
41
+ options.retryStatusCodes = [401];
42
+ options.retryDelay = 500;
43
+ options.baseURL = (BASE_URL as string) ?? "/";
44
+
45
+ options.headers = {
46
+ ...options.headers,
47
+ Authorization: `Bearer ${useCookie("accessToken", cookieConfig).value}`,
41
48
  };
49
+
50
+ return useFetch(path, options);
51
+ };
52
+
53
+ // Expose to useNuxtApp().$api
54
+ return {
55
+ provide: {
56
+ api,
57
+ useAPI,
58
+ },
59
+ };
42
60
  });
@@ -0,0 +1,30 @@
1
+ export default defineNuxtPlugin(async () => {
2
+ const cookieConfig = useRuntimeConfig().public.cookieConfig;
3
+
4
+ const clientId = useCookie("clientId", cookieConfig).value;
5
+
6
+ if (!clientId) {
7
+ const res = await fetch("/api/auth/init");
8
+ const headers = res.headers.get("accept-ch");
9
+
10
+ console.log("headers", headers);
11
+
12
+ // const headerValues = [
13
+ // headers.get("user-agent"),
14
+ // headers.get("sec-ch-ua"),
15
+ // headers.get("sec-ch-ua-platform"),
16
+ // headers.get("sec-ch-ua-mobile"),
17
+ // headers.get("accept-language"),
18
+ // ].join("|");
19
+
20
+ const buffer = await crypto.subtle.digest(
21
+ "SHA-256",
22
+ new TextEncoder().encode(headers ?? "")
23
+ );
24
+ const _clientId = [...new Uint8Array(buffer)]
25
+ .map((b) => b.toString(16).padStart(2, "0"))
26
+ .join("");
27
+
28
+ useCookie("clientId", cookieConfig).value = _clientId;
29
+ }
30
+ });
@@ -0,0 +1,4 @@
1
+ <svg width="90" height="60" viewBox="0 0 2513 878" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M0 24.1946L4.53678 850.592L566.72 847.379C625.868 841.385 692.418 827.256 738.929 791.051C764.467 771.17 789.927 744.86 806.602 711.095V848.891L1219.07 845.866C1552.59 823.506 1665.54 593.357 1663.87 442.497C1662.12 285.221 1557.81 43.5298 1182.4 25.7067L806.602 24.1946V526.8C784.393 477.731 736.651 429.974 634.016 401.479C711.863 357.072 746.929 287.803 738.74 215.105C730.949 145.945 701.513 51.8245 520.974 27.2189L0 24.1946ZM413.982 133.259C517.507 151.891 538.109 210.503 538.365 254.8C538.644 302.947 511.433 365.955 413.982 370.858L192.435 370.102V134.772L413.982 133.259ZM1006.6 134.015L1127.39 135.717C1365.92 132.8 1443 301.788 1442.13 438.149C1441.41 551.412 1395.86 739.742 1127.39 739.07L1003.57 737.558L1006.6 134.015ZM478.82 479.356C584.297 490.092 623.741 551.516 626.265 607.701C628.49 657.211 605.288 730.312 481.844 739.826H193.191V482.38L478.82 479.356Z" fill="#0B2972"></path>
3
+ <path d="M2024.73 0C1755.12 0 1536.65 196.662 1536.65 439.095C1536.65 681.527 1755.12 878 2024.73 878C2294.34 878 2513 681.527 2513 439.095C2513 196.662 2294.34 0 2024.73 0ZM2027.38 99.0467C2182.94 99.0467 2309.03 249.959 2309.03 436.07C2309.03 622.182 2182.94 773.094 2027.38 773.094C1871.81 773.094 1745.72 622.182 1745.72 436.07C1745.72 249.959 1871.81 99.0467 2027.38 99.0467Z" fill="#FFB20C"></path>
4
+ </svg>