najm-auth 1.1.8 → 1.1.9

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 (2) hide show
  1. package/dist/index.js +140 -140
  2. package/package.json +10 -10
package/dist/index.js CHANGED
@@ -2950,146 +2950,6 @@ var revokeTokenDto = z4.object({
2950
2950
  userId: userIdField
2951
2951
  });
2952
2952
 
2953
- // src/AuthPlugin.ts
2954
- import { cookies } from "najm-cookies";
2955
- import { i18n, I18N_CONTRIBUTIONS } from "najm-i18n";
2956
- import { guards } from "najm-guard";
2957
- import { validation } from "najm-validation";
2958
- import { rateLimit } from "najm-rate";
2959
- import { email } from "najm-email";
2960
-
2961
- // src/locales/en.json
2962
- var en_default = {
2963
- auth: {
2964
- errors: {
2965
- invalidCredentials: "Invalid email or password",
2966
- emailExists: "Email already registered",
2967
- accessDenied: "Access denied",
2968
- tokenExpired: "Token has expired",
2969
- tokenInvalid: "Invalid token",
2970
- tokenMissing: "Authorization token is missing",
2971
- tokenVerificationFailed: "Token verification failed",
2972
- tokenRevoked: "Token has been revoked",
2973
- refreshTokenMissing: "Refresh token is missing",
2974
- refreshTokenInvalid: "Invalid refresh token",
2975
- invalidResetToken: "Invalid password reset token",
2976
- resetTokenExpired: "Password reset token has expired",
2977
- unauthorized: "Unauthorized access",
2978
- sessionExpired: "Session has expired"
2979
- },
2980
- success: {
2981
- login: "Login successful",
2982
- logout: "Logout successful",
2983
- passwordChanged: "Password changed successfully",
2984
- tokenRefreshed: "Token refreshed successfully"
2985
- }
2986
- },
2987
- users: {
2988
- errors: {
2989
- notFound: "User not found",
2990
- idExists: "User ID already exists",
2991
- emailRequired: "Email is required",
2992
- passwordRequired: "Password is required",
2993
- invalidEmail: "Invalid email format",
2994
- weakPassword: "Password is too weak",
2995
- adminRoleNotFound: "Admin role not found in system"
2996
- },
2997
- success: {
2998
- created: "User created successfully",
2999
- updated: "User updated successfully",
3000
- deleted: "User deleted successfully",
3001
- retrieved: "User retrieved successfully"
3002
- }
3003
- },
3004
- roles: {
3005
- errors: {
3006
- notFound: "Role not found",
3007
- exists: "Role already exists",
3008
- nameRequired: "Role name is required",
3009
- cannotDeleteSystem: "Cannot delete system role"
3010
- },
3011
- success: {
3012
- created: "Role created successfully",
3013
- updated: "Role updated successfully",
3014
- deleted: "Role deleted successfully",
3015
- assigned: "Role assigned successfully",
3016
- retrieved: "Role retrieved successfully"
3017
- }
3018
- },
3019
- permissions: {
3020
- errors: {
3021
- notFound: "Permission not found",
3022
- nameExists: "Permission name already exists",
3023
- roleAlreadyHasPermission: "Role already has this permission",
3024
- cannotRemoveRequired: "Cannot remove required permission"
3025
- },
3026
- success: {
3027
- created: "Permission created successfully",
3028
- updated: "Permission updated successfully",
3029
- deleted: "Permission deleted successfully",
3030
- granted: "Permission granted successfully",
3031
- revoked: "Permission revoked successfully",
3032
- retrieved: "Permissions retrieved successfully",
3033
- assigned: "Permission assigned to role successfully",
3034
- removed: "Permission removed from role successfully",
3035
- allDeleted: "All permissions deleted successfully"
3036
- }
3037
- }
3038
- };
3039
-
3040
- // src/locales/index.ts
3041
- var AUTH_LOCALES = {
3042
- en: en_default
3043
- };
3044
- function getAuthLocale(lang) {
3045
- return AUTH_LOCALES[lang] ?? AUTH_LOCALES.en;
3046
- }
3047
- __name(getAuthLocale, "getAuthLocale");
3048
- var AUTH_SUPPORTED_LANGUAGES = Object.keys(AUTH_LOCALES);
3049
-
3050
- // src/AuthPlugin.ts
3051
- var DEFAULT_JWT = {
3052
- accessSecret: process.env.JWT_ACCESS_SECRET || "",
3053
- accessExpiresIn: process.env.ACCESS_EXPIRES_IN || "1h",
3054
- refreshSecret: process.env.JWT_REFRESH_SECRET || "",
3055
- refreshExpiresIn: process.env.REFRESH_EXPIRES_IN || "7d"
3056
- };
3057
- var mergeConfig = /* @__PURE__ */ __name((config) => {
3058
- const finalConfig = {
3059
- jwt: {
3060
- ...DEFAULT_JWT,
3061
- ...config?.jwt
3062
- },
3063
- refreshCookieName: config?.refreshCookieName ?? "refreshToken",
3064
- database: config?.database ?? "default",
3065
- blacklistPrefix: config?.blacklistPrefix ?? "auth:blacklist:",
3066
- defaultRole: config?.defaultRole ?? null,
3067
- frontendUrl: config?.frontendUrl ?? process.env.FRONTEND_URL ?? "http://localhost:3000"
3068
- };
3069
- if (!finalConfig.jwt.accessSecret) {
3070
- throw Err8.configRequired("auth", "JWT_ACCESS_SECRET");
3071
- }
3072
- if (!finalConfig.jwt.refreshSecret) {
3073
- throw Err8.configRequired("auth", "JWT_REFRESH_SECRET");
3074
- }
3075
- return finalConfig;
3076
- }, "mergeConfig");
3077
- var selectSchema = /* @__PURE__ */ __name((config) => {
3078
- if (config?.schema)
3079
- return config.schema;
3080
- const dialect = config?.dialect ?? "pg";
3081
- switch (dialect) {
3082
- case "sqlite":
3083
- return authSchema2;
3084
- case "mysql":
3085
- return authSchema3;
3086
- case "pg":
3087
- default:
3088
- return authSchema;
3089
- }
3090
- }, "selectSchema");
3091
- var auth = /* @__PURE__ */ __name((config) => plugin("auth").version("1.0.0").depends(cache(), cookies(), i18n(), guards(), validation(config?.validation), rateLimit(config?.rateLimit), email()).requires("database").contributes(I18N_CONTRIBUTIONS, AUTH_LOCALES).services(auth_exports, users_exports, roles_exports, permissions_exports, tokens_exports).config(AUTH_CONFIG, mergeConfig(config)).set(AUTH_SCHEMA, selectSchema(config)).build(), "auth");
3092
-
3093
2953
  // src/ownership/scopedOwnership.ts
3094
2954
  import { aliasedTable, eq as eq6, getTableColumns, sql as sql4 } from "drizzle-orm";
3095
2955
  var DEFAULT_ADMIN_ROLES = ["admin", "principal"];
@@ -3696,6 +3556,146 @@ function Owned(token) {
3696
3556
  }
3697
3557
  __name(Owned, "Owned");
3698
3558
 
3559
+ // src/AuthPlugin.ts
3560
+ import { cookies } from "najm-cookies";
3561
+ import { i18n, I18N_CONTRIBUTIONS } from "najm-i18n";
3562
+ import { guards } from "najm-guard";
3563
+ import { validation } from "najm-validation";
3564
+ import { rateLimit } from "najm-rate";
3565
+ import { email } from "najm-email";
3566
+
3567
+ // src/locales/en.json
3568
+ var en_default = {
3569
+ auth: {
3570
+ errors: {
3571
+ invalidCredentials: "Invalid email or password",
3572
+ emailExists: "Email already registered",
3573
+ accessDenied: "Access denied",
3574
+ tokenExpired: "Token has expired",
3575
+ tokenInvalid: "Invalid token",
3576
+ tokenMissing: "Authorization token is missing",
3577
+ tokenVerificationFailed: "Token verification failed",
3578
+ tokenRevoked: "Token has been revoked",
3579
+ refreshTokenMissing: "Refresh token is missing",
3580
+ refreshTokenInvalid: "Invalid refresh token",
3581
+ invalidResetToken: "Invalid password reset token",
3582
+ resetTokenExpired: "Password reset token has expired",
3583
+ unauthorized: "Unauthorized access",
3584
+ sessionExpired: "Session has expired"
3585
+ },
3586
+ success: {
3587
+ login: "Login successful",
3588
+ logout: "Logout successful",
3589
+ passwordChanged: "Password changed successfully",
3590
+ tokenRefreshed: "Token refreshed successfully"
3591
+ }
3592
+ },
3593
+ users: {
3594
+ errors: {
3595
+ notFound: "User not found",
3596
+ idExists: "User ID already exists",
3597
+ emailRequired: "Email is required",
3598
+ passwordRequired: "Password is required",
3599
+ invalidEmail: "Invalid email format",
3600
+ weakPassword: "Password is too weak",
3601
+ adminRoleNotFound: "Admin role not found in system"
3602
+ },
3603
+ success: {
3604
+ created: "User created successfully",
3605
+ updated: "User updated successfully",
3606
+ deleted: "User deleted successfully",
3607
+ retrieved: "User retrieved successfully"
3608
+ }
3609
+ },
3610
+ roles: {
3611
+ errors: {
3612
+ notFound: "Role not found",
3613
+ exists: "Role already exists",
3614
+ nameRequired: "Role name is required",
3615
+ cannotDeleteSystem: "Cannot delete system role"
3616
+ },
3617
+ success: {
3618
+ created: "Role created successfully",
3619
+ updated: "Role updated successfully",
3620
+ deleted: "Role deleted successfully",
3621
+ assigned: "Role assigned successfully",
3622
+ retrieved: "Role retrieved successfully"
3623
+ }
3624
+ },
3625
+ permissions: {
3626
+ errors: {
3627
+ notFound: "Permission not found",
3628
+ nameExists: "Permission name already exists",
3629
+ roleAlreadyHasPermission: "Role already has this permission",
3630
+ cannotRemoveRequired: "Cannot remove required permission"
3631
+ },
3632
+ success: {
3633
+ created: "Permission created successfully",
3634
+ updated: "Permission updated successfully",
3635
+ deleted: "Permission deleted successfully",
3636
+ granted: "Permission granted successfully",
3637
+ revoked: "Permission revoked successfully",
3638
+ retrieved: "Permissions retrieved successfully",
3639
+ assigned: "Permission assigned to role successfully",
3640
+ removed: "Permission removed from role successfully",
3641
+ allDeleted: "All permissions deleted successfully"
3642
+ }
3643
+ }
3644
+ };
3645
+
3646
+ // src/locales/index.ts
3647
+ var AUTH_LOCALES = {
3648
+ en: en_default
3649
+ };
3650
+ function getAuthLocale(lang) {
3651
+ return AUTH_LOCALES[lang] ?? AUTH_LOCALES.en;
3652
+ }
3653
+ __name(getAuthLocale, "getAuthLocale");
3654
+ var AUTH_SUPPORTED_LANGUAGES = Object.keys(AUTH_LOCALES);
3655
+
3656
+ // src/AuthPlugin.ts
3657
+ var DEFAULT_JWT = {
3658
+ accessSecret: process.env.JWT_ACCESS_SECRET || "",
3659
+ accessExpiresIn: process.env.ACCESS_EXPIRES_IN || "1h",
3660
+ refreshSecret: process.env.JWT_REFRESH_SECRET || "",
3661
+ refreshExpiresIn: process.env.REFRESH_EXPIRES_IN || "7d"
3662
+ };
3663
+ var mergeConfig = /* @__PURE__ */ __name((config) => {
3664
+ const finalConfig = {
3665
+ jwt: {
3666
+ ...DEFAULT_JWT,
3667
+ ...config?.jwt
3668
+ },
3669
+ refreshCookieName: config?.refreshCookieName ?? "refreshToken",
3670
+ database: config?.database ?? "default",
3671
+ blacklistPrefix: config?.blacklistPrefix ?? "auth:blacklist:",
3672
+ defaultRole: config?.defaultRole ?? null,
3673
+ frontendUrl: config?.frontendUrl ?? process.env.FRONTEND_URL ?? "http://localhost:3000"
3674
+ };
3675
+ if (!finalConfig.jwt.accessSecret) {
3676
+ throw Err8.configRequired("auth", "JWT_ACCESS_SECRET");
3677
+ }
3678
+ if (!finalConfig.jwt.refreshSecret) {
3679
+ throw Err8.configRequired("auth", "JWT_REFRESH_SECRET");
3680
+ }
3681
+ return finalConfig;
3682
+ }, "mergeConfig");
3683
+ var selectSchema = /* @__PURE__ */ __name((config) => {
3684
+ if (config?.schema)
3685
+ return config.schema;
3686
+ const dialect = config?.dialect ?? "pg";
3687
+ switch (dialect) {
3688
+ case "sqlite":
3689
+ return authSchema2;
3690
+ case "mysql":
3691
+ return authSchema3;
3692
+ case "pg":
3693
+ default:
3694
+ return authSchema;
3695
+ }
3696
+ }, "selectSchema");
3697
+ var auth = /* @__PURE__ */ __name((config) => plugin("auth").version("1.0.0").depends(cache(), cookies(), i18n(), guards(), validation(config?.validation), rateLimit(config?.rateLimit), email()).requires("database").contributes(I18N_CONTRIBUTIONS, AUTH_LOCALES).services(auth_exports, users_exports, roles_exports, permissions_exports, tokens_exports, ScopeContext).config(AUTH_CONFIG, mergeConfig(config)).set(AUTH_SCHEMA, selectSchema(config)).build(), "auth");
3698
+
3699
3699
  // src/seed.ts
3700
3700
  import { hash } from "bcryptjs";
3701
3701
  var toSeedId = /* @__PURE__ */ __name((prefix, value) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "najm-auth",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "Authentication and authorization library for najm framework",
5
5
  "type": "module",
6
6
  "files": [
@@ -58,15 +58,15 @@
58
58
  "typescript": "^5.9.3"
59
59
  },
60
60
  "dependencies": {
61
- "najm-cookies": "^1.1.2",
62
- "najm-core": "^1.1.2",
63
- "najm-database": "^1.1.3",
64
- "najm-guard": "^1.1.2",
65
- "najm-i18n": "^1.1.2",
66
- "najm-cache": "^1.1.2",
67
- "najm-email": "^1.1.2",
68
- "najm-rate": "^1.1.2",
69
- "najm-validation": "^1.1.2",
61
+ "najm-cookies": "^1.1.3",
62
+ "najm-core": "^1.1.3",
63
+ "najm-database": "^1.1.4",
64
+ "najm-guard": "^1.1.3",
65
+ "najm-i18n": "^1.1.3",
66
+ "najm-cache": "^1.1.3",
67
+ "najm-email": "^1.1.3",
68
+ "najm-rate": "^1.1.3",
69
+ "najm-validation": "^1.1.3",
70
70
  "bcryptjs": "^3.0.3",
71
71
  "hono": "^4.0.0",
72
72
  "jsonwebtoken": "^9.0.3",