@plyaz/types 1.27.6 → 1.27.8

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.
@@ -737,3 +737,165 @@ export interface AuthErrorOptions {
737
737
  * Type for a single error definition object.
738
738
  */
739
739
  export type AuthErrorDefinition = (typeof AUTH_ERROR_DEFINITIONS)[AuthErrorCodeValue];
740
+ /**
741
+ * @fileoverview Authentication error codes for @plyaz/auth
742
+ * @module @plyaz/auth/constants/auth-error-codes
743
+ *
744
+ * @description
745
+ * Standardized error codes for authentication system failures.
746
+ * These codes provide consistent error identification across the entire
747
+ * auth system, enabling proper error handling, logging, and user feedback.
748
+ * Used by error classes, services, and frontend components.
749
+ *
750
+ * @example
751
+ * ```typescript
752
+ * import { AUTH_ERROR_CODES } from '@plyaz/auth';
753
+ *
754
+ * throw new InvalidCredentialsError(AUTH_ERROR_CODES.INVALID_CREDENTIALS);
755
+ *
756
+ * if (error.code === AUTH_ERROR_CODES.TOKEN_EXPIRED) {
757
+ * // Handle token expiration
758
+ * }
759
+ * ```
760
+ */
761
+ /**
762
+ * Authentication error codes
763
+ * Standardized error identifiers for consistent error handling
764
+ */
765
+ /**
766
+ * Type for authentication error codes
767
+ */
768
+ export type AuthErrorCode = (typeof AUTH_ERROR_CODES)[keyof typeof AUTH_ERROR_CODES];
769
+ /**
770
+ * Error code to HTTP status mapping
771
+ * Maps error codes to appropriate HTTP status codes
772
+ */
773
+ export declare const ERROR_CODE_TO_HTTP_STATUS: Record<AuthErrorCode, number>;
774
+ /**
775
+ * Error code descriptions for logging and debugging
776
+ */
777
+ export declare const ERROR_CODE_DESCRIPTIONS: Record<AuthErrorCode, string>;
778
+ /**
779
+ * @fileoverview Interfaces and types for @plyaz/auth
780
+ * @module @plyaz/auth/interfaces
781
+ */
782
+ export interface AuthUser {
783
+ id: string;
784
+ email: string;
785
+ clerkUserId?: string;
786
+ authProvider: string;
787
+ firstName?: string;
788
+ lastName?: string;
789
+ displayName: string;
790
+ avatarUrl?: string;
791
+ phoneNumber?: string;
792
+ isActive: boolean;
793
+ isVerified: boolean;
794
+ createdAt: Date;
795
+ updatedAt: Date;
796
+ lastLoginAt?: Date;
797
+ roles?: string[];
798
+ passwordHash?: string;
799
+ isSuspended?: boolean;
800
+ }
801
+ export interface UserRepository {
802
+ findById(id: string): Promise<AuthUser | null>;
803
+ findByEmail(email: string): Promise<AuthUser | null>;
804
+ create(data: CreateUserData): Promise<AuthUser>;
805
+ update(id: string, data: UpdateUserData): Promise<AuthUser>;
806
+ delete(id: string): Promise<void>;
807
+ }
808
+ export interface SessionRepository {
809
+ create(data: CreateSessionData): Promise<Session>;
810
+ findById(id: string): Promise<Session | null>;
811
+ findByUserId(userId: string): Promise<Session[]>;
812
+ invalidate(sessionId: string): Promise<void>;
813
+ delete(sessionId: string): Promise<void>;
814
+ deleteByUserId(userId: string): Promise<void>;
815
+ updateLastActive(sessionId: string): Promise<void>;
816
+ }
817
+ export interface ConnectedAccountRepository {
818
+ create(data: CreateConnectedAccountData): Promise<ConnectedAccount>;
819
+ findById(id: string): Promise<ConnectedAccount | null>;
820
+ findByUserId(userId: string): Promise<ConnectedAccount[]>;
821
+ findByProvider(provider: string, providerAccountId: string): Promise<ConnectedAccount | null>;
822
+ update(id: string, data: UpdateConnectedAccountData): Promise<ConnectedAccount>;
823
+ delete(id: string): Promise<void>;
824
+ }
825
+ export interface JWTConfig {
826
+ privateKey: string;
827
+ publicKey: string;
828
+ issuer: string;
829
+ audience: string;
830
+ accessTokenTTL: string;
831
+ refreshTokenTTL: string;
832
+ algorithm?: string;
833
+ }
834
+ export interface SessionConfig {
835
+ maxConcurrentSessions: number;
836
+ sessionTTL: number;
837
+ cleanupInterval: number;
838
+ }
839
+ /**
840
+ * @fileoverview OAuth provider constants for @plyaz/auth
841
+ * @module @plyaz/auth/constants/oauth-providers
842
+ *
843
+ * @description
844
+ * Defines supported OAuth providers and their configurations.
845
+ * Used by adapters, strategies, and frontend components to handle
846
+ * OAuth authentication flows. Provides standardized provider names
847
+ * and metadata for consistent provider handling.
848
+ *
849
+ * @example
850
+ * ```typescript
851
+ * import { OAUTH_PROVIDERS, OAuthProviderConfig } from '@plyaz/auth';
852
+ *
853
+ * const googleConfig = OAUTH_PROVIDER_CONFIGS[OAUTH_PROVIDERS.GOOGLE];
854
+ * const authUrl = `${googleConfig.authUrl}?client_id=${clientId}`;
855
+ * ```
856
+ */
857
+ /**
858
+ * Supported OAuth providers
859
+ * Standardized provider identifiers used throughout the system
860
+ */
861
+ export declare const OAUTH_PROVIDERS: {
862
+ /** Google OAuth 2.0 */
863
+ readonly GOOGLE: "GOOGLE";
864
+ /** Facebook OAuth 2.0 */
865
+ readonly FACEBOOK: "FACEBOOK";
866
+ /** Apple Sign In */
867
+ readonly APPLE: "APPLE";
868
+ /** GitHub OAuth 2.0 */
869
+ readonly GITHUB: "GITHUB";
870
+ /** Twitter OAuth 2.0 */
871
+ readonly TWITTER: "TWITTER";
872
+ /** LinkedIn OAuth 2.0 */
873
+ readonly LINKEDIN: "LINKEDIN";
874
+ /** Discord OAuth 2.0 */
875
+ readonly DISCORD: "DISCORD";
876
+ /** Microsoft OAuth 2.0 */
877
+ readonly MICROSOFT: "MICROSOFT";
878
+ };
879
+ /**
880
+ * Type for OAuth provider names
881
+ */
882
+ export type OAuthProvider = typeof OAUTH_PROVIDERS[keyof typeof OAUTH_PROVIDERS];
883
+ /**
884
+ * OAuth provider configuration interface
885
+ */
886
+ export interface OAuthProviderConfig {
887
+ /** Provider display name */
888
+ name: string;
889
+ /** OAuth authorization URL */
890
+ authUrl: string;
891
+ /** OAuth token exchange URL */
892
+ tokenUrl: string;
893
+ /** OAuth user info URL */
894
+ userInfoUrl: string;
895
+ /** Required OAuth scopes */
896
+ scopes: string[];
897
+ /** Provider brand color (for UI) */
898
+ brandColor: string;
899
+ /** Provider icon name (for UI) */
900
+ iconName: string;
901
+ }
package/dist/index.cjs CHANGED
@@ -5988,6 +5988,46 @@ var AUTH_ERROR_DEFINITIONS = {
5988
5988
  retryable: false
5989
5989
  }
5990
5990
  };
5991
+ var USERROLESTATUS = /* @__PURE__ */ ((USERROLESTATUS2) => {
5992
+ USERROLESTATUS2["ACTIVE"] = "ACTIVE";
5993
+ USERROLESTATUS2["INACTIVE"] = "INACTIVE";
5994
+ USERROLESTATUS2["SUSPENDED"] = "SUSPENDED";
5995
+ return USERROLESTATUS2;
5996
+ })(USERROLESTATUS || {});
5997
+ var AUTHPROVIDER = /* @__PURE__ */ ((AUTHPROVIDER2) => {
5998
+ AUTHPROVIDER2["EMAIL"] = "EMAIL";
5999
+ AUTHPROVIDER2["CLERK"] = "CLERK";
6000
+ AUTHPROVIDER2["GOOGLE"] = "GOOGLE";
6001
+ AUTHPROVIDER2["FACEBOOK"] = "FACEBOOK";
6002
+ AUTHPROVIDER2["APPLE"] = "APPLE";
6003
+ AUTHPROVIDER2["WEB3"] = "WEB3";
6004
+ AUTHPROVIDER2["NEXTAUTH"] = "NEXTAUTH";
6005
+ return AUTHPROVIDER2;
6006
+ })(AUTHPROVIDER || {});
6007
+ var TOKENTYPE = /* @__PURE__ */ ((TOKENTYPE2) => {
6008
+ TOKENTYPE2["BEARER"] = "Bearer";
6009
+ TOKENTYPE2["JWT"] = "JWT";
6010
+ return TOKENTYPE2;
6011
+ })(TOKENTYPE || {});
6012
+ var PROVIDERTYPE = /* @__PURE__ */ ((PROVIDERTYPE2) => {
6013
+ PROVIDERTYPE2["OAUTH"] = "OAUTH";
6014
+ PROVIDERTYPE2["WEB3"] = "WEB3";
6015
+ PROVIDERTYPE2["EMAIL"] = "EMAIL";
6016
+ return PROVIDERTYPE2;
6017
+ })(PROVIDERTYPE || {});
6018
+ var SESSIONSTATUS = /* @__PURE__ */ ((SESSIONSTATUS2) => {
6019
+ SESSIONSTATUS2["ACTIVE"] = "ACTIVE";
6020
+ SESSIONSTATUS2["EXPIRED"] = "EXPIRED";
6021
+ SESSIONSTATUS2["REVOKED"] = "REVOKED";
6022
+ return SESSIONSTATUS2;
6023
+ })(SESSIONSTATUS || {});
6024
+ var MFATYPE = /* @__PURE__ */ ((MFATYPE2) => {
6025
+ MFATYPE2["TOTP"] = "TOTP";
6026
+ MFATYPE2["SMS"] = "SMS";
6027
+ MFATYPE2["EMAIL"] = "EMAIL";
6028
+ MFATYPE2["BackupCodes"] = "BACKUP_CODES";
6029
+ return MFATYPE2;
6030
+ })(MFATYPE || {});
5991
6031
  var DEFAULT_PASSWORD = 8;
5992
6032
  var ContactUsFormSchema = zod.z.object({
5993
6033
  name: zod.z.string({ error: "errors.form.missingField" }).min(1, "errors.form.nameMissing"),
@@ -6016,6 +6056,90 @@ var AUTH_ERROR_CODES = {
6016
6056
  ACCOUNT_LOCKED: "AUTH_ACCOUNT_LOCKED",
6017
6057
  ACCOUNT_SUSPENDED: "AUTH_ACCOUNT_SUSPENDED"
6018
6058
  };
6059
+ var ERROR_CODE_TO_HTTP_STATUS = {
6060
+ [AUTH_ERROR_CODES.INVALID_CREDENTIALS]: 401,
6061
+ [AUTH_ERROR_CODES.TOKEN_EXPIRED]: 401,
6062
+ [AUTH_ERROR_CODES.TOKEN_INVALID]: 401,
6063
+ [AUTH_ERROR_CODES.TOKEN_REVOKED]: 401,
6064
+ [AUTH_ERROR_CODES.SESSION_EXPIRED]: 401,
6065
+ [AUTH_ERROR_CODES.MFA_REQUIRED]: 401,
6066
+ [AUTH_ERROR_CODES.MFA_INVALID]: 401,
6067
+ [AUTH_ERROR_CODES.INSUFFICIENT_PERMISSIONS]: 403,
6068
+ [AUTH_ERROR_CODES.ROLE_REQUIRED]: 403,
6069
+ [AUTH_ERROR_CODES.WALLET_SIGNATURE_INVALID]: 401,
6070
+ [AUTH_ERROR_CODES.NONCE_EXPIRED]: 401,
6071
+ [AUTH_ERROR_CODES.NONCE_ALREADY_USED]: 401,
6072
+ [AUTH_ERROR_CODES.ACCOUNT_LOCKED]: 423,
6073
+ [AUTH_ERROR_CODES.ACCOUNT_SUSPENDED]: 423
6074
+ };
6075
+ var ERROR_CODE_DESCRIPTIONS = {
6076
+ [AUTH_ERROR_CODES.INVALID_CREDENTIALS]: "errors.auth.invalid_credentials",
6077
+ [AUTH_ERROR_CODES.TOKEN_EXPIRED]: "errors.auth.token_expired",
6078
+ [AUTH_ERROR_CODES.TOKEN_INVALID]: "errors.auth.token_invalid",
6079
+ [AUTH_ERROR_CODES.TOKEN_REVOKED]: "errors.auth.token_revoked",
6080
+ [AUTH_ERROR_CODES.SESSION_EXPIRED]: "errors.auth.session_expired",
6081
+ [AUTH_ERROR_CODES.MFA_REQUIRED]: "errors.auth.mfa_required",
6082
+ [AUTH_ERROR_CODES.MFA_INVALID]: "errors.auth.mfa_invalid",
6083
+ [AUTH_ERROR_CODES.INSUFFICIENT_PERMISSIONS]: "errors.auth.insufficient_permissions",
6084
+ [AUTH_ERROR_CODES.ROLE_REQUIRED]: "errors.auth.role_required",
6085
+ [AUTH_ERROR_CODES.WALLET_SIGNATURE_INVALID]: "errors.auth.wallet_signature_invalid",
6086
+ [AUTH_ERROR_CODES.NONCE_EXPIRED]: "errors.auth.nonce_expired",
6087
+ [AUTH_ERROR_CODES.NONCE_ALREADY_USED]: "errors.auth.nonce_already_used",
6088
+ [AUTH_ERROR_CODES.ACCOUNT_LOCKED]: "errors.auth.account_locked",
6089
+ [AUTH_ERROR_CODES.ACCOUNT_SUSPENDED]: "errors.auth.account_suspended"
6090
+ };
6091
+ var OAUTH_PROVIDERS = {
6092
+ /** Google OAuth 2.0 */
6093
+ GOOGLE: "GOOGLE",
6094
+ /** Facebook OAuth 2.0 */
6095
+ FACEBOOK: "FACEBOOK",
6096
+ /** Apple Sign In */
6097
+ APPLE: "APPLE",
6098
+ /** GitHub OAuth 2.0 */
6099
+ GITHUB: "GITHUB",
6100
+ /** Twitter OAuth 2.0 */
6101
+ TWITTER: "TWITTER",
6102
+ /** LinkedIn OAuth 2.0 */
6103
+ LINKEDIN: "LINKEDIN",
6104
+ /** Discord OAuth 2.0 */
6105
+ DISCORD: "DISCORD",
6106
+ /** Microsoft OAuth 2.0 */
6107
+ MICROSOFT: "MICROSOFT"
6108
+ };
6109
+
6110
+ // src/auth/auth-events.ts
6111
+ var AUTH_EVENTS = {
6112
+ /** User successfully authenticated */
6113
+ USER_AUTHENTICATED: "auth.user.authenticated",
6114
+ /** User signed up (new account created) */
6115
+ USER_SIGNED_UP: "auth.user.signed_up",
6116
+ /** User logged out */
6117
+ USER_LOGGED_OUT: "auth.user.logged_out",
6118
+ /** Authentication attempt failed */
6119
+ AUTHENTICATION_FAILED: "auth.authentication.failed",
6120
+ /** Session created */
6121
+ SESSION_CREATED: "auth.session.created",
6122
+ /** Session expired */
6123
+ SESSION_EXPIRED: "auth.session.expired",
6124
+ /** Session refreshed */
6125
+ SESSION_REFRESHED: "auth.session.refreshed",
6126
+ /** Session invalidated (logout) */
6127
+ SESSION_INVALIDATED: "auth.session.invalidated",
6128
+ /** Account linked to user */
6129
+ ACCOUNT_LINKED: "auth.account.linked",
6130
+ /** Account unlinked from user */
6131
+ ACCOUNT_UNLINKED: "auth.account.unlinked",
6132
+ /** Role assigned to user */
6133
+ ROLE_ASSIGNED: "auth.rbac.role_assigned",
6134
+ /** Role revoked from user */
6135
+ ROLE_REVOKED: "auth.rbac.role_revoked",
6136
+ /** Suspicious login attempt detected */
6137
+ SUSPICIOUS_LOGIN_ATTEMPT: "auth.security.suspicious_login",
6138
+ /** Password changed */
6139
+ PASSWORD_CHANGED: "auth.password.changed",
6140
+ /** Password reset requested */
6141
+ PASSWORD_RESET_REQUESTED: "auth.password.reset_requested"
6142
+ };
6019
6143
 
6020
6144
  // src/core/modules.ts
6021
6145
  var BACKEND_RUNTIMES = [
@@ -9048,8 +9172,10 @@ exports.API_ERROR_CODES = API_ERROR_CODES;
9048
9172
  exports.APP_CONTEXTS = APP_CONTEXTS;
9049
9173
  exports.ATHLETE_PROFILE_ERRORS = ATHLETE_PROFILE_ERRORS;
9050
9174
  exports.AUDIT_OPERATION = AUDIT_OPERATION;
9175
+ exports.AUTHPROVIDER = AUTHPROVIDER;
9051
9176
  exports.AUTH_ERROR_CODES = AUTH_ERROR_CODES;
9052
9177
  exports.AUTH_ERROR_DEFINITIONS = AUTH_ERROR_DEFINITIONS;
9178
+ exports.AUTH_EVENTS = AUTH_EVENTS;
9053
9179
  exports.AUTH_PROVIDER = AUTH_PROVIDER;
9054
9180
  exports.AUTH_PROVIDER_TYPE = AUTH_PROVIDER_TYPE;
9055
9181
  exports.ApiEventAction = ApiEventAction;
@@ -9099,6 +9225,8 @@ exports.ENTITY_TYPE = ENTITY_TYPE;
9099
9225
  exports.ERROR_CATEGORY = ERROR_CATEGORY;
9100
9226
  exports.ERROR_CATEGORY_TO_EMITTER_KEY = ERROR_CATEGORY_TO_EMITTER_KEY;
9101
9227
  exports.ERROR_CODES = ERROR_CODES;
9228
+ exports.ERROR_CODE_DESCRIPTIONS = ERROR_CODE_DESCRIPTIONS;
9229
+ exports.ERROR_CODE_TO_HTTP_STATUS = ERROR_CODE_TO_HTTP_STATUS;
9102
9230
  exports.ERROR_DEFINITIONS = ERROR_DEFINITIONS;
9103
9231
  exports.ERROR_EVENTS = ERROR_EVENTS;
9104
9232
  exports.ERROR_EXCEPTIONS_NAMESPACES = ERROR_EXCEPTIONS_NAMESPACES;
@@ -9166,6 +9294,7 @@ exports.MEDIA_ENTITY = MEDIA_ENTITY;
9166
9294
  exports.MEDIA_EXTENSIONS = MEDIA_EXTENSIONS;
9167
9295
  exports.MEDIA_MIME_PREFIXES = MEDIA_MIME_PREFIXES;
9168
9296
  exports.MEDIA_VARIANT_TYPE = MEDIA_VARIANT_TYPE;
9297
+ exports.MFATYPE = MFATYPE;
9169
9298
  exports.MIME_TYPES = MIME_TYPES;
9170
9299
  exports.NETWORK_CONFIDENCE_LEVELS = NETWORK_CONFIDENCE_LEVELS;
9171
9300
  exports.NETWORK_EVENTS = NETWORK_EVENTS;
@@ -9178,6 +9307,7 @@ exports.NOTIFICATION_PROVIDERS = NOTIFICATION_PROVIDERS;
9178
9307
  exports.NetworkPresetNames = NetworkPresetNames;
9179
9308
  exports.NotificationCategorySchema = NotificationCategorySchema;
9180
9309
  exports.NotificationEventAction = NotificationEventAction;
9310
+ exports.OAUTH_PROVIDERS = OAUTH_PROVIDERS;
9181
9311
  exports.OBSERVABILITY_METRICS = OBSERVABILITY_METRICS;
9182
9312
  exports.OBSERVABILITY_SPANS = OBSERVABILITY_SPANS;
9183
9313
  exports.ONBOARD_LINK_TYPE = ONBOARD_LINK_TYPE;
@@ -9202,6 +9332,7 @@ exports.PERFORMANCE_EVENTS = PERFORMANCE_EVENTS;
9202
9332
  exports.PERFORMANCE_METRIC_TYPE = PERFORMANCE_METRIC_TYPE;
9203
9333
  exports.PRIORITY_LEVEL = PRIORITY_LEVEL;
9204
9334
  exports.PRODUCT_TYPE = PRODUCT_TYPE;
9335
+ exports.PROVIDERTYPE = PROVIDERTYPE;
9205
9336
  exports.PROVIDER_PRODUCT_STATUS = PROVIDER_PRODUCT_STATUS;
9206
9337
  exports.PUB_SUB_EVENT = PUB_SUB_EVENT;
9207
9338
  exports.PhoneSchema = PhoneSchema;
@@ -9223,6 +9354,7 @@ exports.ROUTING_STRATEGY = ROUTING_STRATEGY;
9223
9354
  exports.RTT_THRESHOLDS = RTT_THRESHOLDS;
9224
9355
  exports.SECURITY_THREAT_TYPE = SECURITY_THREAT_TYPE;
9225
9356
  exports.SERVICE_KEYS = SERVICE_KEYS;
9357
+ exports.SESSIONSTATUS = SESSIONSTATUS;
9226
9358
  exports.SIGNATURE_METHOD = SIGNATURE_METHOD;
9227
9359
  exports.SORT_DIRECTION = SORT_DIRECTION;
9228
9360
  exports.SPEED_THRESHOLDS = SPEED_THRESHOLDS;
@@ -9263,6 +9395,7 @@ exports.TEMPLATE_DOCUMENT_TYPE_SCHEMA = TEMPLATE_DOCUMENT_TYPE_SCHEMA;
9263
9395
  exports.TEMPLATE_OUTPUT_FORMAT = TEMPLATE_OUTPUT_FORMAT;
9264
9396
  exports.TEMPLATE_VARIABLE_TYPE = TEMPLATE_VARIABLE_TYPE;
9265
9397
  exports.TEMPLATE_VARIABLE_TYPE_SCHEMA = TEMPLATE_VARIABLE_TYPE_SCHEMA;
9398
+ exports.TOKENTYPE = TOKENTYPE;
9266
9399
  exports.TOKEN_TYPE = TOKEN_TYPE;
9267
9400
  exports.TRACKING_PHASES = TRACKING_PHASES;
9268
9401
  exports.TRANSACTION_TYPE = TRANSACTION_TYPE;
@@ -9279,6 +9412,7 @@ exports.UNIFIED_OPERATIONS = UNIFIED_OPERATIONS;
9279
9412
  exports.UNIVERSAL_RUNTIMES = UNIVERSAL_RUNTIMES;
9280
9413
  exports.UPDATE_STRATEGIES = UPDATE_STRATEGIES;
9281
9414
  exports.UPLOAD_STATUS = UPLOAD_STATUS;
9415
+ exports.USERROLESTATUS = USERROLESTATUS;
9282
9416
  exports.USER_ROLE = USER_ROLE;
9283
9417
  exports.USER_ROLE_STATUS = USER_ROLE_STATUS;
9284
9418
  exports.USER_STATUS = USER_STATUS;