@yangsaiyam/helper 1.5.1 → 1.5.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yangsaiyam/helper",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "main": "./src/index.ts",
5
5
  "types": "./src/index.ts",
6
6
  "exports": {
@@ -8,5 +8,9 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "dayjs": "^1.11.20"
11
+ },
12
+ "devDependencies": {
13
+ "@types/node": "^25.6.0",
14
+ "typescript": "^6.0.3"
11
15
  }
12
16
  }
@@ -3,8 +3,8 @@ import assert from "node:assert/strict";
3
3
  import {
4
4
  ASSESSMENT_QUESTION_TYPE,
5
5
  QuestionType,
6
- } from "./index.ts";
7
- import { getI18nKeyByKey, getLabelByKey, getOptionByKey } from "../shared/helpers.ts";
6
+ } from "./index";
7
+ import { getI18nKeyByKey, getLabelByKey, getOptionByKey } from "../shared/helpers";
8
8
 
9
9
  assert.deepEqual(ASSESSMENT_QUESTION_TYPE, [
10
10
  {
@@ -10,7 +10,7 @@ import {
10
10
  permissionLabelKey,
11
11
  roleLabelKey,
12
12
  roleToId,
13
- } from "./index.ts";
13
+ } from "./index";
14
14
 
15
15
  assert.equal(normalizeRole(0), "super-admin");
16
16
  assert.equal(normalizeRole("admin"), "admin");
@@ -46,14 +46,36 @@ assert.equal(
46
46
  permissionLabelKey(Permission.CONTACT_FORM_DELETE),
47
47
  "permissions.contactFormDelete",
48
48
  );
49
+ assert.equal(
50
+ permissionLabelKey(Permission.OTP_ATTEMPTS_READ),
51
+ "permissions.otpAttemptsRead",
52
+ );
53
+ assert.equal(
54
+ permissionLabelKey(Permission.TWO_FACTOR_AUTH_WRITE),
55
+ "permissions.twoFactorAuthWrite",
56
+ );
57
+ assert.equal(permissionLabelKey(Permission.VIEWS_READ), "permissions.viewsRead");
49
58
 
50
59
  assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.USERS_DELETE));
60
+ assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.OTP_ATTEMPTS_READ));
61
+ assert.ok(
62
+ ROLE_PERMISSIONS["super-admin"].includes(Permission.TWO_FACTOR_AUTH_WRITE),
63
+ );
64
+ assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.VIEWS_READ));
51
65
  assert.ok(ROLE_PERMISSIONS.admin.includes(Permission.CONTACT_FORM_DELETE));
66
+ assert.ok(ROLE_PERMISSIONS.admin.includes(Permission.VIEWS_READ));
67
+ assert.equal(
68
+ ROLE_PERMISSIONS.admin.includes(Permission.USERS_WRITE),
69
+ false,
70
+ );
52
71
  assert.ok(ROLE_PERMISSIONS.hr.includes(Permission.JOB_APPLICATIONS_READ));
53
- assert.deepEqual(ROLE_PERMISSIONS.staff, [Permission.CAREERS_READ]);
72
+ assert.deepEqual(ROLE_PERMISSIONS.staff, [Permission.CONTACT_FORM_READ]);
54
73
 
55
74
  assert.equal(hasPermission("super-admin", Permission.USERS_WRITE), true);
75
+ assert.equal(hasPermission("super-admin", Permission.OTP_ATTEMPTS_WRITE), true);
56
76
  assert.equal(hasPermission(1, Permission.USERS_WRITE), false);
57
77
  assert.equal(hasPermission("hr", Permission.CAREERS_WRITE), true);
58
78
  assert.equal(hasPermission("staff", Permission.CAREERS_WRITE), false);
79
+ assert.equal(hasPermission("staff", Permission.CONTACT_FORM_READ), true);
80
+ assert.equal(hasPermission("admin", Permission.VIEWS_READ), true);
59
81
  assert.equal(hasPermission(undefined, Permission.CAREERS_READ), false);
@@ -74,6 +74,11 @@ export const Permission = {
74
74
  CONTACT_FORM_READ: "contact-form:read",
75
75
  CONTACT_FORM_DELETE: "contact-form:delete",
76
76
  JOB_APPLICATIONS_READ: "job-applications:read",
77
+ OTP_ATTEMPTS_READ: "otp-attempts:read",
78
+ OTP_ATTEMPTS_WRITE: "otp-attempts:write",
79
+ TWO_FACTOR_AUTH_READ: "two-factor-auth:read",
80
+ TWO_FACTOR_AUTH_WRITE: "two-factor-auth:write",
81
+ VIEWS_READ: "views:read",
77
82
  } as const;
78
83
 
79
84
  export type Permission = (typeof Permission)[keyof typeof Permission];
@@ -90,6 +95,11 @@ export const PERMISSION_I18N_KEY: Record<Permission, string> = {
90
95
  [Permission.CONTACT_FORM_READ]: "permissions.contactFormRead",
91
96
  [Permission.CONTACT_FORM_DELETE]: "permissions.contactFormDelete",
92
97
  [Permission.JOB_APPLICATIONS_READ]: "permissions.jobApplicationsRead",
98
+ [Permission.OTP_ATTEMPTS_READ]: "permissions.otpAttemptsRead",
99
+ [Permission.OTP_ATTEMPTS_WRITE]: "permissions.otpAttemptsWrite",
100
+ [Permission.TWO_FACTOR_AUTH_READ]: "permissions.twoFactorAuthRead",
101
+ [Permission.TWO_FACTOR_AUTH_WRITE]: "permissions.twoFactorAuthWrite",
102
+ [Permission.VIEWS_READ]: "permissions.viewsRead",
93
103
  };
94
104
 
95
105
  export const ROLE_PERMISSIONS: Record<CanonicalRole, Permission[]> = {
@@ -105,6 +115,11 @@ export const ROLE_PERMISSIONS: Record<CanonicalRole, Permission[]> = {
105
115
  Permission.CONTACT_FORM_READ,
106
116
  Permission.CONTACT_FORM_DELETE,
107
117
  Permission.JOB_APPLICATIONS_READ,
118
+ Permission.OTP_ATTEMPTS_READ,
119
+ Permission.OTP_ATTEMPTS_WRITE,
120
+ Permission.TWO_FACTOR_AUTH_READ,
121
+ Permission.TWO_FACTOR_AUTH_WRITE,
122
+ Permission.VIEWS_READ,
108
123
  ],
109
124
  admin: [
110
125
  Permission.ALLOWED_EMAILS_READ,
@@ -116,6 +131,7 @@ export const ROLE_PERMISSIONS: Record<CanonicalRole, Permission[]> = {
116
131
  Permission.CONTACT_FORM_READ,
117
132
  Permission.CONTACT_FORM_DELETE,
118
133
  Permission.JOB_APPLICATIONS_READ,
134
+ Permission.VIEWS_READ,
119
135
  ],
120
136
  hr: [
121
137
  Permission.CAREERS_READ,
@@ -123,7 +139,7 @@ export const ROLE_PERMISSIONS: Record<CanonicalRole, Permission[]> = {
123
139
  Permission.CAREERS_DELETE,
124
140
  Permission.JOB_APPLICATIONS_READ,
125
141
  ],
126
- staff: [Permission.CAREERS_READ],
142
+ staff: [Permission.CONTACT_FORM_READ],
127
143
  };
128
144
 
129
145
  export function hasPermission(
@@ -8,7 +8,7 @@ import {
8
8
  normalizeTimezone,
9
9
  timezoneLabelKey,
10
10
  timezoneToUtc,
11
- } from "./index.ts";
11
+ } from "./index";
12
12
 
13
13
  assert.equal(normalizeTimezone("UTC"), "UTC");
14
14
  assert.equal(normalizeTimezone("utc"), "UTC");
package/tsconfig.json CHANGED
@@ -5,7 +5,8 @@
5
5
  "moduleResolution": "Bundler",
6
6
  "strict": true,
7
7
  "declaration": true,
8
- "skipLibCheck": true
8
+ "skipLibCheck": true,
9
+ "types": ["node"]
9
10
  },
10
11
  "include": ["src"]
11
12
  }