@guinetik/primitives-ts 0.2.0 → 0.2.2
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/dist/auth.types.d.ts +17 -0
- package/dist/auth.types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/security.interface.d.ts +145 -0
- package/dist/security.interface.d.ts.map +1 -0
- package/dist/security.interface.js +33 -0
- package/package.json +1 -1
package/dist/auth.types.d.ts
CHANGED
|
@@ -6,6 +6,21 @@
|
|
|
6
6
|
* Authentication provider types
|
|
7
7
|
*/
|
|
8
8
|
export type AuthProvider = 'email' | 'google';
|
|
9
|
+
/**
|
|
10
|
+
* Provider-specific user information
|
|
11
|
+
*/
|
|
12
|
+
export interface UserProvider {
|
|
13
|
+
/** Provider identifier (e.g., 'password', 'google.com') */
|
|
14
|
+
providerId: string;
|
|
15
|
+
/** User ID from this provider */
|
|
16
|
+
uid: string;
|
|
17
|
+
/** Display name from this provider */
|
|
18
|
+
displayName?: string;
|
|
19
|
+
/** Email from this provider */
|
|
20
|
+
email?: string;
|
|
21
|
+
/** Photo URL from this provider */
|
|
22
|
+
photoURL?: string;
|
|
23
|
+
}
|
|
9
24
|
/**
|
|
10
25
|
* User information
|
|
11
26
|
*/
|
|
@@ -20,6 +35,8 @@ export interface User {
|
|
|
20
35
|
emailVerified?: boolean;
|
|
21
36
|
/** URL to user's profile photo */
|
|
22
37
|
photoURL?: string;
|
|
38
|
+
/** List of providers linked to this account */
|
|
39
|
+
providerData?: UserProvider[];
|
|
23
40
|
}
|
|
24
41
|
/**
|
|
25
42
|
* Authentication response after successful login
|
package/dist/auth.types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.types.d.ts","sourceRoot":"","sources":["../src/auth.types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,MAAM,YAA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,IAAI,EAAE,IAAI,CAAC;IAEX,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,wBAAwB;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,8BAA8B;IAC9B,QAAQ,EAAE,YAAY,CAAC;IAEvB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,4 +13,6 @@ export * from './website.types';
|
|
|
13
13
|
export * from './firestore.types';
|
|
14
14
|
export * from './website-firestore.types';
|
|
15
15
|
export * from './totp.types';
|
|
16
|
+
export type { Security, SecurityChallengeOptions, SecurityChallengeResult } from './security.interface';
|
|
17
|
+
export { SecurityLevel } from './security.interface';
|
|
16
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,cAAc,cAAc,CAAC;AAG7B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,2BAA2B,CAAC;AAG1C,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,cAAc,cAAc,CAAC;AAG7B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,2BAA2B,CAAC;AAG1C,cAAc,cAAc,CAAC;AAG7B,YAAY,EAAE,QAAQ,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACxG,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
23
23
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.SecurityLevel = void 0;
|
|
26
27
|
// Auth types
|
|
27
28
|
__exportStar(require("./auth.types"), exports);
|
|
28
29
|
// System monitoring types
|
|
@@ -35,3 +36,5 @@ __exportStar(require("./firestore.types"), exports);
|
|
|
35
36
|
__exportStar(require("./website-firestore.types"), exports);
|
|
36
37
|
// TOTP/2FA types
|
|
37
38
|
__exportStar(require("./totp.types"), exports);
|
|
39
|
+
var security_interface_1 = require("./security.interface");
|
|
40
|
+
Object.defineProperty(exports, "SecurityLevel", { enumerable: true, get: function () { return security_interface_1.SecurityLevel; } });
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Clearance Levels
|
|
3
|
+
*
|
|
4
|
+
* Hierarchical security levels similar to log levels.
|
|
5
|
+
* Higher numbers = stronger security requirements.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* - Sensitive operations specify minimum required level
|
|
9
|
+
* - System selects appropriate challenge based on user's available methods
|
|
10
|
+
* - User must have a method at or above the required level
|
|
11
|
+
*
|
|
12
|
+
* Example:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Shell execution requires at least 2FA
|
|
15
|
+
* const executeCommand = withSecurityChallenge(fn, {
|
|
16
|
+
* minLevel: SecurityLevel.TWO_FACTOR
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare enum SecurityLevel {
|
|
21
|
+
/** Password confirmation - baseline, everyone has this */
|
|
22
|
+
PASSWORD = 1,
|
|
23
|
+
/** Two-factor authentication - authenticator app codes */
|
|
24
|
+
TWO_FACTOR = 2,
|
|
25
|
+
/** Biometric verification - fingerprint, face ID, etc. */
|
|
26
|
+
BIOMETRIC = 3,
|
|
27
|
+
/** Hardware security key - YubiKey, etc. */
|
|
28
|
+
HARDWARE_KEY = 4
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Security Challenge Options
|
|
32
|
+
*
|
|
33
|
+
* Configuration for security challenge dialogs and verification flows
|
|
34
|
+
*/
|
|
35
|
+
export interface SecurityChallengeOptions {
|
|
36
|
+
/** Minimum security level required (defaults to PASSWORD) */
|
|
37
|
+
minLevel?: SecurityLevel;
|
|
38
|
+
/** Title shown in the challenge dialog */
|
|
39
|
+
title?: string;
|
|
40
|
+
/** Description/reason for the security challenge */
|
|
41
|
+
message?: string;
|
|
42
|
+
/** Additional context passed to the implementation */
|
|
43
|
+
context?: Record<string, any>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Security - Abstract Security Challenge Interface
|
|
47
|
+
*
|
|
48
|
+
* Base interface for all security challenge implementations (2FA, biometric, SMS, etc.).
|
|
49
|
+
* Each implementation handles its own UI (dialog) and verification logic.
|
|
50
|
+
*
|
|
51
|
+
* Design Pattern: Strategy Pattern
|
|
52
|
+
* - Different security methods implement this interface
|
|
53
|
+
* - Each strategy encapsulates its own verification logic
|
|
54
|
+
* - Consumers don't need to know the implementation details
|
|
55
|
+
*
|
|
56
|
+
* Example Implementations:
|
|
57
|
+
* - Security2FactorChallenge (TOTP/authenticator apps)
|
|
58
|
+
* - SecurityBiometricChallenge (fingerprint/face ID)
|
|
59
|
+
* - SecuritySmsChallenge (SMS verification codes)
|
|
60
|
+
* - SecurityEmailChallenge (email verification codes)
|
|
61
|
+
*
|
|
62
|
+
* Usage:
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const twoFactorSecurity = new Security2FactorChallenge();
|
|
65
|
+
* const verified = await twoFactorSecurity.challenge(userId, {
|
|
66
|
+
* title: 'Delete Account',
|
|
67
|
+
* message: 'This action cannot be undone'
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* if (verified) {
|
|
71
|
+
* // Proceed with sensitive operation
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export interface Security {
|
|
76
|
+
/**
|
|
77
|
+
* Initiates a security challenge for the user
|
|
78
|
+
*
|
|
79
|
+
* Shows the appropriate UI (dialog, prompt, biometric scanner, etc.)
|
|
80
|
+
* and waits for the user to complete the challenge.
|
|
81
|
+
*
|
|
82
|
+
* The promise resolves to:
|
|
83
|
+
* - `true` if the challenge succeeds (user verified)
|
|
84
|
+
* - `false` if the challenge fails or is cancelled
|
|
85
|
+
*
|
|
86
|
+
* Implementation Note:
|
|
87
|
+
* Each concrete implementation should:
|
|
88
|
+
* 1. Show its own UI (dialog, modal, native prompt, etc.)
|
|
89
|
+
* 2. Wait for user input/interaction
|
|
90
|
+
* 3. Verify the credentials/input
|
|
91
|
+
* 4. Resolve the promise based on verification result
|
|
92
|
+
*
|
|
93
|
+
* @param uid - User ID to verify against
|
|
94
|
+
* @param options - Challenge customization options
|
|
95
|
+
* @returns Promise resolving to true if verified, false otherwise
|
|
96
|
+
*/
|
|
97
|
+
challenge(uid: string, options?: SecurityChallengeOptions): Promise<boolean>;
|
|
98
|
+
/**
|
|
99
|
+
* Gets the type identifier for this security implementation
|
|
100
|
+
*
|
|
101
|
+
* Used by the SecurityService registry to identify and retrieve
|
|
102
|
+
* the correct implementation.
|
|
103
|
+
*
|
|
104
|
+
* Examples: '2fa', 'biometric', 'password', 'hardware-key'
|
|
105
|
+
*
|
|
106
|
+
* @returns Unique identifier for this security type
|
|
107
|
+
*/
|
|
108
|
+
getType(): string;
|
|
109
|
+
/**
|
|
110
|
+
* Gets the security level of this implementation
|
|
111
|
+
*
|
|
112
|
+
* Used by SecurityService to determine if this method meets
|
|
113
|
+
* the minimum required security level for an operation.
|
|
114
|
+
*
|
|
115
|
+
* @returns SecurityLevel enum value
|
|
116
|
+
*/
|
|
117
|
+
getLevel(): SecurityLevel;
|
|
118
|
+
/**
|
|
119
|
+
* Checks if this security method is available for the user
|
|
120
|
+
*
|
|
121
|
+
* Some security methods may not be available depending on:
|
|
122
|
+
* - User hasn't enrolled (e.g., no 2FA setup)
|
|
123
|
+
* - Device capabilities (e.g., no biometric sensor)
|
|
124
|
+
* - Browser support (e.g., WebAuthn not supported)
|
|
125
|
+
*
|
|
126
|
+
* @param uid - User ID to check availability for
|
|
127
|
+
* @returns Promise resolving to true if available, false otherwise
|
|
128
|
+
*/
|
|
129
|
+
isAvailable(uid: string): Promise<boolean>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Security Challenge Result
|
|
133
|
+
*
|
|
134
|
+
* Extended result object that implementations can optionally return
|
|
135
|
+
* with additional metadata about the challenge
|
|
136
|
+
*/
|
|
137
|
+
export interface SecurityChallengeResult {
|
|
138
|
+
/** Whether the challenge succeeded */
|
|
139
|
+
verified: boolean;
|
|
140
|
+
/** Optional error message if verification failed */
|
|
141
|
+
error?: string;
|
|
142
|
+
/** Optional metadata (e.g., biometric sensor used, code expiry time) */
|
|
143
|
+
metadata?: Record<string, any>;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=security.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.interface.d.ts","sourceRoot":"","sources":["../src/security.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,oBAAY,aAAa;IACvB,0DAA0D;IAC1D,QAAQ,IAAI;IAEZ,0DAA0D;IAC1D,UAAU,IAAI;IAEd,0DAA0D;IAC1D,SAAS,IAAI;IAEb,4CAA4C;IAC5C,YAAY,IAAI;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7E;;;;;;;;;OASG;IACH,OAAO,IAAI,MAAM,CAAC;IAElB;;;;;;;OAOG;IACH,QAAQ,IAAI,aAAa,CAAC;IAE1B;;;;;;;;;;OAUG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5C;AAED;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACtC,sCAAsC;IACtC,QAAQ,EAAE,OAAO,CAAC;IAClB,oDAAoD;IACpD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SecurityLevel = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Security Clearance Levels
|
|
6
|
+
*
|
|
7
|
+
* Hierarchical security levels similar to log levels.
|
|
8
|
+
* Higher numbers = stronger security requirements.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* - Sensitive operations specify minimum required level
|
|
12
|
+
* - System selects appropriate challenge based on user's available methods
|
|
13
|
+
* - User must have a method at or above the required level
|
|
14
|
+
*
|
|
15
|
+
* Example:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Shell execution requires at least 2FA
|
|
18
|
+
* const executeCommand = withSecurityChallenge(fn, {
|
|
19
|
+
* minLevel: SecurityLevel.TWO_FACTOR
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
var SecurityLevel;
|
|
24
|
+
(function (SecurityLevel) {
|
|
25
|
+
/** Password confirmation - baseline, everyone has this */
|
|
26
|
+
SecurityLevel[SecurityLevel["PASSWORD"] = 1] = "PASSWORD";
|
|
27
|
+
/** Two-factor authentication - authenticator app codes */
|
|
28
|
+
SecurityLevel[SecurityLevel["TWO_FACTOR"] = 2] = "TWO_FACTOR";
|
|
29
|
+
/** Biometric verification - fingerprint, face ID, etc. */
|
|
30
|
+
SecurityLevel[SecurityLevel["BIOMETRIC"] = 3] = "BIOMETRIC";
|
|
31
|
+
/** Hardware security key - YubiKey, etc. */
|
|
32
|
+
SecurityLevel[SecurityLevel["HARDWARE_KEY"] = 4] = "HARDWARE_KEY";
|
|
33
|
+
})(SecurityLevel || (exports.SecurityLevel = SecurityLevel = {}));
|