helix-lang 11.0.0
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/README.md +168 -0
- package/dist/architect.d.ts +14 -0
- package/dist/architect.d.ts.map +1 -0
- package/dist/architect.js +127 -0
- package/dist/architect.js.map +1 -0
- package/dist/bin/helix.d.ts +20 -0
- package/dist/bin/helix.d.ts.map +1 -0
- package/dist/bin/helix.js +921 -0
- package/dist/bin/helix.js.map +1 -0
- package/dist/commands/collaborate/index.d.ts +2 -0
- package/dist/commands/collaborate/index.d.ts.map +1 -0
- package/dist/commands/collaborate/index.js +129 -0
- package/dist/commands/collaborate/index.js.map +1 -0
- package/dist/commands/collaborate/server.d.ts +31 -0
- package/dist/commands/collaborate/server.d.ts.map +1 -0
- package/dist/commands/collaborate/server.js +159 -0
- package/dist/commands/collaborate/server.js.map +1 -0
- package/dist/commands/deploy/index.d.ts +25 -0
- package/dist/commands/deploy/index.d.ts.map +1 -0
- package/dist/commands/deploy/index.js +130 -0
- package/dist/commands/deploy/index.js.map +1 -0
- package/dist/commands/deploy/platforms/fly.d.ts +9 -0
- package/dist/commands/deploy/platforms/fly.d.ts.map +1 -0
- package/dist/commands/deploy/platforms/fly.js +68 -0
- package/dist/commands/deploy/platforms/fly.js.map +1 -0
- package/dist/commands/deploy/platforms/railway.d.ts +9 -0
- package/dist/commands/deploy/platforms/railway.d.ts.map +1 -0
- package/dist/commands/deploy/platforms/railway.js +115 -0
- package/dist/commands/deploy/platforms/railway.js.map +1 -0
- package/dist/commands/deploy/platforms/vercel.d.ts +10 -0
- package/dist/commands/deploy/platforms/vercel.d.ts.map +1 -0
- package/dist/commands/deploy/platforms/vercel.js +126 -0
- package/dist/commands/deploy/platforms/vercel.js.map +1 -0
- package/dist/commands/deploy.d.ts +6 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +56 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/evolve/analyzers/performance.d.ts +13 -0
- package/dist/commands/evolve/analyzers/performance.d.ts.map +1 -0
- package/dist/commands/evolve/analyzers/performance.js +591 -0
- package/dist/commands/evolve/analyzers/performance.js.map +1 -0
- package/dist/commands/evolve/analyzers/security.d.ts +21 -0
- package/dist/commands/evolve/analyzers/security.d.ts.map +1 -0
- package/dist/commands/evolve/analyzers/security.js +280 -0
- package/dist/commands/evolve/analyzers/security.js.map +1 -0
- package/dist/commands/evolve/index.d.ts +2 -0
- package/dist/commands/evolve/index.d.ts.map +1 -0
- package/dist/commands/evolve/index.js +122 -0
- package/dist/commands/evolve/index.js.map +1 -0
- package/dist/commands/generate.d.ts +6 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +277 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/install.d.ts +2 -0
- package/dist/commands/install.d.ts.map +1 -0
- package/dist/commands/install.js +176 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/library/index.d.ts +27 -0
- package/dist/commands/library/index.d.ts.map +1 -0
- package/dist/commands/library/index.js +126 -0
- package/dist/commands/library/index.js.map +1 -0
- package/dist/commands/migrate.d.ts +5 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +258 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/new.d.ts +6 -0
- package/dist/commands/new.d.ts.map +1 -0
- package/dist/commands/new.js +195 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/preflight.d.ts +20 -0
- package/dist/commands/preflight.d.ts.map +1 -0
- package/dist/commands/preflight.js +182 -0
- package/dist/commands/preflight.js.map +1 -0
- package/dist/commands/preview.d.ts +13 -0
- package/dist/commands/preview.d.ts.map +1 -0
- package/dist/commands/preview.js +260 -0
- package/dist/commands/preview.js.map +1 -0
- package/dist/commands/run.d.ts +6 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +96 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/spawn.d.ts +11 -0
- package/dist/commands/spawn.d.ts.map +1 -0
- package/dist/commands/spawn.js +916 -0
- package/dist/commands/spawn.js.map +1 -0
- package/dist/compiler.d.ts +12 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +92 -0
- package/dist/compiler.js.map +1 -0
- package/dist/core/file-writer.d.ts +36 -0
- package/dist/core/file-writer.d.ts.map +1 -0
- package/dist/core/file-writer.js +268 -0
- package/dist/core/file-writer.js.map +1 -0
- package/dist/core/registry.d.ts +57 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +222 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/self-healing.d.ts +47 -0
- package/dist/core/self-healing.d.ts.map +1 -0
- package/dist/core/self-healing.js +250 -0
- package/dist/core/self-healing.js.map +1 -0
- package/dist/core/types.d.ts +126 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +7 -0
- package/dist/core/types.js.map +1 -0
- package/dist/generators/databases/mongodb.d.ts +10 -0
- package/dist/generators/databases/mongodb.d.ts.map +1 -0
- package/dist/generators/databases/mongodb.js +83 -0
- package/dist/generators/databases/mongodb.js.map +1 -0
- package/dist/generators/databases/redis.d.ts +2 -0
- package/dist/generators/databases/redis.d.ts.map +1 -0
- package/dist/generators/databases/redis.js +140 -0
- package/dist/generators/databases/redis.js.map +1 -0
- package/dist/generators/flutter.d.ts +32 -0
- package/dist/generators/flutter.d.ts.map +1 -0
- package/dist/generators/flutter.js +628 -0
- package/dist/generators/flutter.js.map +1 -0
- package/dist/openrouter.d.ts +68 -0
- package/dist/openrouter.d.ts.map +1 -0
- package/dist/openrouter.js +241 -0
- package/dist/openrouter.js.map +1 -0
- package/dist/page-generator.d.ts +22 -0
- package/dist/page-generator.d.ts.map +1 -0
- package/dist/page-generator.js +192 -0
- package/dist/page-generator.js.map +1 -0
- package/dist/parser.d.ts +76 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +691 -0
- package/dist/parser.js.map +1 -0
- package/dist/prompts/master-architect.d.ts +9 -0
- package/dist/prompts/master-architect.d.ts.map +1 -0
- package/dist/prompts/master-architect.js +150 -0
- package/dist/prompts/master-architect.js.map +1 -0
- package/dist/researcher.d.ts +12 -0
- package/dist/researcher.d.ts.map +1 -0
- package/dist/researcher.js +85 -0
- package/dist/researcher.js.map +1 -0
- package/dist/self-heal.d.ts +29 -0
- package/dist/self-heal.d.ts.map +1 -0
- package/dist/self-heal.js +260 -0
- package/dist/self-heal.js.map +1 -0
- package/dist/services/SupabaseDeployer.d.ts +9 -0
- package/dist/services/SupabaseDeployer.d.ts.map +1 -0
- package/dist/services/SupabaseDeployer.js +50 -0
- package/dist/services/SupabaseDeployer.js.map +1 -0
- package/dist/test-generator.d.ts +18 -0
- package/dist/test-generator.d.ts.map +1 -0
- package/dist/test-generator.js +180 -0
- package/dist/test-generator.js.map +1 -0
- package/dist/themes/index.d.ts +52 -0
- package/dist/themes/index.d.ts.map +1 -0
- package/dist/themes/index.js +273 -0
- package/dist/themes/index.js.map +1 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +81 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/constitutional-validator.d.ts +73 -0
- package/dist/utils/constitutional-validator.d.ts.map +1 -0
- package/dist/utils/constitutional-validator.js +249 -0
- package/dist/utils/constitutional-validator.js.map +1 -0
- package/library/auth-flow/app/api/auth/[...nextauth]/route.ts +31 -0
- package/library/auth-flow/app/api/auth/login/route.ts +90 -0
- package/library/auth-flow/app/api/auth/register/route.ts +91 -0
- package/library/auth-flow/components/auth/AuthMiddleware.tsx +139 -0
- package/library/auth-flow/components/auth/LoginForm.tsx +125 -0
- package/library/auth-flow/components/auth/RegisterForm.tsx +168 -0
- package/library/auth-flow/components/auth/nextauth-config.ts +99 -0
- package/library/auth-flow/manifest.json +29 -0
- package/library/auth-flow/schema.prisma +45 -0
- package/library/dashboard-analytics/components/dashboard/ActivityFeed.tsx +109 -0
- package/library/dashboard-analytics/components/dashboard/LineChart.tsx +180 -0
- package/library/dashboard-analytics/components/dashboard/StatsCard.tsx +47 -0
- package/library/dashboard-analytics/components/dashboard/SummaryGrid.tsx +39 -0
- package/library/dashboard-analytics/manifest.json +19 -0
- package/library/data-table/components/table/BulkActions.tsx +59 -0
- package/library/data-table/components/table/ColumnToggle.tsx +65 -0
- package/library/data-table/components/table/DataTable.tsx +318 -0
- package/library/data-table/components/table/ExportCSV.tsx +52 -0
- package/library/data-table/components/table/SearchFilter.tsx +48 -0
- package/library/data-table/manifest.json +20 -0
- package/library/file-upload/app/api/upload/route.ts +107 -0
- package/library/file-upload/components/upload/DropZone.tsx +268 -0
- package/library/file-upload/components/upload/FilePreview.tsx +82 -0
- package/library/file-upload/components/upload/UploadProgress.tsx +92 -0
- package/library/file-upload/components/upload/fileStorage.ts +142 -0
- package/library/file-upload/manifest.json +21 -0
- package/library/notification-system/app/api/notifications/route.ts +121 -0
- package/library/notification-system/components/notifications/NotificationBell.tsx +154 -0
- package/library/notification-system/components/notifications/NotificationProvider.tsx +161 -0
- package/library/notification-system/components/notifications/Toast.tsx +112 -0
- package/library/notification-system/manifest.json +20 -0
- package/package.json +66 -0
package/dist/types.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Helix Language - Type Definitions and System Prompts
|
|
4
|
+
* v11.0 - With Deep Research Capabilities
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.COMPILER_SYSTEM_PROMPT = exports.ARCHITECT_SYSTEM_PROMPT = exports.RESEARCHER_SYSTEM_PROMPT = exports.HELIX_SYNTAX_GUIDE = void 0;
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// HELIX SYNTAX GUIDE
|
|
10
|
+
// ============================================================================
|
|
11
|
+
exports.HELIX_SYNTAX_GUIDE = `
|
|
12
|
+
HELIX SYNTAX RULES:
|
|
13
|
+
1. 'strand Name {}' defines a stateful entity.
|
|
14
|
+
2. 'field name: Type' defines data structure. Types: String, Int, Float, Boolean, DateTime.
|
|
15
|
+
3. 'relation name: OtherStrand' defines a belongs-to relationship (foreign key).
|
|
16
|
+
4. 'relation name: OtherStrand[]' defines a has-many relationship.
|
|
17
|
+
5. 'strategy Name: Action -> Fallback' defines error handling.
|
|
18
|
+
6. 'view Name {}' defines UI layout.
|
|
19
|
+
7. 'theme: ThemeName' in a view selects the visual theme.
|
|
20
|
+
Available themes: Glassmorphism (default), Professional, Minimal, Vibrant.
|
|
21
|
+
Example: theme: Professional
|
|
22
|
+
|
|
23
|
+
EXAMPLE:
|
|
24
|
+
strand Customer {
|
|
25
|
+
field name: String
|
|
26
|
+
field email: String
|
|
27
|
+
relation orders: Order[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
strand Order {
|
|
31
|
+
field total: Float
|
|
32
|
+
field status: String
|
|
33
|
+
relation customer: Customer
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
view OrderBoard {
|
|
37
|
+
list: Order.all()
|
|
38
|
+
theme: Professional
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
// ============================================================================
|
|
42
|
+
// RESEARCHER SYSTEM PROMPT
|
|
43
|
+
// ============================================================================
|
|
44
|
+
exports.RESEARCHER_SYSTEM_PROMPT = `
|
|
45
|
+
You are the Helix Lead Researcher.
|
|
46
|
+
Goal: Analyze the requested domain deeply.
|
|
47
|
+
Output: A structured Markdown report containing:
|
|
48
|
+
- Key Data Entities & Fields (e.g., specific schemas).
|
|
49
|
+
- Critical Features (e.g., standard industry requirements).
|
|
50
|
+
- "Gotchas" & Constraints (e.g., specific regulatory or physical limits).
|
|
51
|
+
- User Interface trends for this domain.
|
|
52
|
+
DO NOT write code. Write a System Analysis Report.
|
|
53
|
+
`;
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// ARCHITECT SYSTEM PROMPT
|
|
56
|
+
// ============================================================================
|
|
57
|
+
exports.ARCHITECT_SYSTEM_PROMPT = `
|
|
58
|
+
You are the Helix Architect.
|
|
59
|
+
Goal: Convert vague user requests into valid 'Helix' syntax blueprints.
|
|
60
|
+
Output: ONLY the .helix code. No markdown fences.
|
|
61
|
+
|
|
62
|
+
When Context is provided:
|
|
63
|
+
- Use the research to inform the fields and logic of the Helix Blueprint.
|
|
64
|
+
- If the research mentions specific constraints (e.g., service intervals, regulatory limits), include them in the 'strand'.
|
|
65
|
+
- Reference specific data models and entities from the research.
|
|
66
|
+
|
|
67
|
+
${exports.HELIX_SYNTAX_GUIDE}
|
|
68
|
+
`;
|
|
69
|
+
// ============================================================================
|
|
70
|
+
// COMPILER SYSTEM PROMPT
|
|
71
|
+
// ============================================================================
|
|
72
|
+
exports.COMPILER_SYSTEM_PROMPT = `
|
|
73
|
+
You are the Helix Compiler.
|
|
74
|
+
Goal: Transpile 'Helix' blueprints into a single React (Next.js) + TypeScript + Tailwind file.
|
|
75
|
+
Rules:
|
|
76
|
+
- Implement 'strand' as React Hooks (swr/tanstack).
|
|
77
|
+
- Implement 'strategy' as explicit try/catch/retry logic.
|
|
78
|
+
- Implement 'view' as Tailwind JSX.
|
|
79
|
+
Output: ONLY the .tsx code. No markdown fences.
|
|
80
|
+
`;
|
|
81
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAElE,QAAA,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BjC,CAAC;AAEF,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAElE,QAAA,wBAAwB,GAAG;;;;;;;;;CASvC,CAAC;AAEF,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAElE,QAAA,uBAAuB,GAAG;;;;;;;;;;EAUrC,0BAAkB;CACnB,CAAC;AAEF,+EAA+E;AAC/E,yBAAyB;AACzB,+EAA+E;AAElE,QAAA,sBAAsB,GAAG;;;;;;;;CAQrC,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constitutional Helix - Validation & Compliance System
|
|
3
|
+
* Enforces UI Constitution (Deep Void) and AI Constitution (AI-First Agent)
|
|
4
|
+
*/
|
|
5
|
+
export declare const UI_CONSTITUTION: {
|
|
6
|
+
readonly background: {
|
|
7
|
+
readonly gradient: readonly ["#0f0c29", "#000000"];
|
|
8
|
+
readonly law: "All core views must use Deep Void gradient";
|
|
9
|
+
};
|
|
10
|
+
readonly glassmorphism: {
|
|
11
|
+
readonly blur: "16px";
|
|
12
|
+
readonly transparency: "rgba(255, 255, 255, 0.1)";
|
|
13
|
+
readonly border: "rgba(255, 255, 255, 0.2)";
|
|
14
|
+
readonly law: "All cards use glass blur with 10% white fill, 20% white border";
|
|
15
|
+
};
|
|
16
|
+
readonly accent: {
|
|
17
|
+
readonly helixGold: "#FFD700";
|
|
18
|
+
readonly law: "Reserved for high-action elements only (CTAs, FABs)";
|
|
19
|
+
};
|
|
20
|
+
readonly spacing: {
|
|
21
|
+
readonly grid: readonly [8, 16, 24];
|
|
22
|
+
readonly law: "Strict 8px/16px/24px spacing system";
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare const AI_CONSTITUTION: {
|
|
26
|
+
readonly contextAwareness: {
|
|
27
|
+
readonly requirement: "Redis caching for user context memory";
|
|
28
|
+
readonly law: "AI must remember past interactions";
|
|
29
|
+
};
|
|
30
|
+
readonly proactiveIntelligence: {
|
|
31
|
+
readonly requirement: "One predictive feature per app";
|
|
32
|
+
readonly example: "Predict maintenance based on usage patterns";
|
|
33
|
+
readonly law: "Every app must be proactive, not just reactive";
|
|
34
|
+
};
|
|
35
|
+
readonly safetyHealth: {
|
|
36
|
+
readonly requirement: "Helix Evolve pre-scan before generation";
|
|
37
|
+
readonly law: "Prevent N+1 queries and inefficient renders at birth";
|
|
38
|
+
};
|
|
39
|
+
readonly naturalInterface: {
|
|
40
|
+
readonly preference: "Chat/voice over complex menus";
|
|
41
|
+
readonly law: "Favor conversational interfaces";
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export interface ConstitutionalViolation {
|
|
45
|
+
type: 'ui' | 'ai';
|
|
46
|
+
severity: 'low' | 'medium' | 'high';
|
|
47
|
+
law: string;
|
|
48
|
+
message: string;
|
|
49
|
+
suggestion: string;
|
|
50
|
+
autoFixable: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface ConstitutionalReport {
|
|
53
|
+
compliant: boolean;
|
|
54
|
+
score: number;
|
|
55
|
+
violations: ConstitutionalViolation[];
|
|
56
|
+
warnings: string[];
|
|
57
|
+
}
|
|
58
|
+
export interface SpawnOptions {
|
|
59
|
+
target?: 'web' | 'flutter';
|
|
60
|
+
db?: string;
|
|
61
|
+
theme?: string;
|
|
62
|
+
aiContext?: boolean;
|
|
63
|
+
cache?: boolean;
|
|
64
|
+
noConstitution?: boolean;
|
|
65
|
+
components?: string[];
|
|
66
|
+
}
|
|
67
|
+
export declare function validateUIConstitution(prompt: string, options: SpawnOptions): ConstitutionalViolation[];
|
|
68
|
+
export declare function validateAIConstitution(prompt: string, options: SpawnOptions): ConstitutionalViolation[];
|
|
69
|
+
export declare function validateConstitution(prompt: string, options: SpawnOptions): ConstitutionalReport;
|
|
70
|
+
export declare function autoCorrectOptions(options: SpawnOptions, violations: ConstitutionalViolation[]): SpawnOptions;
|
|
71
|
+
export declare function printConstitutionalReport(report: ConstitutionalReport): void;
|
|
72
|
+
export declare function enhancePromptWithConstitution(prompt: string): string;
|
|
73
|
+
//# sourceMappingURL=constitutional-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constitutional-validator.d.ts","sourceRoot":"","sources":["../../src/utils/constitutional-validator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,eAAO,MAAM,eAAe;;;;;;;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E,oBAAoB,GAAG,IAAI,CAmC5E;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAiBpE"}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Constitutional Helix - Validation & Compliance System
|
|
4
|
+
* Enforces UI Constitution (Deep Void) and AI Constitution (AI-First Agent)
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.AI_CONSTITUTION = exports.UI_CONSTITUTION = void 0;
|
|
11
|
+
exports.validateUIConstitution = validateUIConstitution;
|
|
12
|
+
exports.validateAIConstitution = validateAIConstitution;
|
|
13
|
+
exports.validateConstitution = validateConstitution;
|
|
14
|
+
exports.autoCorrectOptions = autoCorrectOptions;
|
|
15
|
+
exports.printConstitutionalReport = printConstitutionalReport;
|
|
16
|
+
exports.enhancePromptWithConstitution = enhancePromptWithConstitution;
|
|
17
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
// ============================================
|
|
19
|
+
// CONSTITUTIONAL DEFINITIONS
|
|
20
|
+
// ============================================
|
|
21
|
+
exports.UI_CONSTITUTION = {
|
|
22
|
+
background: {
|
|
23
|
+
gradient: ['#0f0c29', '#000000'],
|
|
24
|
+
law: 'All core views must use Deep Void gradient',
|
|
25
|
+
},
|
|
26
|
+
glassmorphism: {
|
|
27
|
+
blur: '16px',
|
|
28
|
+
transparency: 'rgba(255, 255, 255, 0.1)',
|
|
29
|
+
border: 'rgba(255, 255, 255, 0.2)',
|
|
30
|
+
law: 'All cards use glass blur with 10% white fill, 20% white border',
|
|
31
|
+
},
|
|
32
|
+
accent: {
|
|
33
|
+
helixGold: '#FFD700',
|
|
34
|
+
law: 'Reserved for high-action elements only (CTAs, FABs)',
|
|
35
|
+
},
|
|
36
|
+
spacing: {
|
|
37
|
+
grid: [8, 16, 24],
|
|
38
|
+
law: 'Strict 8px/16px/24px spacing system',
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
exports.AI_CONSTITUTION = {
|
|
42
|
+
contextAwareness: {
|
|
43
|
+
requirement: 'Redis caching for user context memory',
|
|
44
|
+
law: 'AI must remember past interactions',
|
|
45
|
+
},
|
|
46
|
+
proactiveIntelligence: {
|
|
47
|
+
requirement: 'One predictive feature per app',
|
|
48
|
+
example: 'Predict maintenance based on usage patterns',
|
|
49
|
+
law: 'Every app must be proactive, not just reactive',
|
|
50
|
+
},
|
|
51
|
+
safetyHealth: {
|
|
52
|
+
requirement: 'Helix Evolve pre-scan before generation',
|
|
53
|
+
law: 'Prevent N+1 queries and inefficient renders at birth',
|
|
54
|
+
},
|
|
55
|
+
naturalInterface: {
|
|
56
|
+
preference: 'Chat/voice over complex menus',
|
|
57
|
+
law: 'Favor conversational interfaces',
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
// ============================================
|
|
61
|
+
// VALIDATORS
|
|
62
|
+
// ============================================
|
|
63
|
+
function validateUIConstitution(prompt, options) {
|
|
64
|
+
const violations = [];
|
|
65
|
+
// V2: Accept any valid theme — only flag if no theme at all
|
|
66
|
+
const validThemes = ['deep-void', 'glassmorphism', 'glass', 'professional', 'pro', 'saas',
|
|
67
|
+
'business', 'clean', 'minimal', 'minimalist', 'simple', 'vibrant', 'colorful', 'social'];
|
|
68
|
+
const hasValidTheme = options.theme && validThemes.includes(options.theme.toLowerCase());
|
|
69
|
+
if (!hasValidTheme) {
|
|
70
|
+
violations.push({
|
|
71
|
+
type: 'ui',
|
|
72
|
+
severity: 'low', // Downgraded from 'high' — glassmorphism is applied as default anyway
|
|
73
|
+
law: exports.UI_CONSTITUTION.background.law,
|
|
74
|
+
message: 'No explicit theme specified — defaulting to Glassmorphism',
|
|
75
|
+
suggestion: 'Set --theme <name> to choose: glassmorphism, professional, minimal, vibrant',
|
|
76
|
+
autoFixable: true,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
// Check for glass/blur mentions
|
|
80
|
+
const hasGlassmorphism = prompt.toLowerCase().includes('glass') ||
|
|
81
|
+
prompt.toLowerCase().includes('blur') ||
|
|
82
|
+
prompt.toLowerCase().includes('frosted');
|
|
83
|
+
if (!hasGlassmorphism && !prompt.includes('card')) {
|
|
84
|
+
violations.push({
|
|
85
|
+
type: 'ui',
|
|
86
|
+
severity: 'medium',
|
|
87
|
+
law: exports.UI_CONSTITUTION.glassmorphism.law,
|
|
88
|
+
message: 'No glassmorphism UI specified',
|
|
89
|
+
suggestion: 'Cards should use blur(16px) with glass effect',
|
|
90
|
+
autoFixable: false,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// Check spacing mentions
|
|
94
|
+
const hasSpacing = prompt.match(/\d+(px|rem)/);
|
|
95
|
+
if (!hasSpacing) {
|
|
96
|
+
violations.push({
|
|
97
|
+
type: 'ui',
|
|
98
|
+
severity: 'low',
|
|
99
|
+
law: exports.UI_CONSTITUTION.spacing.law,
|
|
100
|
+
message: 'No spacing system mentioned',
|
|
101
|
+
suggestion: 'Use 8/16/24px grid for consistent spacing',
|
|
102
|
+
autoFixable: false,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return violations;
|
|
106
|
+
}
|
|
107
|
+
function validateAIConstitution(prompt, options) {
|
|
108
|
+
const violations = [];
|
|
109
|
+
// Check Redis context
|
|
110
|
+
const hasRedis = prompt.toLowerCase().includes('redis') ||
|
|
111
|
+
options.cache ||
|
|
112
|
+
options.db?.includes('redis');
|
|
113
|
+
if (!hasRedis) {
|
|
114
|
+
violations.push({
|
|
115
|
+
type: 'ai',
|
|
116
|
+
severity: 'medium',
|
|
117
|
+
law: exports.AI_CONSTITUTION.contextAwareness.law,
|
|
118
|
+
message: 'No Redis context layer specified',
|
|
119
|
+
suggestion: 'Add --cache or include redis in --db for user context memory',
|
|
120
|
+
autoFixable: true,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// Check for predictive features
|
|
124
|
+
const hasPredictive = prompt.toLowerCase().includes('predict') ||
|
|
125
|
+
prompt.toLowerCase().includes('suggest') ||
|
|
126
|
+
prompt.toLowerCase().includes('recommend') ||
|
|
127
|
+
prompt.toLowerCase().includes('forecast');
|
|
128
|
+
if (!hasPredictive) {
|
|
129
|
+
violations.push({
|
|
130
|
+
type: 'ai',
|
|
131
|
+
severity: 'high',
|
|
132
|
+
law: exports.AI_CONSTITUTION.proactiveIntelligence.law,
|
|
133
|
+
message: 'No predictive AI feature detected',
|
|
134
|
+
suggestion: 'Add AI prediction/suggestion capability to make app proactive',
|
|
135
|
+
autoFixable: false,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
// Check for natural interface
|
|
139
|
+
const hasNaturalUI = prompt.toLowerCase().includes('chat') ||
|
|
140
|
+
prompt.toLowerCase().includes('voice') ||
|
|
141
|
+
prompt.toLowerCase().includes('conversation');
|
|
142
|
+
if (!hasNaturalUI && !prompt.includes('dashboard')) {
|
|
143
|
+
violations.push({
|
|
144
|
+
type: 'ai',
|
|
145
|
+
severity: 'low',
|
|
146
|
+
law: exports.AI_CONSTITUTION.naturalInterface.law,
|
|
147
|
+
message: 'No natural interface (chat/voice) specified',
|
|
148
|
+
suggestion: 'Consider chat or voice input for better UX',
|
|
149
|
+
autoFixable: false,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return violations;
|
|
153
|
+
}
|
|
154
|
+
function validateConstitution(prompt, options) {
|
|
155
|
+
// Bypass if explicitly disabled
|
|
156
|
+
if (options.noConstitution) {
|
|
157
|
+
return {
|
|
158
|
+
compliant: true,
|
|
159
|
+
score: 100,
|
|
160
|
+
violations: [],
|
|
161
|
+
warnings: ['Constitutional validation bypassed with --no-constitution'],
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const uiViolations = validateUIConstitution(prompt, options);
|
|
165
|
+
const aiViolations = validateAIConstitution(prompt, options);
|
|
166
|
+
const allViolations = [...uiViolations, ...aiViolations];
|
|
167
|
+
// Calculate score
|
|
168
|
+
const highCount = allViolations.filter(v => v.severity === 'high').length;
|
|
169
|
+
const mediumCount = allViolations.filter(v => v.severity === 'medium').length;
|
|
170
|
+
const lowCount = allViolations.filter(v => v.severity === 'low').length;
|
|
171
|
+
const score = Math.max(0, 100 - (highCount * 15 + mediumCount * 8 + lowCount * 3));
|
|
172
|
+
const compliant = score >= 70; // 70% threshold for compliance
|
|
173
|
+
return {
|
|
174
|
+
compliant,
|
|
175
|
+
score,
|
|
176
|
+
violations: allViolations,
|
|
177
|
+
warnings: [],
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function autoCorrectOptions(options, violations) {
|
|
181
|
+
const corrected = { ...options };
|
|
182
|
+
violations.forEach(violation => {
|
|
183
|
+
if (!violation.autoFixable)
|
|
184
|
+
return;
|
|
185
|
+
// Auto-fix theme — default to glassmorphism if none specified
|
|
186
|
+
if (violation.message.includes('theme')) {
|
|
187
|
+
corrected.theme = corrected.theme || 'glassmorphism';
|
|
188
|
+
}
|
|
189
|
+
// Auto-add Redis cache
|
|
190
|
+
if (violation.message.includes('Redis')) {
|
|
191
|
+
corrected.cache = true;
|
|
192
|
+
if (corrected.db && !corrected.db.includes('redis')) {
|
|
193
|
+
corrected.db += ',redis';
|
|
194
|
+
}
|
|
195
|
+
else if (!corrected.db) {
|
|
196
|
+
corrected.db = 'redis';
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
return corrected;
|
|
201
|
+
}
|
|
202
|
+
function printConstitutionalReport(report) {
|
|
203
|
+
console.log(chalk_1.default.cyan('\n📜 Constitutional Compliance Report\n'));
|
|
204
|
+
// Score
|
|
205
|
+
const scoreColor = report.score >= 90 ? chalk_1.default.green :
|
|
206
|
+
report.score >= 70 ? chalk_1.default.yellow :
|
|
207
|
+
chalk_1.default.red;
|
|
208
|
+
console.log(scoreColor(`Score: ${report.score}/100`));
|
|
209
|
+
console.log(report.compliant ? chalk_1.default.green('✅ Compliant') : chalk_1.default.red('❌ Non-Compliant'));
|
|
210
|
+
// Violations
|
|
211
|
+
if (report.violations.length > 0) {
|
|
212
|
+
console.log(chalk_1.default.yellow(`\n⚠️ ${report.violations.length} Constitutional Violations:\n`));
|
|
213
|
+
report.violations.forEach((v, index) => {
|
|
214
|
+
const severityIcon = v.severity === 'high' ? '🔴' :
|
|
215
|
+
v.severity === 'medium' ? '🟡' :
|
|
216
|
+
'⚪';
|
|
217
|
+
console.log(`${severityIcon} ${index + 1}. [${v.type.toUpperCase()}] ${v.message}`);
|
|
218
|
+
console.log(chalk_1.default.gray(` Law: "${v.law}"`));
|
|
219
|
+
console.log(chalk_1.default.cyan(` 💡 ${v.suggestion}`));
|
|
220
|
+
if (v.autoFixable) {
|
|
221
|
+
console.log(chalk_1.default.green(' ✨ Auto-fixable'));
|
|
222
|
+
}
|
|
223
|
+
console.log('');
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
// Warnings
|
|
227
|
+
if (report.warnings.length > 0) {
|
|
228
|
+
console.log(chalk_1.default.yellow('Warnings:'));
|
|
229
|
+
report.warnings.forEach(w => console.log(chalk_1.default.gray(` - ${w}`)));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function enhancePromptWithConstitution(prompt) {
|
|
233
|
+
const enhancement = `
|
|
234
|
+
CONSTITUTIONAL REQUIREMENTS:
|
|
235
|
+
|
|
236
|
+
UI Constitution - Deep Void:
|
|
237
|
+
- Background: Linear gradient #0f0c29 → #000000
|
|
238
|
+
- Cards: backdrop-filter blur(16px), rgba(255,255,255,0.1), border rgba(255,255,255,0.2)
|
|
239
|
+
- Accent: #FFD700 for CTAs/FABs only
|
|
240
|
+
- Spacing: 8px/16px/24px grid
|
|
241
|
+
|
|
242
|
+
AI Constitution - AI-First:
|
|
243
|
+
- Redis context for user memory
|
|
244
|
+
- One predictive AI feature
|
|
245
|
+
- Natural interface (chat/voice preferred)
|
|
246
|
+
`;
|
|
247
|
+
return `${prompt}\n${enhancement}`;
|
|
248
|
+
}
|
|
249
|
+
//# sourceMappingURL=constitutional-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constitutional-validator.js","sourceRoot":"","sources":["../../src/utils/constitutional-validator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAmFH,wDAiDC;AAED,wDAqDC;AAED,oDA6BC;AAED,gDAuBC;AAED,8DAmCC;AAED,sEAiBC;AAzSD,kDAA0B;AAE1B,+CAA+C;AAC/C,6BAA6B;AAC7B,+CAA+C;AAElC,QAAA,eAAe,GAAG;IAC3B,UAAU,EAAE;QACR,QAAQ,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC;QAChC,GAAG,EAAE,4CAA4C;KACpD;IACD,aAAa,EAAE;QACX,IAAI,EAAE,MAAM;QACZ,YAAY,EAAE,0BAA0B;QACxC,MAAM,EAAE,0BAA0B;QAClC,GAAG,EAAE,gEAAgE;KACxE;IACD,MAAM,EAAE;QACJ,SAAS,EAAE,SAAS;QACpB,GAAG,EAAE,qDAAqD;KAC7D;IACD,OAAO,EAAE;QACL,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;QACjB,GAAG,EAAE,qCAAqC;KAC7C;CACK,CAAC;AAEE,QAAA,eAAe,GAAG;IAC3B,gBAAgB,EAAE;QACd,WAAW,EAAE,uCAAuC;QACpD,GAAG,EAAE,oCAAoC;KAC5C;IACD,qBAAqB,EAAE;QACnB,WAAW,EAAE,gCAAgC;QAC7C,OAAO,EAAE,6CAA6C;QACtD,GAAG,EAAE,gDAAgD;KACxD;IACD,YAAY,EAAE;QACV,WAAW,EAAE,yCAAyC;QACtD,GAAG,EAAE,sDAAsD;KAC9D;IACD,gBAAgB,EAAE;QACd,UAAU,EAAE,+BAA+B;QAC3C,GAAG,EAAE,iCAAiC;KACzC;CACK,CAAC;AAgCX,+CAA+C;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Ac;IACxD,MAAM,WAAW,GAAG;;;;;;;;;;;;;CAavB,CAAC;IAEE,OAAO,GAAG,MAAM,KAAK,WAAW,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NextAuth catch-all API route.
|
|
3
|
+
*
|
|
4
|
+
* This file should be placed at: app/api/auth/[...nextauth]/route.ts
|
|
5
|
+
*
|
|
6
|
+
* Prerequisites:
|
|
7
|
+
* - npm install next-auth
|
|
8
|
+
* - Set NEXTAUTH_SECRET in your .env
|
|
9
|
+
* - Configure authOptions in components/auth/nextauth-config.ts
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// import NextAuth from 'next-auth';
|
|
13
|
+
// import { authOptions } from '@/components/auth/nextauth-config';
|
|
14
|
+
//
|
|
15
|
+
// const handler = NextAuth(authOptions);
|
|
16
|
+
// export { handler as GET, handler as POST };
|
|
17
|
+
|
|
18
|
+
import { NextResponse } from 'next/server';
|
|
19
|
+
|
|
20
|
+
// Placeholder until NextAuth is installed and configured
|
|
21
|
+
export async function GET() {
|
|
22
|
+
return NextResponse.json({
|
|
23
|
+
message: 'NextAuth not configured yet. Install next-auth and uncomment the handler above.',
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function POST() {
|
|
28
|
+
return NextResponse.json({
|
|
29
|
+
message: 'NextAuth not configured yet. Install next-auth and uncomment the handler above.',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* POST /api/auth/login
|
|
5
|
+
* Authenticates a user with email and password.
|
|
6
|
+
*
|
|
7
|
+
* Replace the database stubs below with your actual Prisma or Supabase queries.
|
|
8
|
+
*/
|
|
9
|
+
export async function POST(request: NextRequest) {
|
|
10
|
+
try {
|
|
11
|
+
const { email, password } = await request.json();
|
|
12
|
+
|
|
13
|
+
if (!email || !password) {
|
|
14
|
+
return NextResponse.json(
|
|
15
|
+
{ error: 'Email and password are required' },
|
|
16
|
+
{ status: 400 }
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// --- Replace with your database lookup ---
|
|
21
|
+
// const user = await prisma.user.findUnique({ where: { email } });
|
|
22
|
+
const user = await lookupUser(email);
|
|
23
|
+
|
|
24
|
+
if (!user) {
|
|
25
|
+
return NextResponse.json(
|
|
26
|
+
{ error: 'Invalid credentials' },
|
|
27
|
+
{ status: 401 }
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// --- Replace with bcrypt.compare(password, user.passwordHash) ---
|
|
32
|
+
const isValid = await verifyPassword(password, user.passwordHash);
|
|
33
|
+
|
|
34
|
+
if (!isValid) {
|
|
35
|
+
return NextResponse.json(
|
|
36
|
+
{ error: 'Invalid credentials' },
|
|
37
|
+
{ status: 401 }
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Create session
|
|
42
|
+
const sessionToken = crypto.randomUUID();
|
|
43
|
+
const expiresAt = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
|
|
44
|
+
|
|
45
|
+
// --- Replace with your session creation logic ---
|
|
46
|
+
// await prisma.session.create({ data: { userId: user.id, token: sessionToken, expiresAt } });
|
|
47
|
+
await createSession(user.id, sessionToken, expiresAt);
|
|
48
|
+
|
|
49
|
+
const response = NextResponse.json({
|
|
50
|
+
message: 'Login successful',
|
|
51
|
+
token: sessionToken,
|
|
52
|
+
user: { id: user.id, email: user.email, name: user.name },
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Set httpOnly cookie as well
|
|
56
|
+
response.cookies.set('authToken', sessionToken, {
|
|
57
|
+
httpOnly: true,
|
|
58
|
+
secure: process.env.NODE_ENV === 'production',
|
|
59
|
+
sameSite: 'lax',
|
|
60
|
+
path: '/',
|
|
61
|
+
maxAge: 7 * 24 * 60 * 60,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return response;
|
|
65
|
+
} catch (error: unknown) {
|
|
66
|
+
const message = error instanceof Error ? error.message : 'Internal server error';
|
|
67
|
+
return NextResponse.json({ error: message }, { status: 500 });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// --- Stubs: replace with real implementations ---
|
|
72
|
+
|
|
73
|
+
async function lookupUser(_email: string): Promise<{
|
|
74
|
+
id: string;
|
|
75
|
+
email: string;
|
|
76
|
+
name: string | null;
|
|
77
|
+
passwordHash: string;
|
|
78
|
+
} | null> {
|
|
79
|
+
// Replace with: return prisma.user.findUnique({ where: { email } });
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function verifyPassword(_plain: string, _hash: string): Promise<boolean> {
|
|
84
|
+
// Replace with: return bcrypt.compare(plain, hash);
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function createSession(_userId: string, _token: string, _expiresAt: Date): Promise<void> {
|
|
89
|
+
// Replace with: await prisma.session.create({ data: { userId, token, expiresAt } });
|
|
90
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* POST /api/auth/register
|
|
5
|
+
* Creates a new user account.
|
|
6
|
+
*
|
|
7
|
+
* Replace the database stubs below with your actual Prisma or Supabase queries.
|
|
8
|
+
*/
|
|
9
|
+
export async function POST(request: NextRequest) {
|
|
10
|
+
try {
|
|
11
|
+
const { name, email, password } = await request.json();
|
|
12
|
+
|
|
13
|
+
if (!email || !password) {
|
|
14
|
+
return NextResponse.json(
|
|
15
|
+
{ error: 'Email and password are required' },
|
|
16
|
+
{ status: 400 }
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof password !== 'string' || password.length < 8) {
|
|
21
|
+
return NextResponse.json(
|
|
22
|
+
{ error: 'Password must be at least 8 characters' },
|
|
23
|
+
{ status: 400 }
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Check if user already exists
|
|
28
|
+
const existing = await lookupUserByEmail(email);
|
|
29
|
+
if (existing) {
|
|
30
|
+
return NextResponse.json(
|
|
31
|
+
{ error: 'An account with this email already exists' },
|
|
32
|
+
{ status: 409 }
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Hash password
|
|
37
|
+
const passwordHash = await hashPassword(password);
|
|
38
|
+
|
|
39
|
+
// Create user
|
|
40
|
+
const user = await createUser({ name: name || null, email, passwordHash });
|
|
41
|
+
|
|
42
|
+
// Create session
|
|
43
|
+
const sessionToken = crypto.randomUUID();
|
|
44
|
+
const expiresAt = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
|
|
45
|
+
await createSession(user.id, sessionToken, expiresAt);
|
|
46
|
+
|
|
47
|
+
const response = NextResponse.json({
|
|
48
|
+
message: 'Account created successfully',
|
|
49
|
+
token: sessionToken,
|
|
50
|
+
user: { id: user.id, email: user.email, name: user.name },
|
|
51
|
+
}, { status: 201 });
|
|
52
|
+
|
|
53
|
+
response.cookies.set('authToken', sessionToken, {
|
|
54
|
+
httpOnly: true,
|
|
55
|
+
secure: process.env.NODE_ENV === 'production',
|
|
56
|
+
sameSite: 'lax',
|
|
57
|
+
path: '/',
|
|
58
|
+
maxAge: 7 * 24 * 60 * 60,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return response;
|
|
62
|
+
} catch (error: unknown) {
|
|
63
|
+
const message = error instanceof Error ? error.message : 'Internal server error';
|
|
64
|
+
return NextResponse.json({ error: message }, { status: 500 });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// --- Stubs: replace with real implementations ---
|
|
69
|
+
|
|
70
|
+
async function lookupUserByEmail(_email: string): Promise<{ id: string } | null> {
|
|
71
|
+
// return prisma.user.findUnique({ where: { email }, select: { id: true } });
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function hashPassword(_password: string): Promise<string> {
|
|
76
|
+
// return bcrypt.hash(password, 12);
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function createUser(data: {
|
|
81
|
+
name: string | null;
|
|
82
|
+
email: string;
|
|
83
|
+
passwordHash: string;
|
|
84
|
+
}): Promise<{ id: string; email: string; name: string | null }> {
|
|
85
|
+
// return prisma.user.create({ data });
|
|
86
|
+
return { id: crypto.randomUUID(), email: data.email, name: data.name };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function createSession(_userId: string, _token: string, _expiresAt: Date): Promise<void> {
|
|
90
|
+
// await prisma.session.create({ data: { userId, token, expiresAt } });
|
|
91
|
+
}
|