@friggframework/devtools 2.0.0-next.3 → 2.0.0-next.30
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/frigg-cli/.eslintrc.js +141 -0
- package/frigg-cli/__tests__/jest.config.js +102 -0
- package/frigg-cli/__tests__/unit/commands/build.test.js +483 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +418 -0
- package/frigg-cli/__tests__/unit/commands/ui.test.js +592 -0
- package/frigg-cli/__tests__/utils/command-tester.js +170 -0
- package/frigg-cli/__tests__/utils/mock-factory.js +270 -0
- package/frigg-cli/__tests__/utils/test-fixtures.js +463 -0
- package/frigg-cli/__tests__/utils/test-setup.js +286 -0
- package/frigg-cli/build-command/index.js +54 -0
- package/frigg-cli/deploy-command/index.js +36 -0
- package/frigg-cli/generate-command/__tests__/generate-command.test.js +312 -0
- package/frigg-cli/generate-command/azure-generator.js +43 -0
- package/frigg-cli/generate-command/gcp-generator.js +47 -0
- package/frigg-cli/generate-command/index.js +332 -0
- package/frigg-cli/generate-command/terraform-generator.js +555 -0
- package/frigg-cli/generate-iam-command.js +115 -0
- package/frigg-cli/index.js +47 -1
- package/frigg-cli/index.test.js +1 -4
- package/frigg-cli/init-command/backend-first-handler.js +756 -0
- package/frigg-cli/init-command/index.js +93 -0
- package/frigg-cli/init-command/template-handler.js +143 -0
- package/frigg-cli/install-command/index.js +1 -4
- package/frigg-cli/package.json +51 -0
- package/frigg-cli/start-command/index.js +24 -4
- package/frigg-cli/test/init-command.test.js +180 -0
- package/frigg-cli/test/npm-registry.test.js +319 -0
- package/frigg-cli/ui-command/index.js +154 -0
- package/frigg-cli/utils/app-resolver.js +319 -0
- package/frigg-cli/utils/backend-path.js +16 -17
- package/frigg-cli/utils/npm-registry.js +167 -0
- package/frigg-cli/utils/process-manager.js +199 -0
- package/frigg-cli/utils/repo-detection.js +405 -0
- package/infrastructure/AWS-DISCOVERY-TROUBLESHOOTING.md +245 -0
- package/infrastructure/AWS-IAM-CREDENTIAL-NEEDS.md +596 -0
- package/infrastructure/DEPLOYMENT-INSTRUCTIONS.md +268 -0
- package/infrastructure/GENERATE-IAM-DOCS.md +253 -0
- package/infrastructure/IAM-POLICY-TEMPLATES.md +176 -0
- package/infrastructure/README-TESTING.md +332 -0
- package/infrastructure/README.md +421 -0
- package/infrastructure/WEBSOCKET-CONFIGURATION.md +105 -0
- package/infrastructure/__tests__/fixtures/mock-aws-resources.js +391 -0
- package/infrastructure/__tests__/helpers/test-utils.js +277 -0
- package/infrastructure/aws-discovery.js +568 -0
- package/infrastructure/aws-discovery.test.js +373 -0
- package/infrastructure/build-time-discovery.js +206 -0
- package/infrastructure/build-time-discovery.test.js +375 -0
- package/infrastructure/create-frigg-infrastructure.js +3 -5
- package/infrastructure/frigg-deployment-iam-stack.yaml +379 -0
- package/infrastructure/iam-generator.js +687 -0
- package/infrastructure/iam-generator.test.js +169 -0
- package/infrastructure/iam-policy-basic.json +212 -0
- package/infrastructure/iam-policy-full.json +282 -0
- package/infrastructure/integration.test.js +383 -0
- package/infrastructure/run-discovery.js +110 -0
- package/infrastructure/serverless-template.js +923 -113
- package/infrastructure/serverless-template.test.js +541 -0
- package/management-ui/.eslintrc.js +22 -0
- package/management-ui/README.md +203 -0
- package/management-ui/components.json +21 -0
- package/management-ui/docs/phase2-integration-guide.md +320 -0
- package/management-ui/index.html +13 -0
- package/management-ui/package-lock.json +16517 -0
- package/management-ui/package.json +76 -0
- package/management-ui/packages/devtools/frigg-cli/ui-command/index.js +302 -0
- package/management-ui/postcss.config.js +6 -0
- package/management-ui/server/api/backend.js +256 -0
- package/management-ui/server/api/cli.js +315 -0
- package/management-ui/server/api/codegen.js +663 -0
- package/management-ui/server/api/connections.js +857 -0
- package/management-ui/server/api/discovery.js +185 -0
- package/management-ui/server/api/environment/index.js +1 -0
- package/management-ui/server/api/environment/router.js +378 -0
- package/management-ui/server/api/environment.js +328 -0
- package/management-ui/server/api/integrations.js +876 -0
- package/management-ui/server/api/logs.js +248 -0
- package/management-ui/server/api/monitoring.js +282 -0
- package/management-ui/server/api/open-ide.js +31 -0
- package/management-ui/server/api/project.js +1029 -0
- package/management-ui/server/api/users/sessions.js +371 -0
- package/management-ui/server/api/users/simulation.js +254 -0
- package/management-ui/server/api/users.js +362 -0
- package/management-ui/server/api-contract.md +275 -0
- package/management-ui/server/index.js +873 -0
- package/management-ui/server/middleware/errorHandler.js +93 -0
- package/management-ui/server/middleware/security.js +32 -0
- package/management-ui/server/processManager.js +296 -0
- package/management-ui/server/server.js +346 -0
- package/management-ui/server/services/aws-monitor.js +413 -0
- package/management-ui/server/services/npm-registry.js +347 -0
- package/management-ui/server/services/template-engine.js +538 -0
- package/management-ui/server/utils/cliIntegration.js +220 -0
- package/management-ui/server/utils/environment/auditLogger.js +471 -0
- package/management-ui/server/utils/environment/awsParameterStore.js +264 -0
- package/management-ui/server/utils/environment/encryption.js +278 -0
- package/management-ui/server/utils/environment/envFileManager.js +286 -0
- package/management-ui/server/utils/import-commonjs.js +28 -0
- package/management-ui/server/utils/response.js +83 -0
- package/management-ui/server/websocket/handler.js +325 -0
- package/management-ui/src/App.jsx +109 -0
- package/management-ui/src/assets/FriggLogo.svg +1 -0
- package/management-ui/src/components/AppRouter.jsx +65 -0
- package/management-ui/src/components/Button.jsx +70 -0
- package/management-ui/src/components/Card.jsx +97 -0
- package/management-ui/src/components/EnvironmentCompare.jsx +400 -0
- package/management-ui/src/components/EnvironmentEditor.jsx +372 -0
- package/management-ui/src/components/EnvironmentImportExport.jsx +469 -0
- package/management-ui/src/components/EnvironmentSchema.jsx +491 -0
- package/management-ui/src/components/EnvironmentSecurity.jsx +463 -0
- package/management-ui/src/components/ErrorBoundary.jsx +73 -0
- package/management-ui/src/components/IntegrationCard.jsx +481 -0
- package/management-ui/src/components/IntegrationCardEnhanced.jsx +770 -0
- package/management-ui/src/components/IntegrationExplorer.jsx +379 -0
- package/management-ui/src/components/IntegrationStatus.jsx +336 -0
- package/management-ui/src/components/Layout.jsx +716 -0
- package/management-ui/src/components/LoadingSpinner.jsx +113 -0
- package/management-ui/src/components/RepositoryPicker.jsx +248 -0
- package/management-ui/src/components/SessionMonitor.jsx +350 -0
- package/management-ui/src/components/StatusBadge.jsx +208 -0
- package/management-ui/src/components/UserContextSwitcher.jsx +212 -0
- package/management-ui/src/components/UserSimulation.jsx +327 -0
- package/management-ui/src/components/Welcome.jsx +434 -0
- package/management-ui/src/components/codegen/APIEndpointGenerator.jsx +637 -0
- package/management-ui/src/components/codegen/APIModuleSelector.jsx +227 -0
- package/management-ui/src/components/codegen/CodeGenerationWizard.jsx +247 -0
- package/management-ui/src/components/codegen/CodePreviewEditor.jsx +316 -0
- package/management-ui/src/components/codegen/DynamicModuleForm.jsx +271 -0
- package/management-ui/src/components/codegen/FormBuilder.jsx +737 -0
- package/management-ui/src/components/codegen/IntegrationGenerator.jsx +855 -0
- package/management-ui/src/components/codegen/ProjectScaffoldWizard.jsx +797 -0
- package/management-ui/src/components/codegen/SchemaBuilder.jsx +303 -0
- package/management-ui/src/components/codegen/TemplateSelector.jsx +586 -0
- package/management-ui/src/components/codegen/index.js +10 -0
- package/management-ui/src/components/connections/ConnectionConfigForm.jsx +362 -0
- package/management-ui/src/components/connections/ConnectionHealthMonitor.jsx +182 -0
- package/management-ui/src/components/connections/ConnectionTester.jsx +200 -0
- package/management-ui/src/components/connections/EntityRelationshipMapper.jsx +292 -0
- package/management-ui/src/components/connections/OAuthFlow.jsx +204 -0
- package/management-ui/src/components/connections/index.js +5 -0
- package/management-ui/src/components/index.js +21 -0
- package/management-ui/src/components/monitoring/APIGatewayMetrics.jsx +222 -0
- package/management-ui/src/components/monitoring/LambdaMetrics.jsx +169 -0
- package/management-ui/src/components/monitoring/MetricsChart.jsx +197 -0
- package/management-ui/src/components/monitoring/MonitoringDashboard.jsx +393 -0
- package/management-ui/src/components/monitoring/SQSMetrics.jsx +246 -0
- package/management-ui/src/components/monitoring/index.js +6 -0
- package/management-ui/src/components/monitoring/monitoring.css +218 -0
- package/management-ui/src/components/theme-provider.jsx +52 -0
- package/management-ui/src/components/theme-toggle.jsx +39 -0
- package/management-ui/src/components/ui/badge.tsx +36 -0
- package/management-ui/src/components/ui/button.test.jsx +56 -0
- package/management-ui/src/components/ui/button.tsx +57 -0
- package/management-ui/src/components/ui/card.tsx +76 -0
- package/management-ui/src/components/ui/dropdown-menu.tsx +199 -0
- package/management-ui/src/components/ui/select.tsx +157 -0
- package/management-ui/src/components/ui/skeleton.jsx +15 -0
- package/management-ui/src/hooks/useFrigg.jsx +601 -0
- package/management-ui/src/hooks/useSocket.jsx +58 -0
- package/management-ui/src/index.css +193 -0
- package/management-ui/src/lib/utils.ts +6 -0
- package/management-ui/src/main.jsx +10 -0
- package/management-ui/src/pages/CodeGeneration.jsx +14 -0
- package/management-ui/src/pages/Connections.jsx +252 -0
- package/management-ui/src/pages/ConnectionsEnhanced.jsx +633 -0
- package/management-ui/src/pages/Dashboard.jsx +311 -0
- package/management-ui/src/pages/Environment.jsx +314 -0
- package/management-ui/src/pages/IntegrationConfigure.jsx +669 -0
- package/management-ui/src/pages/IntegrationDiscovery.jsx +567 -0
- package/management-ui/src/pages/IntegrationTest.jsx +742 -0
- package/management-ui/src/pages/Integrations.jsx +253 -0
- package/management-ui/src/pages/Monitoring.jsx +17 -0
- package/management-ui/src/pages/Simulation.jsx +155 -0
- package/management-ui/src/pages/Users.jsx +492 -0
- package/management-ui/src/services/api.js +41 -0
- package/management-ui/src/services/apiModuleService.js +193 -0
- package/management-ui/src/services/websocket-handlers.js +120 -0
- package/management-ui/src/test/api/project.test.js +273 -0
- package/management-ui/src/test/components/Welcome.test.jsx +378 -0
- package/management-ui/src/test/mocks/server.js +178 -0
- package/management-ui/src/test/setup.js +61 -0
- package/management-ui/src/test/utils/test-utils.jsx +134 -0
- package/management-ui/src/utils/repository.js +98 -0
- package/management-ui/src/utils/repository.test.js +118 -0
- package/management-ui/src/workflows/phase2-integration-workflows.js +884 -0
- package/management-ui/tailwind.config.js +63 -0
- package/management-ui/tsconfig.json +37 -0
- package/management-ui/tsconfig.node.json +10 -0
- package/management-ui/vite.config.js +26 -0
- package/management-ui/vitest.config.js +38 -0
- package/package.json +16 -9
- package/infrastructure/app-handler-helpers.js +0 -57
- package/infrastructure/backend-utils.js +0 -90
- package/infrastructure/routers/auth.js +0 -26
- package/infrastructure/routers/integration-defined-routers.js +0 -37
- package/infrastructure/routers/middleware/loadUser.js +0 -15
- package/infrastructure/routers/middleware/requireLoggedInUser.js +0 -12
- package/infrastructure/routers/user.js +0 -41
- package/infrastructure/routers/websocket.js +0 -55
- package/infrastructure/workers/integration-defined-workers.js +0 -24
|
@@ -0,0 +1,855 @@
|
|
|
1
|
+
import React, { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import { Card } from '../Card';
|
|
3
|
+
import { Button } from '../Button';
|
|
4
|
+
import FormBuilder from './FormBuilder';
|
|
5
|
+
import SchemaBuilder from './SchemaBuilder';
|
|
6
|
+
import APIModuleSelector from './APIModuleSelector';
|
|
7
|
+
import apiModuleService from '../../services/apiModuleService';
|
|
8
|
+
|
|
9
|
+
const API_MODULE_TYPES = {
|
|
10
|
+
API: 'api',
|
|
11
|
+
OAUTH1: 'oauth1',
|
|
12
|
+
OAUTH2: 'oauth2',
|
|
13
|
+
BASIC_AUTH: 'basic-auth',
|
|
14
|
+
CUSTOM: 'custom'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const AUTHENTICATION_FIELDS = {
|
|
18
|
+
[API_MODULE_TYPES.API]: [
|
|
19
|
+
{ name: 'apiKey', label: 'API Key', type: 'string', required: true, encrypted: false }
|
|
20
|
+
],
|
|
21
|
+
[API_MODULE_TYPES.OAUTH2]: [
|
|
22
|
+
{ name: 'access_token', label: 'Access Token', type: 'string', required: true, encrypted: false },
|
|
23
|
+
{ name: 'refresh_token', label: 'Refresh Token', type: 'string', required: false, encrypted: false },
|
|
24
|
+
{ name: 'expires_at', label: 'Expires At', type: 'date', required: false, encrypted: false },
|
|
25
|
+
{ name: 'scope', label: 'Scope', type: 'string', required: false, encrypted: false }
|
|
26
|
+
],
|
|
27
|
+
[API_MODULE_TYPES.BASIC_AUTH]: [
|
|
28
|
+
{ name: 'username', label: 'Username', type: 'string', required: true, encrypted: false },
|
|
29
|
+
{ name: 'password', label: 'Password', type: 'string', required: true, encrypted: true }
|
|
30
|
+
],
|
|
31
|
+
[API_MODULE_TYPES.OAUTH1]: [
|
|
32
|
+
{ name: 'oauth_token', label: 'OAuth Token', type: 'string', required: true, encrypted: false },
|
|
33
|
+
{ name: 'oauth_token_secret', label: 'OAuth Token Secret', type: 'string', required: true, encrypted: true }
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const IntegrationGenerator = ({ onGenerate }) => {
|
|
38
|
+
const [formData, setFormData] = useState({
|
|
39
|
+
name: '',
|
|
40
|
+
displayName: '',
|
|
41
|
+
description: '',
|
|
42
|
+
category: 'API Module',
|
|
43
|
+
type: API_MODULE_TYPES.API,
|
|
44
|
+
baseURL: '',
|
|
45
|
+
authorizationURL: '',
|
|
46
|
+
tokenURL: '',
|
|
47
|
+
scope: '',
|
|
48
|
+
apiEndpoints: [],
|
|
49
|
+
entitySchema: [],
|
|
50
|
+
useExistingModule: false,
|
|
51
|
+
selectedModule: null,
|
|
52
|
+
moduleDetails: null
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const [currentTab, setCurrentTab] = useState('basic');
|
|
56
|
+
const [moduleDetailsLoading, setModuleDetailsLoading] = useState(false);
|
|
57
|
+
|
|
58
|
+
const handleInputChange = useCallback((field, value) => {
|
|
59
|
+
setFormData(prev => ({
|
|
60
|
+
...prev,
|
|
61
|
+
[field]: value
|
|
62
|
+
}));
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
65
|
+
const handleModuleSelect = useCallback(async (moduleName) => {
|
|
66
|
+
setFormData(prev => ({
|
|
67
|
+
...prev,
|
|
68
|
+
selectedModule: moduleName
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
if (moduleName) {
|
|
72
|
+
setModuleDetailsLoading(true);
|
|
73
|
+
try {
|
|
74
|
+
const details = await apiModuleService.getModuleDetails(moduleName);
|
|
75
|
+
setFormData(prev => ({
|
|
76
|
+
...prev,
|
|
77
|
+
moduleDetails: details,
|
|
78
|
+
// Auto-fill form fields based on module
|
|
79
|
+
name: details.name.replace('@friggframework/api-module-', ''),
|
|
80
|
+
displayName: details.displayName,
|
|
81
|
+
description: details.description || prev.description,
|
|
82
|
+
type: details.authType === 'oauth2' ? INTEGRATION_TYPES.OAUTH2 :
|
|
83
|
+
details.authType === 'api-key' ? INTEGRATION_TYPES.API :
|
|
84
|
+
details.authType === 'basic-auth' ? INTEGRATION_TYPES.BASIC_AUTH :
|
|
85
|
+
INTEGRATION_TYPES.CUSTOM
|
|
86
|
+
}));
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error('Error loading module details:', error);
|
|
89
|
+
} finally {
|
|
90
|
+
setModuleDetailsLoading(false);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}, []);
|
|
94
|
+
|
|
95
|
+
const handleEndpointAdd = useCallback(() => {
|
|
96
|
+
setFormData(prev => ({
|
|
97
|
+
...prev,
|
|
98
|
+
apiEndpoints: [
|
|
99
|
+
...prev.apiEndpoints,
|
|
100
|
+
{
|
|
101
|
+
id: Date.now(),
|
|
102
|
+
name: '',
|
|
103
|
+
method: 'GET',
|
|
104
|
+
path: '',
|
|
105
|
+
description: '',
|
|
106
|
+
parameters: [],
|
|
107
|
+
responseSchema: {}
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
}));
|
|
111
|
+
}, []);
|
|
112
|
+
|
|
113
|
+
const handleEndpointUpdate = useCallback((id, updates) => {
|
|
114
|
+
setFormData(prev => ({
|
|
115
|
+
...prev,
|
|
116
|
+
apiEndpoints: prev.apiEndpoints.map(endpoint =>
|
|
117
|
+
endpoint.id === id ? { ...endpoint, ...updates } : endpoint
|
|
118
|
+
)
|
|
119
|
+
}));
|
|
120
|
+
}, []);
|
|
121
|
+
|
|
122
|
+
const handleEndpointRemove = useCallback((id) => {
|
|
123
|
+
setFormData(prev => ({
|
|
124
|
+
...prev,
|
|
125
|
+
apiEndpoints: prev.apiEndpoints.filter(endpoint => endpoint.id !== id)
|
|
126
|
+
}));
|
|
127
|
+
}, []);
|
|
128
|
+
|
|
129
|
+
const generateIntegrationCode = useCallback(() => {
|
|
130
|
+
const className = formData.name.replace(/-/g, '_').replace(/(?:^|_)(\w)/g, (_, c) => c.toUpperCase());
|
|
131
|
+
|
|
132
|
+
// If using existing module, generate wrapper code
|
|
133
|
+
if (formData.useExistingModule && formData.selectedModule) {
|
|
134
|
+
return generateModuleWrapperCode();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Otherwise generate full custom integration
|
|
138
|
+
const authFields = AUTHENTICATION_FIELDS[formData.type] || [];
|
|
139
|
+
const allEntityFields = [...authFields, ...formData.entitySchema, { name: 'user_id', label: 'User ID', type: 'string', required: true }];
|
|
140
|
+
|
|
141
|
+
// Generate Entity class
|
|
142
|
+
const entityCode = `class ${className}Entity extends Entity {
|
|
143
|
+
static tableName = '${formData.name}';
|
|
144
|
+
|
|
145
|
+
static getSchema() {
|
|
146
|
+
return {
|
|
147
|
+
${allEntityFields.map(field =>
|
|
148
|
+
` ${field.name}: { type: '${field.type}', required: ${field.required}${field.encrypted ? ', encrypted: true' : ''}${field.default ? `, default: '${field.default}'` : ''} }`
|
|
149
|
+
).join(',\n')}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}`;
|
|
153
|
+
|
|
154
|
+
// Generate API class
|
|
155
|
+
const apiMethods = formData.apiEndpoints.map(endpoint => {
|
|
156
|
+
const methodName = endpoint.name || `${endpoint.method.toLowerCase()}${endpoint.path.replace(/[^a-zA-Z0-9]/g, '')}`;
|
|
157
|
+
const hasParams = endpoint.parameters && endpoint.parameters.length > 0;
|
|
158
|
+
|
|
159
|
+
return ` async ${methodName}(${hasParams ? 'params = {}' : ''}) {
|
|
160
|
+
const response = await this.${endpoint.method.toLowerCase()}('${endpoint.path}'${hasParams ? ', params' : ''});
|
|
161
|
+
return response.data;
|
|
162
|
+
}`;
|
|
163
|
+
}).join('\n\n');
|
|
164
|
+
|
|
165
|
+
const apiCode = `class ${className}Api extends Api {
|
|
166
|
+
constructor(config) {
|
|
167
|
+
super(config);
|
|
168
|
+
this.baseURL = '${formData.baseURL || 'https://api.example.com'}';
|
|
169
|
+
this.headers = {
|
|
170
|
+
'Content-Type': 'application/json'
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
${formData.type === INTEGRATION_TYPES.API ? ` setApiKey(apiKey) {
|
|
175
|
+
this.headers['Authorization'] = \`Bearer \${apiKey}\`;
|
|
176
|
+
}` : ''}
|
|
177
|
+
|
|
178
|
+
${formData.type === INTEGRATION_TYPES.BASIC_AUTH ? ` setCredentials(username, password) {
|
|
179
|
+
const credentials = Buffer.from(\`\${username}:\${password}\`).toString('base64');
|
|
180
|
+
this.headers['Authorization'] = \`Basic \${credentials}\`;
|
|
181
|
+
}` : ''}
|
|
182
|
+
|
|
183
|
+
${formData.type === INTEGRATION_TYPES.OAUTH2 ? ` setAccessToken(token) {
|
|
184
|
+
this.headers['Authorization'] = \`Bearer \${token}\`;
|
|
185
|
+
}` : ''}
|
|
186
|
+
|
|
187
|
+
async testConnection() {
|
|
188
|
+
const response = await this.get('/ping');
|
|
189
|
+
return response.data;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
${apiMethods || ' // Add your API methods here'}
|
|
193
|
+
}`;
|
|
194
|
+
|
|
195
|
+
// Generate Integration class
|
|
196
|
+
const integrationCode = `class ${className}Integration extends IntegrationBase {
|
|
197
|
+
static Entity = ${className}Entity;
|
|
198
|
+
static Api = ${className}Api;
|
|
199
|
+
static type = '${formData.name}';
|
|
200
|
+
|
|
201
|
+
static Config = {
|
|
202
|
+
name: '${formData.name}',
|
|
203
|
+
displayName: '${formData.displayName}',
|
|
204
|
+
description: '${formData.description}',
|
|
205
|
+
category: '${formData.category}',
|
|
206
|
+
version: '1.0.0',
|
|
207
|
+
supportedVersions: ['1.0.0']
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
async connect(params) {
|
|
211
|
+
const api = new ${className}Api();
|
|
212
|
+
|
|
213
|
+
// Set authentication
|
|
214
|
+
${formData.type === INTEGRATION_TYPES.API ? ` api.setApiKey(params.apiKey);` : ''}
|
|
215
|
+
${formData.type === INTEGRATION_TYPES.BASIC_AUTH ? ` api.setCredentials(params.username, params.password);` : ''}
|
|
216
|
+
${formData.type === INTEGRATION_TYPES.OAUTH2 ? ` api.setAccessToken(params.access_token);` : ''}
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
await api.testConnection();
|
|
220
|
+
} catch (error) {
|
|
221
|
+
throw new Error('Connection failed: ' + error.message);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const entity = await ${className}Entity.create({
|
|
225
|
+
${authFields.map(field => ` ${field.name}: params.${field.name}`).join(',\n')},
|
|
226
|
+
user_id: params.userId
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
return entity;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
static async checkConnection(entity) {
|
|
233
|
+
const api = new ${className}Api();
|
|
234
|
+
|
|
235
|
+
${formData.type === INTEGRATION_TYPES.API ? ` api.setApiKey(entity.apiKey);` : ''}
|
|
236
|
+
${formData.type === INTEGRATION_TYPES.BASIC_AUTH ? ` api.setCredentials(entity.username, entity.password);` : ''}
|
|
237
|
+
${formData.type === INTEGRATION_TYPES.OAUTH2 ? ` api.setAccessToken(entity.access_token);` : ''}
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
await api.testConnection();
|
|
241
|
+
return true;
|
|
242
|
+
} catch (error) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}`;
|
|
247
|
+
|
|
248
|
+
const fullCode = `const { Api, Entity, IntegrationBase } = require('@friggframework/core');
|
|
249
|
+
${formData.type === INTEGRATION_TYPES.OAUTH2 ? "const { OAuth2AuthorizationCode } = require('@friggframework/oauth2');" : ''}
|
|
250
|
+
|
|
251
|
+
${entityCode}
|
|
252
|
+
|
|
253
|
+
${apiCode}
|
|
254
|
+
|
|
255
|
+
${integrationCode}
|
|
256
|
+
|
|
257
|
+
module.exports = ${className}Integration;`;
|
|
258
|
+
|
|
259
|
+
const metadata = {
|
|
260
|
+
name: formData.name,
|
|
261
|
+
className,
|
|
262
|
+
type: formData.type,
|
|
263
|
+
files: [
|
|
264
|
+
{ name: 'index.js', content: fullCode },
|
|
265
|
+
{ name: 'package.json', content: generatePackageJson() },
|
|
266
|
+
{ name: 'README.md', content: generateReadme() },
|
|
267
|
+
{ name: '__tests__/index.test.js', content: generateTestFile() }
|
|
268
|
+
]
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
onGenerate(formData, fullCode, metadata);
|
|
272
|
+
}, [formData, onGenerate]);
|
|
273
|
+
|
|
274
|
+
const generateModuleWrapperCode = () => {
|
|
275
|
+
const className = formData.name.replace(/-/g, '_').replace(/(?:^|_)(\w)/g, (_, c) => c.toUpperCase());
|
|
276
|
+
const moduleName = formData.selectedModule;
|
|
277
|
+
const moduleDetails = formData.moduleDetails || {};
|
|
278
|
+
|
|
279
|
+
// Generate wrapper code that extends the npm module
|
|
280
|
+
const wrapperCode = `const ${className}Module = require('${moduleName}');
|
|
281
|
+
const { IntegrationBase } = require('@friggframework/core');
|
|
282
|
+
|
|
283
|
+
// Wrapper class that extends the npm module with custom functionality
|
|
284
|
+
class ${className}Integration extends IntegrationBase {
|
|
285
|
+
static Api = ${className}Module.Api;
|
|
286
|
+
static Entity = ${className}Module.Entity;
|
|
287
|
+
static Config = {
|
|
288
|
+
...${className}Module.Config,
|
|
289
|
+
// Override or extend configuration
|
|
290
|
+
displayName: '${formData.displayName || moduleDetails.displayName}',
|
|
291
|
+
description: '${formData.description || moduleDetails.description}'
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
constructor(config) {
|
|
295
|
+
super(config);
|
|
296
|
+
// Initialize the base module
|
|
297
|
+
this.module = new ${className}Module(config);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async connect(params) {
|
|
301
|
+
// Delegate to the module's connect method
|
|
302
|
+
return this.module.connect(params);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
static async checkConnection(entity) {
|
|
306
|
+
// Delegate to the module's checkConnection method
|
|
307
|
+
return ${className}Module.checkConnection(entity);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Add custom methods here
|
|
311
|
+
${formData.apiEndpoints.map(endpoint => {
|
|
312
|
+
const methodName = endpoint.name || `${endpoint.method.toLowerCase()}${endpoint.path.replace(/[^a-zA-Z0-9]/g, '')}`;
|
|
313
|
+
return ` async ${methodName}(params = {}) {
|
|
314
|
+
const api = new ${className}Module.Api(this.entity);
|
|
315
|
+
return api.${endpoint.method.toLowerCase()}('${endpoint.path}', params);
|
|
316
|
+
}`;
|
|
317
|
+
}).join('\n\n')}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
module.exports = ${className}Integration;`;
|
|
321
|
+
|
|
322
|
+
const packageJson = {
|
|
323
|
+
name: `@your-org/${formData.name}-integration`,
|
|
324
|
+
version: '0.1.0',
|
|
325
|
+
description: formData.description || `Integration wrapper for ${moduleName}`,
|
|
326
|
+
main: 'index.js',
|
|
327
|
+
scripts: {
|
|
328
|
+
test: 'jest',
|
|
329
|
+
'test:watch': 'jest --watch'
|
|
330
|
+
},
|
|
331
|
+
keywords: ['frigg', 'integration', formData.name],
|
|
332
|
+
dependencies: {
|
|
333
|
+
'@friggframework/core': '^1.0.0',
|
|
334
|
+
[moduleName]: `^${moduleDetails.version || 'latest'}`
|
|
335
|
+
},
|
|
336
|
+
devDependencies: {
|
|
337
|
+
'@jest/globals': '^29.0.0',
|
|
338
|
+
'jest': '^29.0.0'
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const readme = `# ${formData.displayName || moduleDetails.displayName} Integration
|
|
343
|
+
|
|
344
|
+
${formData.description || moduleDetails.description}
|
|
345
|
+
|
|
346
|
+
This integration extends the [${moduleName}](https://www.npmjs.com/package/${moduleName}) module.
|
|
347
|
+
|
|
348
|
+
## Installation
|
|
349
|
+
|
|
350
|
+
\`\`\`bash
|
|
351
|
+
npm install ${moduleName}
|
|
352
|
+
\`\`\`
|
|
353
|
+
|
|
354
|
+
## Configuration
|
|
355
|
+
|
|
356
|
+
${moduleDetails.requiredFields?.map(field => `- **${field.label}**: ${field.type}${field.required ? ' (required)' : ''}`).join('\n') || 'See module documentation for required configuration.'}
|
|
357
|
+
|
|
358
|
+
## Usage
|
|
359
|
+
|
|
360
|
+
\`\`\`javascript
|
|
361
|
+
const ${className}Integration = require('./index');
|
|
362
|
+
|
|
363
|
+
const integration = new ${className}Integration(config);
|
|
364
|
+
|
|
365
|
+
// Connect
|
|
366
|
+
const entity = await integration.connect({
|
|
367
|
+
${moduleDetails.requiredFields?.map(field => ` ${field.name}: 'your-${field.name}'`).join(',\n') || ' // Add required parameters'}
|
|
368
|
+
});
|
|
369
|
+
\`\`\`
|
|
370
|
+
|
|
371
|
+
## API Methods
|
|
372
|
+
|
|
373
|
+
${formData.apiEndpoints.map(endpoint => `- \`${endpoint.name || 'endpoint'}\`: ${endpoint.description || 'No description'}`).join('\n') || 'See module documentation for available methods.'}
|
|
374
|
+
`;
|
|
375
|
+
|
|
376
|
+
const metadata = {
|
|
377
|
+
name: formData.name,
|
|
378
|
+
className,
|
|
379
|
+
type: 'module-wrapper',
|
|
380
|
+
baseModule: moduleName,
|
|
381
|
+
files: [
|
|
382
|
+
{ name: 'index.js', content: wrapperCode },
|
|
383
|
+
{ name: 'package.json', content: JSON.stringify(packageJson, null, 2) },
|
|
384
|
+
{ name: 'README.md', content: readme }
|
|
385
|
+
]
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
onGenerate(formData, wrapperCode, metadata);
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
const generatePackageJson = () => {
|
|
392
|
+
const className = formData.name.replace(/-/g, '_').replace(/(?:^|_)(\w)/g, (_, c) => c.toUpperCase());
|
|
393
|
+
return JSON.stringify({
|
|
394
|
+
name: `@friggframework/${formData.name}`,
|
|
395
|
+
version: '0.1.0',
|
|
396
|
+
description: formData.description,
|
|
397
|
+
main: 'index.js',
|
|
398
|
+
scripts: {
|
|
399
|
+
test: 'jest',
|
|
400
|
+
'test:watch': 'jest --watch'
|
|
401
|
+
},
|
|
402
|
+
keywords: ['frigg', 'integration', formData.name],
|
|
403
|
+
dependencies: {
|
|
404
|
+
'@friggframework/core': '^1.0.0',
|
|
405
|
+
...(formData.type === INTEGRATION_TYPES.OAUTH2 ? { '@friggframework/oauth2': '^1.0.0' } : {})
|
|
406
|
+
},
|
|
407
|
+
devDependencies: {
|
|
408
|
+
'@jest/globals': '^29.0.0',
|
|
409
|
+
'jest': '^29.0.0'
|
|
410
|
+
}
|
|
411
|
+
}, null, 2);
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
const generateReadme = () => {
|
|
415
|
+
const className = formData.name.replace(/-/g, '_').replace(/(?:^|_)(\w)/g, (_, c) => c.toUpperCase());
|
|
416
|
+
return `# ${formData.displayName} Integration
|
|
417
|
+
|
|
418
|
+
${formData.description}
|
|
419
|
+
|
|
420
|
+
## Installation
|
|
421
|
+
|
|
422
|
+
\`\`\`bash
|
|
423
|
+
npm install @friggframework/${formData.name}
|
|
424
|
+
\`\`\`
|
|
425
|
+
|
|
426
|
+
## Usage
|
|
427
|
+
|
|
428
|
+
\`\`\`javascript
|
|
429
|
+
const ${className}Integration = require('@friggframework/${formData.name}');
|
|
430
|
+
|
|
431
|
+
const integration = new ${className}Integration();
|
|
432
|
+
|
|
433
|
+
// Connect
|
|
434
|
+
const entity = await integration.connect({
|
|
435
|
+
${AUTHENTICATION_FIELDS[formData.type]?.map(field => ` ${field.name}: 'your-${field.name.replace(/_/g, '-')}'`).join(',\n') || ' // Add your authentication parameters'}
|
|
436
|
+
userId: 'user-123'
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
// Check connection
|
|
440
|
+
const isConnected = await ${className}Integration.checkConnection(entity);
|
|
441
|
+
\`\`\`
|
|
442
|
+
|
|
443
|
+
## API Methods
|
|
444
|
+
|
|
445
|
+
${formData.apiEndpoints.map(endpoint => `- \`${endpoint.name || 'endpoint'}\`: ${endpoint.description || 'No description'}`).join('\n') || '- Add your API methods here'}
|
|
446
|
+
|
|
447
|
+
## License
|
|
448
|
+
|
|
449
|
+
MIT`;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
const generateTestFile = () => {
|
|
453
|
+
const className = formData.name.replace(/-/g, '_').replace(/(?:^|_)(\w)/g, (_, c) => c.toUpperCase());
|
|
454
|
+
return `const { describe, it, expect } = require('@jest/globals');
|
|
455
|
+
const ${className}Integration = require('../index');
|
|
456
|
+
|
|
457
|
+
describe('${className}Integration', () => {
|
|
458
|
+
it('should have correct configuration', () => {
|
|
459
|
+
expect(${className}Integration.Config.name).toBe('${formData.name}');
|
|
460
|
+
expect(${className}Integration.type).toBe('${formData.name}');
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
it('should have Entity and Api classes', () => {
|
|
464
|
+
expect(${className}Integration.Entity).toBeDefined();
|
|
465
|
+
expect(${className}Integration.Api).toBeDefined();
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
describe('Entity', () => {
|
|
469
|
+
it('should have correct table name', () => {
|
|
470
|
+
expect(${className}Integration.Entity.tableName).toBe('${formData.name}');
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
it('should have valid schema', () => {
|
|
474
|
+
const schema = ${className}Integration.Entity.getSchema();
|
|
475
|
+
expect(schema).toBeDefined();
|
|
476
|
+
expect(schema.user_id).toBeDefined();
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
describe('Api', () => {
|
|
481
|
+
it('should initialize with correct baseURL', () => {
|
|
482
|
+
const api = new ${className}Integration.Api();
|
|
483
|
+
expect(api.baseURL).toBe('${formData.baseURL || 'https://api.example.com'}');
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
});`;
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
const tabs = [
|
|
490
|
+
{ id: 'module', label: 'Module Selection', icon: '📦' },
|
|
491
|
+
{ id: 'basic', label: 'Basic Info', icon: '📝' },
|
|
492
|
+
{ id: 'auth', label: 'Authentication', icon: '🔐' },
|
|
493
|
+
{ id: 'endpoints', label: 'API Endpoints', icon: '🔗' },
|
|
494
|
+
{ id: 'schema', label: 'Entity Schema', icon: '📊' }
|
|
495
|
+
];
|
|
496
|
+
|
|
497
|
+
return (
|
|
498
|
+
<div className="space-y-6">
|
|
499
|
+
<h2 className="text-2xl font-bold">Integration Generator</h2>
|
|
500
|
+
|
|
501
|
+
{/* Tab Navigation */}
|
|
502
|
+
<div className="border-b border-gray-200">
|
|
503
|
+
<nav className="-mb-px flex space-x-8">
|
|
504
|
+
{tabs.map((tab) => (
|
|
505
|
+
<button
|
|
506
|
+
key={tab.id}
|
|
507
|
+
onClick={() => setCurrentTab(tab.id)}
|
|
508
|
+
className={`py-2 px-1 border-b-2 font-medium text-sm ${
|
|
509
|
+
currentTab === tab.id
|
|
510
|
+
? 'border-blue-500 text-blue-600'
|
|
511
|
+
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'
|
|
512
|
+
}`}
|
|
513
|
+
>
|
|
514
|
+
<span className="mr-2">{tab.icon}</span>
|
|
515
|
+
{tab.label}
|
|
516
|
+
</button>
|
|
517
|
+
))}
|
|
518
|
+
</nav>
|
|
519
|
+
</div>
|
|
520
|
+
|
|
521
|
+
{/* Tab Content */}
|
|
522
|
+
<Card className="p-6">
|
|
523
|
+
{currentTab === 'module' && (
|
|
524
|
+
<div className="space-y-4">
|
|
525
|
+
<div className="mb-6">
|
|
526
|
+
<label className="flex items-center space-x-3">
|
|
527
|
+
<input
|
|
528
|
+
type="checkbox"
|
|
529
|
+
checked={formData.useExistingModule}
|
|
530
|
+
onChange={(e) => handleInputChange('useExistingModule', e.target.checked)}
|
|
531
|
+
className="h-4 w-4 text-blue-600 rounded focus:ring-blue-500"
|
|
532
|
+
/>
|
|
533
|
+
<span className="text-sm font-medium text-gray-700">
|
|
534
|
+
Use existing Frigg API module from npm
|
|
535
|
+
</span>
|
|
536
|
+
</label>
|
|
537
|
+
<p className="text-sm text-gray-500 mt-1 ml-7">
|
|
538
|
+
Select from pre-built API modules or create a custom integration from scratch
|
|
539
|
+
</p>
|
|
540
|
+
</div>
|
|
541
|
+
|
|
542
|
+
{formData.useExistingModule && (
|
|
543
|
+
<APIModuleSelector
|
|
544
|
+
selectedModule={formData.selectedModule}
|
|
545
|
+
onSelect={handleModuleSelect}
|
|
546
|
+
/>
|
|
547
|
+
)}
|
|
548
|
+
|
|
549
|
+
{!formData.useExistingModule && (
|
|
550
|
+
<div className="bg-gray-50 rounded-lg p-6 text-center">
|
|
551
|
+
<svg className="w-12 h-12 text-gray-400 mx-auto mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
552
|
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4" />
|
|
553
|
+
</svg>
|
|
554
|
+
<h3 className="text-lg font-medium text-gray-900 mb-2">Custom Integration</h3>
|
|
555
|
+
<p className="text-sm text-gray-600">
|
|
556
|
+
Build a custom integration from scratch with full control over the implementation
|
|
557
|
+
</p>
|
|
558
|
+
</div>
|
|
559
|
+
)}
|
|
560
|
+
</div>
|
|
561
|
+
)}
|
|
562
|
+
|
|
563
|
+
{currentTab === 'basic' && (
|
|
564
|
+
<div className="space-y-4">
|
|
565
|
+
{formData.useExistingModule && formData.selectedModule && (
|
|
566
|
+
<div className="bg-blue-50 border border-blue-200 rounded-lg p-4 mb-4">
|
|
567
|
+
<div className="flex items-start">
|
|
568
|
+
<svg className="w-5 h-5 text-blue-600 mt-0.5 mr-2" fill="currentColor" viewBox="0 0 20 20">
|
|
569
|
+
<path fillRule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clipRule="evenodd" />
|
|
570
|
+
</svg>
|
|
571
|
+
<div>
|
|
572
|
+
<p className="text-sm text-blue-800">
|
|
573
|
+
Using <strong>{formData.moduleDetails?.displayName || formData.selectedModule}</strong> as base module.
|
|
574
|
+
Some fields have been auto-filled from the module configuration.
|
|
575
|
+
</p>
|
|
576
|
+
</div>
|
|
577
|
+
</div>
|
|
578
|
+
</div>
|
|
579
|
+
)}
|
|
580
|
+
|
|
581
|
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
582
|
+
<div>
|
|
583
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
584
|
+
Integration Name *
|
|
585
|
+
</label>
|
|
586
|
+
<input
|
|
587
|
+
type="text"
|
|
588
|
+
value={formData.name}
|
|
589
|
+
onChange={(e) => handleInputChange('name', e.target.value)}
|
|
590
|
+
placeholder="e.g., salesforce, hubspot"
|
|
591
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
592
|
+
disabled={formData.useExistingModule && moduleDetailsLoading}
|
|
593
|
+
/>
|
|
594
|
+
</div>
|
|
595
|
+
<div>
|
|
596
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
597
|
+
Display Name
|
|
598
|
+
</label>
|
|
599
|
+
<input
|
|
600
|
+
type="text"
|
|
601
|
+
value={formData.displayName}
|
|
602
|
+
onChange={(e) => handleInputChange('displayName', e.target.value)}
|
|
603
|
+
placeholder="e.g., Salesforce, HubSpot"
|
|
604
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
605
|
+
/>
|
|
606
|
+
</div>
|
|
607
|
+
</div>
|
|
608
|
+
|
|
609
|
+
<div>
|
|
610
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
611
|
+
Description
|
|
612
|
+
</label>
|
|
613
|
+
<textarea
|
|
614
|
+
value={formData.description}
|
|
615
|
+
onChange={(e) => handleInputChange('description', e.target.value)}
|
|
616
|
+
placeholder="Brief description of the integration"
|
|
617
|
+
rows={3}
|
|
618
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
619
|
+
/>
|
|
620
|
+
</div>
|
|
621
|
+
|
|
622
|
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
623
|
+
<div>
|
|
624
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
625
|
+
Category
|
|
626
|
+
</label>
|
|
627
|
+
<select
|
|
628
|
+
value={formData.category}
|
|
629
|
+
onChange={(e) => handleInputChange('category', e.target.value)}
|
|
630
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
631
|
+
>
|
|
632
|
+
<option value="API Integration">API Integration</option>
|
|
633
|
+
<option value="CRM">CRM</option>
|
|
634
|
+
<option value="Marketing">Marketing</option>
|
|
635
|
+
<option value="Sales">Sales</option>
|
|
636
|
+
<option value="Support">Support</option>
|
|
637
|
+
<option value="Analytics">Analytics</option>
|
|
638
|
+
<option value="Communication">Communication</option>
|
|
639
|
+
<option value="Other">Other</option>
|
|
640
|
+
</select>
|
|
641
|
+
</div>
|
|
642
|
+
<div>
|
|
643
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
644
|
+
Base URL *
|
|
645
|
+
</label>
|
|
646
|
+
<input
|
|
647
|
+
type="url"
|
|
648
|
+
value={formData.baseURL}
|
|
649
|
+
onChange={(e) => handleInputChange('baseURL', e.target.value)}
|
|
650
|
+
placeholder="https://api.example.com"
|
|
651
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
652
|
+
/>
|
|
653
|
+
</div>
|
|
654
|
+
</div>
|
|
655
|
+
</div>
|
|
656
|
+
)}
|
|
657
|
+
|
|
658
|
+
{currentTab === 'auth' && (
|
|
659
|
+
<div className="space-y-4">
|
|
660
|
+
<div>
|
|
661
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
662
|
+
Authentication Type
|
|
663
|
+
</label>
|
|
664
|
+
<select
|
|
665
|
+
value={formData.type}
|
|
666
|
+
onChange={(e) => handleInputChange('type', e.target.value)}
|
|
667
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
668
|
+
>
|
|
669
|
+
<option value={INTEGRATION_TYPES.API}>API Key</option>
|
|
670
|
+
<option value={INTEGRATION_TYPES.OAUTH2}>OAuth 2.0</option>
|
|
671
|
+
<option value={INTEGRATION_TYPES.BASIC_AUTH}>Basic Auth</option>
|
|
672
|
+
<option value={INTEGRATION_TYPES.OAUTH1}>OAuth 1.0</option>
|
|
673
|
+
<option value={INTEGRATION_TYPES.CUSTOM}>Custom</option>
|
|
674
|
+
</select>
|
|
675
|
+
</div>
|
|
676
|
+
|
|
677
|
+
{formData.type === INTEGRATION_TYPES.OAUTH2 && (
|
|
678
|
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
679
|
+
<div>
|
|
680
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
681
|
+
Authorization URL
|
|
682
|
+
</label>
|
|
683
|
+
<input
|
|
684
|
+
type="url"
|
|
685
|
+
value={formData.authorizationURL}
|
|
686
|
+
onChange={(e) => handleInputChange('authorizationURL', e.target.value)}
|
|
687
|
+
placeholder="https://example.com/oauth/authorize"
|
|
688
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
689
|
+
/>
|
|
690
|
+
</div>
|
|
691
|
+
<div>
|
|
692
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
693
|
+
Token URL
|
|
694
|
+
</label>
|
|
695
|
+
<input
|
|
696
|
+
type="url"
|
|
697
|
+
value={formData.tokenURL}
|
|
698
|
+
onChange={(e) => handleInputChange('tokenURL', e.target.value)}
|
|
699
|
+
placeholder="https://example.com/oauth/token"
|
|
700
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
701
|
+
/>
|
|
702
|
+
</div>
|
|
703
|
+
<div className="md:col-span-2">
|
|
704
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
705
|
+
OAuth Scope
|
|
706
|
+
</label>
|
|
707
|
+
<input
|
|
708
|
+
type="text"
|
|
709
|
+
value={formData.scope}
|
|
710
|
+
onChange={(e) => handleInputChange('scope', e.target.value)}
|
|
711
|
+
placeholder="read write"
|
|
712
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
713
|
+
/>
|
|
714
|
+
</div>
|
|
715
|
+
</div>
|
|
716
|
+
)}
|
|
717
|
+
|
|
718
|
+
<div className="bg-gray-50 p-4 rounded-md">
|
|
719
|
+
<h4 className="font-medium text-gray-900 mb-2">Authentication Fields</h4>
|
|
720
|
+
<p className="text-sm text-gray-600 mb-3">
|
|
721
|
+
The following fields will be included in the Entity schema based on your authentication type:
|
|
722
|
+
</p>
|
|
723
|
+
<div className="space-y-2">
|
|
724
|
+
{AUTHENTICATION_FIELDS[formData.type]?.map((field, index) => (
|
|
725
|
+
<div key={index} className="flex items-center justify-between text-sm">
|
|
726
|
+
<span className="font-medium">{field.label}</span>
|
|
727
|
+
<div className="flex items-center space-x-2">
|
|
728
|
+
<span className="text-gray-500">{field.type}</span>
|
|
729
|
+
{field.required && <span className="text-red-500">Required</span>}
|
|
730
|
+
{field.encrypted && <span className="text-blue-500">Encrypted</span>}
|
|
731
|
+
</div>
|
|
732
|
+
</div>
|
|
733
|
+
)) || <span className="text-gray-500">No standard fields for custom authentication</span>}
|
|
734
|
+
</div>
|
|
735
|
+
</div>
|
|
736
|
+
</div>
|
|
737
|
+
)}
|
|
738
|
+
|
|
739
|
+
{currentTab === 'endpoints' && (
|
|
740
|
+
<div className="space-y-4">
|
|
741
|
+
<div className="flex justify-between items-center">
|
|
742
|
+
<h3 className="text-lg font-medium">API Endpoints</h3>
|
|
743
|
+
<Button onClick={handleEndpointAdd}>Add Endpoint</Button>
|
|
744
|
+
</div>
|
|
745
|
+
|
|
746
|
+
{formData.apiEndpoints.length === 0 && (
|
|
747
|
+
<div className="text-center py-8 text-gray-500">
|
|
748
|
+
No endpoints defined. Click "Add Endpoint" to get started.
|
|
749
|
+
</div>
|
|
750
|
+
)}
|
|
751
|
+
|
|
752
|
+
{formData.apiEndpoints.map((endpoint) => (
|
|
753
|
+
<Card key={endpoint.id} className="p-4">
|
|
754
|
+
<div className="flex justify-between items-start mb-4">
|
|
755
|
+
<h4 className="font-medium">Endpoint {endpoint.id}</h4>
|
|
756
|
+
<Button
|
|
757
|
+
variant="outline"
|
|
758
|
+
size="sm"
|
|
759
|
+
onClick={() => handleEndpointRemove(endpoint.id)}
|
|
760
|
+
className="text-red-600 hover:text-red-700"
|
|
761
|
+
>
|
|
762
|
+
Remove
|
|
763
|
+
</Button>
|
|
764
|
+
</div>
|
|
765
|
+
|
|
766
|
+
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
|
767
|
+
<div>
|
|
768
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
769
|
+
Method
|
|
770
|
+
</label>
|
|
771
|
+
<select
|
|
772
|
+
value={endpoint.method}
|
|
773
|
+
onChange={(e) => handleEndpointUpdate(endpoint.id, { method: e.target.value })}
|
|
774
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
775
|
+
>
|
|
776
|
+
<option value="GET">GET</option>
|
|
777
|
+
<option value="POST">POST</option>
|
|
778
|
+
<option value="PUT">PUT</option>
|
|
779
|
+
<option value="DELETE">DELETE</option>
|
|
780
|
+
<option value="PATCH">PATCH</option>
|
|
781
|
+
</select>
|
|
782
|
+
</div>
|
|
783
|
+
<div>
|
|
784
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
785
|
+
Path
|
|
786
|
+
</label>
|
|
787
|
+
<input
|
|
788
|
+
type="text"
|
|
789
|
+
value={endpoint.path}
|
|
790
|
+
onChange={(e) => handleEndpointUpdate(endpoint.id, { path: e.target.value })}
|
|
791
|
+
placeholder="/users"
|
|
792
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
793
|
+
/>
|
|
794
|
+
</div>
|
|
795
|
+
<div>
|
|
796
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
797
|
+
Method Name
|
|
798
|
+
</label>
|
|
799
|
+
<input
|
|
800
|
+
type="text"
|
|
801
|
+
value={endpoint.name}
|
|
802
|
+
onChange={(e) => handleEndpointUpdate(endpoint.id, { name: e.target.value })}
|
|
803
|
+
placeholder="getUsers"
|
|
804
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
805
|
+
/>
|
|
806
|
+
</div>
|
|
807
|
+
</div>
|
|
808
|
+
|
|
809
|
+
<div className="mt-4">
|
|
810
|
+
<label className="block text-sm font-medium text-gray-700 mb-2">
|
|
811
|
+
Description
|
|
812
|
+
</label>
|
|
813
|
+
<input
|
|
814
|
+
type="text"
|
|
815
|
+
value={endpoint.description}
|
|
816
|
+
onChange={(e) => handleEndpointUpdate(endpoint.id, { description: e.target.value })}
|
|
817
|
+
placeholder="Retrieves a list of users"
|
|
818
|
+
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
|
819
|
+
/>
|
|
820
|
+
</div>
|
|
821
|
+
</Card>
|
|
822
|
+
))}
|
|
823
|
+
</div>
|
|
824
|
+
)}
|
|
825
|
+
|
|
826
|
+
{currentTab === 'schema' && (
|
|
827
|
+
<div className="space-y-4">
|
|
828
|
+
<h3 className="text-lg font-medium">Custom Entity Fields</h3>
|
|
829
|
+
<p className="text-sm text-gray-600">
|
|
830
|
+
Add custom fields to store additional data in your integration entity.
|
|
831
|
+
Authentication fields are automatically included.
|
|
832
|
+
</p>
|
|
833
|
+
|
|
834
|
+
<SchemaBuilder
|
|
835
|
+
schema={formData.entitySchema}
|
|
836
|
+
onChange={(schema) => handleInputChange('entitySchema', schema)}
|
|
837
|
+
/>
|
|
838
|
+
</div>
|
|
839
|
+
)}
|
|
840
|
+
</Card>
|
|
841
|
+
|
|
842
|
+
<div className="flex justify-end">
|
|
843
|
+
<Button
|
|
844
|
+
onClick={generateIntegrationCode}
|
|
845
|
+
disabled={!formData.name || (!formData.baseURL && !formData.useExistingModule) || (formData.useExistingModule && !formData.selectedModule)}
|
|
846
|
+
className="bg-blue-600 hover:bg-blue-700"
|
|
847
|
+
>
|
|
848
|
+
Generate Integration Code
|
|
849
|
+
</Button>
|
|
850
|
+
</div>
|
|
851
|
+
</div>
|
|
852
|
+
);
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
export default IntegrationGenerator;
|