@guinetik/primitives-ts 0.2.0 → 0.2.1

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/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
@@ -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 = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guinetik/primitives-ts",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Shared TypeScript primitives for Guinetik projects",
5
5
  "author": "Guinetik",
6
6
  "license": "MIT",