@yangsaiyam/helper 1.5.3 → 1.7.0
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.
- package/README.md +6 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/roles/index.test.ts +23 -0
- package/src/roles/index.ts +38 -17
- package/src/routes/index.test.ts +114 -0
- package/src/routes/index.ts +148 -0
- package/src/track/index.test.ts +9 -0
- package/src/track/index.ts +14 -14
package/README.md
CHANGED
|
@@ -69,6 +69,12 @@ src/
|
|
|
69
69
|
- `CAREER_CATEGORY`
|
|
70
70
|
- `CAREER_MODE`
|
|
71
71
|
- `CAREER_LOCATION`
|
|
72
|
+
- `ROUTES`
|
|
73
|
+
- `ROUTE`
|
|
74
|
+
- `buildLocalizedRoute`
|
|
75
|
+
- `buildRoutePathName`
|
|
76
|
+
- `routeLabelKey`
|
|
77
|
+
- `routePathKey`
|
|
72
78
|
- `CONTACT_FORM_ENQUIRY_TYPE`
|
|
73
79
|
- `FILE_STATUS`
|
|
74
80
|
- `FILE_ORIGIN`
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/roles/index.test.ts
CHANGED
|
@@ -16,6 +16,8 @@ assert.equal(normalizeRole(0), "super-admin");
|
|
|
16
16
|
assert.equal(normalizeRole("admin"), "admin");
|
|
17
17
|
assert.equal(normalizeRole(2), "staff");
|
|
18
18
|
assert.equal(normalizeRole("hr"), "hr");
|
|
19
|
+
assert.equal(normalizeRole(32766), "visitor");
|
|
20
|
+
assert.equal(normalizeRole("none"), "none");
|
|
19
21
|
assert.equal(normalizeRole("unknown"), undefined);
|
|
20
22
|
assert.equal(normalizeRole(undefined), undefined);
|
|
21
23
|
|
|
@@ -23,12 +25,16 @@ assert.equal(roleToId("super-admin"), 0);
|
|
|
23
25
|
assert.equal(roleToId("admin"), 1);
|
|
24
26
|
assert.equal(roleToId("staff"), 2);
|
|
25
27
|
assert.equal(roleToId("hr"), 3);
|
|
28
|
+
assert.equal(roleToId("visitor"), 32766);
|
|
29
|
+
assert.equal(roleToId("none"), 32767);
|
|
26
30
|
assert.equal(roleToId("unknown"), undefined);
|
|
27
31
|
|
|
28
32
|
assert.equal(roleLabelKey(0), "users.roleSuperAdmin");
|
|
29
33
|
assert.equal(roleLabelKey("admin"), "users.roleAdmin");
|
|
30
34
|
assert.equal(roleLabelKey(2), "users.roleStaff");
|
|
31
35
|
assert.equal(roleLabelKey("hr"), "users.roleHr");
|
|
36
|
+
assert.equal(roleLabelKey("visitor"), "users.roleVisitor");
|
|
37
|
+
assert.equal(roleLabelKey("none"), "users.roleNone");
|
|
32
38
|
assert.equal(roleLabelKey(undefined), "users.roleStaff");
|
|
33
39
|
|
|
34
40
|
assert.deepEqual(ROLE[0], {
|
|
@@ -37,6 +43,16 @@ assert.deepEqual(ROLE[0], {
|
|
|
37
43
|
i18nKey: "users.roleSuperAdmin",
|
|
38
44
|
});
|
|
39
45
|
assert.equal(ROLE[3]?.i18nKey, "users.roleHr");
|
|
46
|
+
assert.deepEqual(ROLE[4], {
|
|
47
|
+
key: 32766,
|
|
48
|
+
value: "visitor",
|
|
49
|
+
i18nKey: "users.roleVisitor",
|
|
50
|
+
});
|
|
51
|
+
assert.deepEqual(ROLE[5], {
|
|
52
|
+
key: 32767,
|
|
53
|
+
value: "none",
|
|
54
|
+
i18nKey: "users.roleNone",
|
|
55
|
+
});
|
|
40
56
|
|
|
41
57
|
assert.equal(
|
|
42
58
|
PERMISSION_I18N_KEY[Permission.ALLOWED_EMAILS_READ],
|
|
@@ -55,6 +71,7 @@ assert.equal(
|
|
|
55
71
|
"permissions.twoFactorAuthWrite",
|
|
56
72
|
);
|
|
57
73
|
assert.equal(permissionLabelKey(Permission.VIEWS_READ), "permissions.viewsRead");
|
|
74
|
+
assert.equal(permissionLabelKey(Permission.LOGS_READ), "permissions.logsRead");
|
|
58
75
|
|
|
59
76
|
assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.USERS_DELETE));
|
|
60
77
|
assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.OTP_ATTEMPTS_READ));
|
|
@@ -62,14 +79,18 @@ assert.ok(
|
|
|
62
79
|
ROLE_PERMISSIONS["super-admin"].includes(Permission.TWO_FACTOR_AUTH_WRITE),
|
|
63
80
|
);
|
|
64
81
|
assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.VIEWS_READ));
|
|
82
|
+
assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.LOGS_READ));
|
|
65
83
|
assert.ok(ROLE_PERMISSIONS.admin.includes(Permission.CONTACT_FORM_DELETE));
|
|
66
84
|
assert.ok(ROLE_PERMISSIONS.admin.includes(Permission.VIEWS_READ));
|
|
85
|
+
assert.ok(ROLE_PERMISSIONS.admin.includes(Permission.LOGS_READ));
|
|
67
86
|
assert.equal(
|
|
68
87
|
ROLE_PERMISSIONS.admin.includes(Permission.USERS_WRITE),
|
|
69
88
|
false,
|
|
70
89
|
);
|
|
71
90
|
assert.ok(ROLE_PERMISSIONS.hr.includes(Permission.JOB_APPLICATIONS_READ));
|
|
72
91
|
assert.deepEqual(ROLE_PERMISSIONS.staff, [Permission.CONTACT_FORM_READ]);
|
|
92
|
+
assert.deepEqual(ROLE_PERMISSIONS.visitor, []);
|
|
93
|
+
assert.deepEqual(ROLE_PERMISSIONS.none, []);
|
|
73
94
|
|
|
74
95
|
assert.equal(hasPermission("super-admin", Permission.USERS_WRITE), true);
|
|
75
96
|
assert.equal(hasPermission("super-admin", Permission.OTP_ATTEMPTS_WRITE), true);
|
|
@@ -78,4 +99,6 @@ assert.equal(hasPermission("hr", Permission.CAREERS_WRITE), true);
|
|
|
78
99
|
assert.equal(hasPermission("staff", Permission.CAREERS_WRITE), false);
|
|
79
100
|
assert.equal(hasPermission("staff", Permission.CONTACT_FORM_READ), true);
|
|
80
101
|
assert.equal(hasPermission("admin", Permission.VIEWS_READ), true);
|
|
102
|
+
assert.equal(hasPermission("visitor", Permission.VIEWS_READ), false);
|
|
103
|
+
assert.equal(hasPermission(32767, Permission.LOGS_READ), false);
|
|
81
104
|
assert.equal(hasPermission(undefined, Permission.CAREERS_READ), false);
|
package/src/roles/index.ts
CHANGED
|
@@ -1,32 +1,53 @@
|
|
|
1
1
|
import type { MappingOption } from "../shared/types";
|
|
2
2
|
|
|
3
|
-
export type CanonicalRole =
|
|
3
|
+
export type CanonicalRole =
|
|
4
|
+
| "super-admin"
|
|
5
|
+
| "admin"
|
|
6
|
+
| "staff"
|
|
7
|
+
| "hr"
|
|
8
|
+
| "visitor"
|
|
9
|
+
| "none";
|
|
4
10
|
export type RoleValue = CanonicalRole | number;
|
|
5
11
|
export type RoleInput = RoleValue | string;
|
|
6
12
|
|
|
13
|
+
export const ROLE_MAP: Record<number, CanonicalRole> = {
|
|
14
|
+
0: "super-admin",
|
|
15
|
+
1: "admin",
|
|
16
|
+
2: "staff",
|
|
17
|
+
3: "hr",
|
|
18
|
+
32766: "visitor",
|
|
19
|
+
32767: "none",
|
|
20
|
+
};
|
|
21
|
+
|
|
7
22
|
export const ROLE = [
|
|
8
23
|
{ key: 0, value: "super-admin", i18nKey: "users.roleSuperAdmin" },
|
|
9
24
|
{ key: 1, value: "admin", i18nKey: "users.roleAdmin" },
|
|
10
25
|
{ key: 2, value: "staff", i18nKey: "users.roleStaff" },
|
|
11
26
|
{ key: 3, value: "hr", i18nKey: "users.roleHr" },
|
|
27
|
+
{ key: 32766, value: "visitor", i18nKey: "users.roleVisitor" },
|
|
28
|
+
{ key: 32767, value: "none", i18nKey: "users.roleNone" },
|
|
12
29
|
] as const satisfies readonly MappingOption[];
|
|
13
30
|
|
|
14
31
|
export function normalizeRole(
|
|
15
32
|
role: RoleInput | undefined,
|
|
16
33
|
): CanonicalRole | undefined {
|
|
34
|
+
if (typeof role === "number") {
|
|
35
|
+
return ROLE_MAP[role];
|
|
36
|
+
}
|
|
37
|
+
|
|
17
38
|
switch (role) {
|
|
18
|
-
case 0:
|
|
19
39
|
case "super-admin":
|
|
20
40
|
return "super-admin";
|
|
21
|
-
case 1:
|
|
22
41
|
case "admin":
|
|
23
42
|
return "admin";
|
|
24
|
-
case 2:
|
|
25
43
|
case "staff":
|
|
26
44
|
return "staff";
|
|
27
|
-
case 3:
|
|
28
45
|
case "hr":
|
|
29
46
|
return "hr";
|
|
47
|
+
case "visitor":
|
|
48
|
+
return "visitor";
|
|
49
|
+
case "none":
|
|
50
|
+
return "none";
|
|
30
51
|
default:
|
|
31
52
|
return undefined;
|
|
32
53
|
}
|
|
@@ -42,24 +63,18 @@ export function roleLabelKey(role: RoleInput | undefined): string {
|
|
|
42
63
|
return "users.roleHr";
|
|
43
64
|
case "staff":
|
|
44
65
|
return "users.roleStaff";
|
|
66
|
+
case "visitor":
|
|
67
|
+
return "users.roleVisitor";
|
|
68
|
+
case "none":
|
|
69
|
+
return "users.roleNone";
|
|
45
70
|
default:
|
|
46
71
|
return "users.roleStaff";
|
|
47
72
|
}
|
|
48
73
|
}
|
|
49
74
|
|
|
50
75
|
export function roleToId(role: RoleInput | undefined): number | undefined {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return 0;
|
|
54
|
-
case "admin":
|
|
55
|
-
return 1;
|
|
56
|
-
case "staff":
|
|
57
|
-
return 2;
|
|
58
|
-
case "hr":
|
|
59
|
-
return 3;
|
|
60
|
-
default:
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
76
|
+
const normalizedRole = normalizeRole(role);
|
|
77
|
+
return ROLE.find((option) => option.value === normalizedRole)?.key;
|
|
63
78
|
}
|
|
64
79
|
|
|
65
80
|
export const Permission = {
|
|
@@ -79,6 +94,7 @@ export const Permission = {
|
|
|
79
94
|
TWO_FACTOR_AUTH_READ: "two-factor-auth:read",
|
|
80
95
|
TWO_FACTOR_AUTH_WRITE: "two-factor-auth:write",
|
|
81
96
|
VIEWS_READ: "views:read",
|
|
97
|
+
LOGS_READ: "logs:read",
|
|
82
98
|
} as const;
|
|
83
99
|
|
|
84
100
|
export type Permission = (typeof Permission)[keyof typeof Permission];
|
|
@@ -100,6 +116,7 @@ export const PERMISSION_I18N_KEY: Record<Permission, string> = {
|
|
|
100
116
|
[Permission.TWO_FACTOR_AUTH_READ]: "permissions.twoFactorAuthRead",
|
|
101
117
|
[Permission.TWO_FACTOR_AUTH_WRITE]: "permissions.twoFactorAuthWrite",
|
|
102
118
|
[Permission.VIEWS_READ]: "permissions.viewsRead",
|
|
119
|
+
[Permission.LOGS_READ]: "permissions.logsRead",
|
|
103
120
|
};
|
|
104
121
|
|
|
105
122
|
export const ROLE_PERMISSIONS: Record<CanonicalRole, Permission[]> = {
|
|
@@ -120,6 +137,7 @@ export const ROLE_PERMISSIONS: Record<CanonicalRole, Permission[]> = {
|
|
|
120
137
|
Permission.TWO_FACTOR_AUTH_READ,
|
|
121
138
|
Permission.TWO_FACTOR_AUTH_WRITE,
|
|
122
139
|
Permission.VIEWS_READ,
|
|
140
|
+
Permission.LOGS_READ,
|
|
123
141
|
],
|
|
124
142
|
admin: [
|
|
125
143
|
Permission.ALLOWED_EMAILS_READ,
|
|
@@ -132,6 +150,7 @@ export const ROLE_PERMISSIONS: Record<CanonicalRole, Permission[]> = {
|
|
|
132
150
|
Permission.CONTACT_FORM_DELETE,
|
|
133
151
|
Permission.JOB_APPLICATIONS_READ,
|
|
134
152
|
Permission.VIEWS_READ,
|
|
153
|
+
Permission.LOGS_READ,
|
|
135
154
|
],
|
|
136
155
|
hr: [
|
|
137
156
|
Permission.CAREERS_READ,
|
|
@@ -140,6 +159,8 @@ export const ROLE_PERMISSIONS: Record<CanonicalRole, Permission[]> = {
|
|
|
140
159
|
Permission.JOB_APPLICATIONS_READ,
|
|
141
160
|
],
|
|
142
161
|
staff: [Permission.CONTACT_FORM_READ],
|
|
162
|
+
visitor: [],
|
|
163
|
+
none: [],
|
|
143
164
|
};
|
|
144
165
|
|
|
145
166
|
export function hasPermission(
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ROUTE,
|
|
5
|
+
ROUTES,
|
|
6
|
+
buildRoutePathName,
|
|
7
|
+
buildLocalizedRoute,
|
|
8
|
+
routeLabelKey,
|
|
9
|
+
routePathKey,
|
|
10
|
+
} from "./index";
|
|
11
|
+
|
|
12
|
+
assert.deepEqual(ROUTES, [
|
|
13
|
+
{
|
|
14
|
+
key: "home",
|
|
15
|
+
path: "/[locale]",
|
|
16
|
+
path_name: "/",
|
|
17
|
+
path_key: "/",
|
|
18
|
+
i18nKey: "routes.home",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
key: "about",
|
|
22
|
+
path: "/[locale]/about",
|
|
23
|
+
path_name: "/about",
|
|
24
|
+
path_key: "/about",
|
|
25
|
+
i18nKey: "routes.about",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
key: "career",
|
|
29
|
+
path: "/[locale]/career",
|
|
30
|
+
path_name: "/career",
|
|
31
|
+
path_key: "/career",
|
|
32
|
+
i18nKey: "routes.career",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
key: "careerDetail",
|
|
36
|
+
path: "/[locale]/career/[id]",
|
|
37
|
+
path_name: "/career/[id]",
|
|
38
|
+
path_key: "/career/[id]",
|
|
39
|
+
i18nKey: "routes.careerDetail",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
key: "careerApply",
|
|
43
|
+
path: "/[locale]/career/[id]/apply",
|
|
44
|
+
path_name: "/career/[id]/apply",
|
|
45
|
+
path_key: "/career/[id]/apply",
|
|
46
|
+
i18nKey: "routes.careerApply",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
key: "careerAssessment",
|
|
50
|
+
path: "/[locale]/career/[id]/apply/assessment",
|
|
51
|
+
path_name: "/career/[id]/apply/assessment",
|
|
52
|
+
path_key: "/career/[id]/apply/assessment",
|
|
53
|
+
i18nKey: "routes.careerAssessment",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
key: "contact",
|
|
57
|
+
path: "/[locale]/contact",
|
|
58
|
+
path_name: "/contact",
|
|
59
|
+
path_key: "/contact",
|
|
60
|
+
i18nKey: "routes.contact",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
key: "services",
|
|
64
|
+
path: "/[locale]/services",
|
|
65
|
+
path_name: "/services",
|
|
66
|
+
path_key: "/services",
|
|
67
|
+
i18nKey: "routes.services",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
key: "servicesAdvertisingPlatform",
|
|
71
|
+
path: "/[locale]/services/advertising-platform",
|
|
72
|
+
path_name: "/services/advertising-platform",
|
|
73
|
+
path_key: "/services/advertising-platform",
|
|
74
|
+
i18nKey: "routes.servicesAdvertisingPlatform",
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: "servicesMcnBusiness",
|
|
78
|
+
path: "/[locale]/services/mcn-business",
|
|
79
|
+
path_name: "/services/mcn-business",
|
|
80
|
+
path_key: "/services/mcn-business",
|
|
81
|
+
i18nKey: "routes.servicesMcnBusiness",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
key: "servicesSoftwareDevelopment",
|
|
85
|
+
path: "/[locale]/services/software-development",
|
|
86
|
+
path_name: "/services/software-development",
|
|
87
|
+
path_key: "/services/software-development",
|
|
88
|
+
i18nKey: "routes.servicesSoftwareDevelopment",
|
|
89
|
+
},
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
assert.equal(ROUTE.home, "/[locale]");
|
|
93
|
+
assert.equal(ROUTE.careerAssessment, "/[locale]/career/[id]/apply/assessment");
|
|
94
|
+
assert.equal(
|
|
95
|
+
buildLocalizedRoute("careerApply", "en", { id: "frontend-engineer" }),
|
|
96
|
+
"/en/career/frontend-engineer/apply",
|
|
97
|
+
);
|
|
98
|
+
assert.equal(
|
|
99
|
+
buildLocalizedRoute("servicesMcnBusiness", "zh"),
|
|
100
|
+
"/zh/services/mcn-business",
|
|
101
|
+
);
|
|
102
|
+
assert.equal(
|
|
103
|
+
buildRoutePathName("careerApply", { id: "frontend-engineer" }),
|
|
104
|
+
"/career/frontend-engineer/apply",
|
|
105
|
+
);
|
|
106
|
+
assert.equal(routePathKey("home"), "/");
|
|
107
|
+
assert.equal(routePathKey("careerApply"), "/career/[id]/apply");
|
|
108
|
+
assert.throws(() => buildLocalizedRoute("careerDetail", "en"), {
|
|
109
|
+
message: 'Route "careerDetail" requires an id parameter.',
|
|
110
|
+
});
|
|
111
|
+
assert.equal(
|
|
112
|
+
routeLabelKey("servicesSoftwareDevelopment"),
|
|
113
|
+
"routes.servicesSoftwareDevelopment",
|
|
114
|
+
);
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
export type RouteKey =
|
|
2
|
+
| "home"
|
|
3
|
+
| "about"
|
|
4
|
+
| "career"
|
|
5
|
+
| "careerDetail"
|
|
6
|
+
| "careerApply"
|
|
7
|
+
| "careerAssessment"
|
|
8
|
+
| "contact"
|
|
9
|
+
| "services"
|
|
10
|
+
| "servicesAdvertisingPlatform"
|
|
11
|
+
| "servicesMcnBusiness"
|
|
12
|
+
| "servicesSoftwareDevelopment";
|
|
13
|
+
|
|
14
|
+
export type RouteMapping = {
|
|
15
|
+
key: RouteKey;
|
|
16
|
+
path: string;
|
|
17
|
+
path_name: string;
|
|
18
|
+
path_key: string;
|
|
19
|
+
i18nKey: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const ROUTES = [
|
|
23
|
+
{
|
|
24
|
+
key: "home",
|
|
25
|
+
path: "/[locale]",
|
|
26
|
+
path_name: "/",
|
|
27
|
+
path_key: "/",
|
|
28
|
+
i18nKey: "routes.home",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
key: "about",
|
|
32
|
+
path: "/[locale]/about",
|
|
33
|
+
path_name: "/about",
|
|
34
|
+
path_key: "/about",
|
|
35
|
+
i18nKey: "routes.about",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "career",
|
|
39
|
+
path: "/[locale]/career",
|
|
40
|
+
path_name: "/career",
|
|
41
|
+
path_key: "/career",
|
|
42
|
+
i18nKey: "routes.career",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "careerDetail",
|
|
46
|
+
path: "/[locale]/career/[id]",
|
|
47
|
+
path_name: "/career/[id]",
|
|
48
|
+
path_key: "/career/[id]",
|
|
49
|
+
i18nKey: "routes.careerDetail",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
key: "careerApply",
|
|
53
|
+
path: "/[locale]/career/[id]/apply",
|
|
54
|
+
path_name: "/career/[id]/apply",
|
|
55
|
+
path_key: "/career/[id]/apply",
|
|
56
|
+
i18nKey: "routes.careerApply",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
key: "careerAssessment",
|
|
60
|
+
path: "/[locale]/career/[id]/apply/assessment",
|
|
61
|
+
path_name: "/career/[id]/apply/assessment",
|
|
62
|
+
path_key: "/career/[id]/apply/assessment",
|
|
63
|
+
i18nKey: "routes.careerAssessment",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
key: "contact",
|
|
67
|
+
path: "/[locale]/contact",
|
|
68
|
+
path_name: "/contact",
|
|
69
|
+
path_key: "/contact",
|
|
70
|
+
i18nKey: "routes.contact",
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
key: "services",
|
|
74
|
+
path: "/[locale]/services",
|
|
75
|
+
path_name: "/services",
|
|
76
|
+
path_key: "/services",
|
|
77
|
+
i18nKey: "routes.services",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
key: "servicesAdvertisingPlatform",
|
|
81
|
+
path: "/[locale]/services/advertising-platform",
|
|
82
|
+
path_name: "/services/advertising-platform",
|
|
83
|
+
path_key: "/services/advertising-platform",
|
|
84
|
+
i18nKey: "routes.servicesAdvertisingPlatform",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
key: "servicesMcnBusiness",
|
|
88
|
+
path: "/[locale]/services/mcn-business",
|
|
89
|
+
path_name: "/services/mcn-business",
|
|
90
|
+
path_key: "/services/mcn-business",
|
|
91
|
+
i18nKey: "routes.servicesMcnBusiness",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
key: "servicesSoftwareDevelopment",
|
|
95
|
+
path: "/[locale]/services/software-development",
|
|
96
|
+
path_name: "/services/software-development",
|
|
97
|
+
path_key: "/services/software-development",
|
|
98
|
+
i18nKey: "routes.servicesSoftwareDevelopment",
|
|
99
|
+
},
|
|
100
|
+
] as const satisfies readonly RouteMapping[];
|
|
101
|
+
|
|
102
|
+
export const ROUTE = Object.fromEntries(
|
|
103
|
+
ROUTES.map((route) => [route.key, route.path]),
|
|
104
|
+
) as Record<RouteKey, string>;
|
|
105
|
+
|
|
106
|
+
export function routeLabelKey(route: RouteKey): string {
|
|
107
|
+
return ROUTES.find((item) => item.key === route)?.i18nKey ?? "routes.home";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function routePathKey(route: RouteKey): string {
|
|
111
|
+
return ROUTES.find((item) => item.key === route)?.path_key ?? "/";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function buildRoutePathName(
|
|
115
|
+
route: RouteKey,
|
|
116
|
+
params: Partial<Record<"id", string | number>> = {},
|
|
117
|
+
): string {
|
|
118
|
+
let pathName: string =
|
|
119
|
+
ROUTES.find((item) => item.key === route)?.path_name ?? "/";
|
|
120
|
+
|
|
121
|
+
if (pathName.includes("[id]")) {
|
|
122
|
+
if (params.id === undefined || params.id === null) {
|
|
123
|
+
throw new Error(`Route "${route}" requires an id parameter.`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
pathName = pathName.replace("[id]", encodeURIComponent(String(params.id)));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return pathName;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function buildLocalizedRoute(
|
|
133
|
+
route: RouteKey,
|
|
134
|
+
locale: string,
|
|
135
|
+
params: Partial<Record<"id", string | number>> = {},
|
|
136
|
+
): string {
|
|
137
|
+
let path = ROUTE[route].replace("[locale]", encodeURIComponent(locale));
|
|
138
|
+
|
|
139
|
+
if (path.includes("[id]")) {
|
|
140
|
+
if (params.id === undefined || params.id === null) {
|
|
141
|
+
throw new Error(`Route "${route}" requires an id parameter.`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
path = path.replace("[id]", encodeURIComponent(String(params.id)));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return path;
|
|
148
|
+
}
|
package/src/track/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { MappingOption } from "../shared/types";
|
|
2
2
|
|
|
3
|
-
export const ORIGIN = [
|
|
4
|
-
{
|
|
5
|
-
key:
|
|
6
|
-
value: "Website",
|
|
7
|
-
i18nKey: "track.origin.
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
key:
|
|
11
|
-
value: "Linkedin",
|
|
12
|
-
i18nKey: "track.origin.
|
|
13
|
-
},
|
|
14
|
-
{ key:
|
|
15
|
-
{ key:
|
|
16
|
-
] as const satisfies readonly MappingOption[];
|
|
3
|
+
export const ORIGIN = [
|
|
4
|
+
{
|
|
5
|
+
key: 0,
|
|
6
|
+
value: "Website",
|
|
7
|
+
i18nKey: "track.origin.0",
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
key: 1,
|
|
11
|
+
value: "Linkedin",
|
|
12
|
+
i18nKey: "track.origin.1",
|
|
13
|
+
},
|
|
14
|
+
{ key: 2, value: "Jobstreet", i18nKey: "track.origin.2" },
|
|
15
|
+
{ key: 3, value: "Maukerja", i18nKey: "track.origin.3" },
|
|
16
|
+
] as const satisfies readonly MappingOption[];
|