@friggframework/devtools 2.0.0-next.7 → 2.0.0-next.70
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/README.md +1289 -0
- package/frigg-cli/__tests__/unit/commands/build.test.js +279 -0
- package/frigg-cli/__tests__/unit/commands/db-setup.test.js +649 -0
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +320 -0
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +309 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +400 -0
- package/frigg-cli/__tests__/unit/commands/ui.test.js +346 -0
- package/frigg-cli/__tests__/unit/dependencies.test.js +74 -0
- package/frigg-cli/__tests__/unit/utils/database-validator.test.js +397 -0
- package/frigg-cli/__tests__/unit/utils/error-messages.test.js +345 -0
- package/frigg-cli/__tests__/unit/version-detection.test.js +171 -0
- package/frigg-cli/__tests__/utils/mock-factory.js +270 -0
- package/frigg-cli/__tests__/utils/prisma-mock.js +194 -0
- package/frigg-cli/__tests__/utils/test-fixtures.js +463 -0
- package/frigg-cli/__tests__/utils/test-setup.js +287 -0
- package/frigg-cli/auth-command/CLAUDE.md +293 -0
- package/frigg-cli/auth-command/README.md +450 -0
- package/frigg-cli/auth-command/api-key-flow.js +153 -0
- package/frigg-cli/auth-command/auth-tester.js +344 -0
- package/frigg-cli/auth-command/credential-storage.js +182 -0
- package/frigg-cli/auth-command/index.js +256 -0
- package/frigg-cli/auth-command/json-schema-form.js +67 -0
- package/frigg-cli/auth-command/module-loader.js +172 -0
- package/frigg-cli/auth-command/oauth-callback-server.js +431 -0
- package/frigg-cli/auth-command/oauth-flow.js +195 -0
- package/frigg-cli/auth-command/utils/browser.js +30 -0
- package/frigg-cli/build-command/index.js +45 -12
- package/frigg-cli/db-setup-command/index.js +246 -0
- package/frigg-cli/deploy-command/SPEC-DEPLOY-DRY-RUN.md +981 -0
- package/frigg-cli/deploy-command/index.js +295 -23
- package/frigg-cli/doctor-command/index.js +335 -0
- package/frigg-cli/generate-command/__tests__/generate-command.test.js +301 -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 +118 -0
- package/frigg-cli/index.js +174 -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/jest.config.js +124 -0
- package/frigg-cli/package.json +63 -0
- package/frigg-cli/repair-command/index.js +564 -0
- package/frigg-cli/start-command/index.js +118 -5
- package/frigg-cli/start-command/start-command.test.js +297 -0
- 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/database-validator.js +167 -0
- package/frigg-cli/utils/error-messages.js +329 -0
- 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/ARCHITECTURE.md +487 -0
- package/infrastructure/CLAUDE.md +481 -0
- package/infrastructure/HEALTH.md +468 -0
- package/infrastructure/README.md +522 -0
- package/infrastructure/__tests__/fixtures/mock-aws-resources.js +391 -0
- package/infrastructure/__tests__/helpers/test-utils.js +277 -0
- package/infrastructure/__tests__/postgres-config.test.js +914 -0
- package/infrastructure/__tests__/template-generation.test.js +687 -0
- package/infrastructure/create-frigg-infrastructure.js +129 -20
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +630 -0
- package/infrastructure/docs/PRE-DEPLOYMENT-HEALTH-CHECK-SPEC.md +1317 -0
- package/infrastructure/docs/WEBSOCKET-CONFIGURATION.md +105 -0
- package/infrastructure/docs/deployment-instructions.md +268 -0
- package/infrastructure/docs/generate-iam-command.md +278 -0
- package/infrastructure/docs/iam-policy-templates.md +193 -0
- package/infrastructure/domains/database/aurora-builder.js +809 -0
- package/infrastructure/domains/database/aurora-builder.test.js +950 -0
- package/infrastructure/domains/database/aurora-discovery.js +87 -0
- package/infrastructure/domains/database/aurora-discovery.test.js +188 -0
- package/infrastructure/domains/database/aurora-resolver.js +210 -0
- package/infrastructure/domains/database/aurora-resolver.test.js +347 -0
- package/infrastructure/domains/database/migration-builder.js +701 -0
- package/infrastructure/domains/database/migration-builder.test.js +321 -0
- package/infrastructure/domains/database/migration-resolver.js +163 -0
- package/infrastructure/domains/database/migration-resolver.test.js +337 -0
- package/infrastructure/domains/health/application/ports/IPropertyReconciler.js +164 -0
- package/infrastructure/domains/health/application/ports/IResourceDetector.js +129 -0
- package/infrastructure/domains/health/application/ports/IResourceImporter.js +142 -0
- package/infrastructure/domains/health/application/ports/IStackRepository.js +131 -0
- package/infrastructure/domains/health/application/ports/index.js +26 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/execute-resource-import-use-case.test.js +679 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +167 -0
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +1130 -0
- package/infrastructure/domains/health/application/use-cases/execute-resource-import-use-case.js +221 -0
- package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.js +152 -0
- package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.test.js +343 -0
- package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.js +535 -0
- package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.test.js +376 -0
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.js +213 -0
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +441 -0
- package/infrastructure/domains/health/docs/ACME-DEV-DRIFT-ANALYSIS.md +267 -0
- package/infrastructure/domains/health/docs/BUILD-VS-DEPLOYED-TEMPLATE-ANALYSIS.md +324 -0
- package/infrastructure/domains/health/docs/ORPHAN-DETECTION-ANALYSIS.md +386 -0
- package/infrastructure/domains/health/docs/SPEC-CLEANUP-COMMAND.md +1419 -0
- package/infrastructure/domains/health/docs/TDD-IMPLEMENTATION-SUMMARY.md +391 -0
- package/infrastructure/domains/health/docs/TEMPLATE-COMPARISON-IMPLEMENTATION.md +551 -0
- package/infrastructure/domains/health/domain/entities/issue.js +299 -0
- package/infrastructure/domains/health/domain/entities/issue.test.js +528 -0
- package/infrastructure/domains/health/domain/entities/property-mismatch.js +108 -0
- package/infrastructure/domains/health/domain/entities/property-mismatch.test.js +275 -0
- package/infrastructure/domains/health/domain/entities/resource.js +159 -0
- package/infrastructure/domains/health/domain/entities/resource.test.js +432 -0
- package/infrastructure/domains/health/domain/entities/stack-health-report.js +306 -0
- package/infrastructure/domains/health/domain/entities/stack-health-report.test.js +601 -0
- package/infrastructure/domains/health/domain/services/__tests__/health-score-percentage-based.test.js +380 -0
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +971 -0
- package/infrastructure/domains/health/domain/services/__tests__/import-template-generator.test.js +1150 -0
- package/infrastructure/domains/health/domain/services/__tests__/logical-id-mapper.test.js +672 -0
- package/infrastructure/domains/health/domain/services/__tests__/template-parser.test.js +496 -0
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +419 -0
- package/infrastructure/domains/health/domain/services/health-score-calculator.js +248 -0
- package/infrastructure/domains/health/domain/services/health-score-calculator.test.js +504 -0
- package/infrastructure/domains/health/domain/services/import-progress-monitor.js +195 -0
- package/infrastructure/domains/health/domain/services/import-template-generator.js +435 -0
- package/infrastructure/domains/health/domain/services/logical-id-mapper.js +345 -0
- package/infrastructure/domains/health/domain/services/mismatch-analyzer.js +234 -0
- package/infrastructure/domains/health/domain/services/mismatch-analyzer.test.js +431 -0
- package/infrastructure/domains/health/domain/services/property-mutability-config.js +382 -0
- package/infrastructure/domains/health/domain/services/template-parser.js +245 -0
- package/infrastructure/domains/health/domain/services/update-progress-monitor.js +192 -0
- package/infrastructure/domains/health/domain/value-objects/health-score.js +138 -0
- package/infrastructure/domains/health/domain/value-objects/health-score.test.js +267 -0
- package/infrastructure/domains/health/domain/value-objects/property-mutability.js +161 -0
- package/infrastructure/domains/health/domain/value-objects/property-mutability.test.js +198 -0
- package/infrastructure/domains/health/domain/value-objects/resource-state.js +167 -0
- package/infrastructure/domains/health/domain/value-objects/resource-state.test.js +196 -0
- package/infrastructure/domains/health/domain/value-objects/stack-identifier.js +192 -0
- package/infrastructure/domains/health/domain/value-objects/stack-identifier.test.js +262 -0
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-cfn-tagged.test.js +312 -0
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-multi-stack.test.js +367 -0
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +432 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.js +784 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +1133 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.js +565 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +554 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.js +318 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.test.js +398 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.js +777 -0
- package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.test.js +580 -0
- package/infrastructure/domains/integration/integration-builder.js +404 -0
- package/infrastructure/domains/integration/integration-builder.test.js +690 -0
- package/infrastructure/domains/integration/integration-resolver.js +170 -0
- package/infrastructure/domains/integration/integration-resolver.test.js +369 -0
- package/infrastructure/domains/integration/websocket-builder.js +69 -0
- package/infrastructure/domains/integration/websocket-builder.test.js +195 -0
- package/infrastructure/domains/networking/vpc-builder.js +2051 -0
- package/infrastructure/domains/networking/vpc-builder.test.js +1960 -0
- package/infrastructure/domains/networking/vpc-discovery.js +177 -0
- package/infrastructure/domains/networking/vpc-discovery.test.js +350 -0
- package/infrastructure/domains/networking/vpc-resolver.js +505 -0
- package/infrastructure/domains/networking/vpc-resolver.test.js +801 -0
- package/infrastructure/domains/parameters/ssm-builder.js +79 -0
- package/infrastructure/domains/parameters/ssm-builder.test.js +189 -0
- package/infrastructure/domains/parameters/ssm-discovery.js +84 -0
- package/infrastructure/domains/parameters/ssm-discovery.test.js +210 -0
- package/infrastructure/domains/scheduler/scheduler-builder.js +211 -0
- package/infrastructure/domains/security/iam-generator.js +816 -0
- package/infrastructure/domains/security/iam-generator.test.js +204 -0
- package/infrastructure/domains/security/kms-builder.js +415 -0
- package/infrastructure/domains/security/kms-builder.test.js +392 -0
- package/infrastructure/domains/security/kms-discovery.js +80 -0
- package/infrastructure/domains/security/kms-discovery.test.js +177 -0
- package/infrastructure/domains/security/kms-resolver.js +96 -0
- package/infrastructure/domains/security/kms-resolver.test.js +216 -0
- package/infrastructure/domains/security/templates/frigg-deployment-iam-stack.yaml +401 -0
- package/infrastructure/domains/security/templates/iam-policy-basic.json +218 -0
- package/infrastructure/domains/security/templates/iam-policy-full.json +288 -0
- package/infrastructure/domains/shared/base-builder.js +112 -0
- package/infrastructure/domains/shared/base-resolver.js +186 -0
- package/infrastructure/domains/shared/base-resolver.test.js +305 -0
- package/infrastructure/domains/shared/builder-orchestrator.js +212 -0
- package/infrastructure/domains/shared/builder-orchestrator.test.js +213 -0
- package/infrastructure/domains/shared/cloudformation-discovery-v2.js +334 -0
- package/infrastructure/domains/shared/cloudformation-discovery.js +672 -0
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +985 -0
- package/infrastructure/domains/shared/environment-builder.js +119 -0
- package/infrastructure/domains/shared/environment-builder.test.js +247 -0
- package/infrastructure/domains/shared/providers/aws-provider-adapter.js +579 -0
- package/infrastructure/domains/shared/providers/aws-provider-adapter.test.js +416 -0
- package/infrastructure/domains/shared/providers/azure-provider-adapter.stub.js +93 -0
- package/infrastructure/domains/shared/providers/cloud-provider-adapter.js +136 -0
- package/infrastructure/domains/shared/providers/gcp-provider-adapter.stub.js +82 -0
- package/infrastructure/domains/shared/providers/provider-factory.js +108 -0
- package/infrastructure/domains/shared/providers/provider-factory.test.js +170 -0
- package/infrastructure/domains/shared/resource-discovery.enhanced.test.js +306 -0
- package/infrastructure/domains/shared/resource-discovery.js +233 -0
- package/infrastructure/domains/shared/resource-discovery.test.js +588 -0
- package/infrastructure/domains/shared/types/app-definition.js +205 -0
- package/infrastructure/domains/shared/types/discovery-result.js +106 -0
- package/infrastructure/domains/shared/types/discovery-result.test.js +258 -0
- package/infrastructure/domains/shared/types/index.js +46 -0
- package/infrastructure/domains/shared/types/resource-ownership.js +108 -0
- package/infrastructure/domains/shared/types/resource-ownership.test.js +101 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +408 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js.bak +338 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +291 -0
- package/infrastructure/domains/shared/utilities/handler-path-resolver.js +134 -0
- package/infrastructure/domains/shared/utilities/handler-path-resolver.test.js +268 -0
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +159 -0
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +444 -0
- package/infrastructure/domains/shared/validation/env-validator.js +78 -0
- package/infrastructure/domains/shared/validation/env-validator.test.js +173 -0
- package/infrastructure/domains/shared/validation/plugin-validator.js +187 -0
- package/infrastructure/domains/shared/validation/plugin-validator.test.js +323 -0
- package/infrastructure/esbuild.config.js +53 -0
- package/infrastructure/infrastructure-composer.js +119 -0
- package/infrastructure/infrastructure-composer.test.js +1895 -0
- package/infrastructure/integration.test.js +383 -0
- package/infrastructure/scripts/build-prisma-layer.js +701 -0
- package/infrastructure/scripts/build-prisma-layer.test.js +170 -0
- package/infrastructure/scripts/build-time-discovery.js +238 -0
- package/infrastructure/scripts/build-time-discovery.test.js +379 -0
- package/infrastructure/scripts/run-discovery.js +110 -0
- package/infrastructure/scripts/verify-prisma-layer.js +72 -0
- package/management-ui/README.md +203 -0
- package/package.json +44 -14
- package/test/index.js +2 -4
- package/test/mock-api.js +1 -3
- package/test/mock-integration.js +4 -14
- package/.eslintrc.json +0 -3
- package/CHANGELOG.md +0 -132
- package/infrastructure/app-handler-helpers.js +0 -57
- package/infrastructure/backend-utils.js +0 -87
- package/infrastructure/routers/auth.js +0 -26
- package/infrastructure/routers/integration-defined-routers.js +0 -42
- 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/serverless-template.js +0 -291
- package/infrastructure/workers/integration-defined-workers.js +0 -24
- package/test/auther-definition-tester.js +0 -125
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
const chalk = require('chalk');
|
|
2
|
+
|
|
3
|
+
async function runAuthTests(definition, ApiClass, credentials, options) {
|
|
4
|
+
console.log(chalk.blue('\n🧪 Running Authentication Tests\n'));
|
|
5
|
+
|
|
6
|
+
const moduleName = definition.moduleName || definition.getName?.() || 'unknown';
|
|
7
|
+
const results = {
|
|
8
|
+
testAuthRequest: { status: 'pending' },
|
|
9
|
+
getEntityDetails: { status: 'pending' },
|
|
10
|
+
getCredentialDetails: { status: 'pending' },
|
|
11
|
+
tokenRefresh: { status: 'pending' },
|
|
12
|
+
credentialProps: { set: 0, total: 0 },
|
|
13
|
+
entityProps: { set: 0, total: 0 },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// 1. Create fresh API instance with credentials
|
|
17
|
+
const apiParams = {
|
|
18
|
+
...definition.env,
|
|
19
|
+
...credentials.tokens,
|
|
20
|
+
...credentials.apiParams,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const api = new ApiClass(apiParams);
|
|
24
|
+
|
|
25
|
+
// If API key, set it
|
|
26
|
+
if (credentials.apiKey) {
|
|
27
|
+
if (typeof api.setApiKey === 'function') {
|
|
28
|
+
api.setApiKey(credentials.apiKey);
|
|
29
|
+
} else {
|
|
30
|
+
api.api_key = credentials.apiKey;
|
|
31
|
+
api.access_token = credentials.apiKey;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 2. Run testAuthRequest
|
|
36
|
+
console.log(chalk.gray('1. Running testAuthRequest...'));
|
|
37
|
+
try {
|
|
38
|
+
let testResult;
|
|
39
|
+
if (definition.requiredAuthMethods?.testAuthRequest) {
|
|
40
|
+
testResult = await definition.requiredAuthMethods.testAuthRequest(api);
|
|
41
|
+
} else {
|
|
42
|
+
testResult = await tryCommonTestMethods(api);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
console.log(chalk.green(' ✓ testAuthRequest passed'));
|
|
46
|
+
results.testAuthRequest = { status: 'passed' };
|
|
47
|
+
|
|
48
|
+
if (options.verbose && testResult) {
|
|
49
|
+
console.log(chalk.gray(' Response preview:'));
|
|
50
|
+
const preview = JSON.stringify(testResult, null, 2);
|
|
51
|
+
const truncated = preview.length > 500 ? preview.slice(0, 500) + '\n ...' : preview;
|
|
52
|
+
console.log(chalk.gray(' ' + truncated.split('\n').join('\n ')));
|
|
53
|
+
}
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.log(chalk.red(' ✗ testAuthRequest failed'));
|
|
56
|
+
console.log(chalk.red(` Error: ${error.message}`));
|
|
57
|
+
results.testAuthRequest = { status: 'failed', error: error.message };
|
|
58
|
+
if (options.verbose && error.stack) {
|
|
59
|
+
console.log(chalk.gray(` Stack: ${error.stack.split('\n').slice(1, 4).join('\n ')}`));
|
|
60
|
+
}
|
|
61
|
+
throw new Error(`Authentication test failed: ${error.message}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 3. Test getEntityDetails
|
|
65
|
+
console.log(chalk.gray('\n2. Testing getEntityDetails...'));
|
|
66
|
+
const entityResult = await testGetEntityDetails(definition, api, credentials, options);
|
|
67
|
+
if (entityResult.skipped) {
|
|
68
|
+
console.log(chalk.yellow(` ⚠ Skipped (${entityResult.reason})`));
|
|
69
|
+
results.getEntityDetails = { status: 'skipped', reason: entityResult.reason };
|
|
70
|
+
} else if (entityResult.error) {
|
|
71
|
+
console.log(chalk.red(` ✗ Failed: ${entityResult.error}`));
|
|
72
|
+
results.getEntityDetails = { status: 'failed', error: entityResult.error };
|
|
73
|
+
} else if (!entityResult.consistent) {
|
|
74
|
+
console.log(chalk.yellow(` ⚠ Entity mismatch (saved: ${entityResult.savedId}, fresh: ${entityResult.freshId})`));
|
|
75
|
+
results.getEntityDetails = { status: 'warning', message: 'entity mismatch' };
|
|
76
|
+
} else {
|
|
77
|
+
console.log(chalk.green(` ✓ getEntityDetails returned consistent entity${entityResult.freshId ? ` (externalId: ${entityResult.freshId})` : ''}`));
|
|
78
|
+
results.getEntityDetails = { status: 'passed' };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 4. Test getCredentialDetails
|
|
82
|
+
console.log(chalk.gray('\n3. Testing getCredentialDetails...'));
|
|
83
|
+
const credResult = await testGetCredentialDetails(definition, api, options);
|
|
84
|
+
if (credResult.skipped) {
|
|
85
|
+
console.log(chalk.yellow(` ⚠ Skipped (${credResult.reason})`));
|
|
86
|
+
results.getCredentialDetails = { status: 'skipped', reason: credResult.reason };
|
|
87
|
+
} else if (credResult.error) {
|
|
88
|
+
console.log(chalk.red(` ✗ Failed: ${credResult.error}`));
|
|
89
|
+
results.getCredentialDetails = { status: 'failed', error: credResult.error };
|
|
90
|
+
} else if (!credResult.valid) {
|
|
91
|
+
console.log(chalk.yellow(' ⚠ getCredentialDetails did not return valid identifiers'));
|
|
92
|
+
results.getCredentialDetails = { status: 'warning', message: 'invalid structure' };
|
|
93
|
+
} else {
|
|
94
|
+
console.log(chalk.green(' ✓ getCredentialDetails returned valid identifiers'));
|
|
95
|
+
results.getCredentialDetails = { status: 'passed' };
|
|
96
|
+
if (options.verbose && credResult.credentials?.identifiers) {
|
|
97
|
+
const ids = credResult.credentials.identifiers;
|
|
98
|
+
console.log(chalk.gray(` Identifiers: ${JSON.stringify(ids)}`));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 5. Test token refresh
|
|
103
|
+
console.log(chalk.gray('\n4. Testing token refresh...'));
|
|
104
|
+
const refreshResult = await testTokenRefresh(api, credentials, options);
|
|
105
|
+
if (refreshResult.skipped) {
|
|
106
|
+
console.log(chalk.yellow(` ⚠ Skipped (${refreshResult.reason})`));
|
|
107
|
+
results.tokenRefresh = { status: 'skipped', reason: refreshResult.reason };
|
|
108
|
+
} else if (refreshResult.error) {
|
|
109
|
+
console.log(chalk.red(` ✗ Failed: ${refreshResult.error}`));
|
|
110
|
+
results.tokenRefresh = { status: 'failed', error: refreshResult.error };
|
|
111
|
+
} else {
|
|
112
|
+
const tokenMsg = refreshResult.tokenChanged ? 'token refreshed successfully' : 'refresh called but token unchanged';
|
|
113
|
+
console.log(chalk.green(` ✓ ${tokenMsg}`));
|
|
114
|
+
results.tokenRefresh = { status: 'passed', tokenChanged: refreshResult.tokenChanged };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 6. Verify credential persistence properties
|
|
118
|
+
console.log(chalk.gray('\n5. Verifying credential properties (apiPropertiesToPersist.credential)...'));
|
|
119
|
+
const credProps = definition.requiredAuthMethods?.apiPropertiesToPersist?.credential || [];
|
|
120
|
+
results.credentialProps.total = credProps.length;
|
|
121
|
+
|
|
122
|
+
if (credProps.length === 0) {
|
|
123
|
+
console.log(chalk.gray(' (no credential properties defined)'));
|
|
124
|
+
} else {
|
|
125
|
+
for (const prop of credProps) {
|
|
126
|
+
const value = api[prop];
|
|
127
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
128
|
+
console.log(chalk.green(` ✓ ${prop}: ${maskSensitive(prop, value)}`));
|
|
129
|
+
results.credentialProps.set++;
|
|
130
|
+
} else {
|
|
131
|
+
console.log(chalk.yellow(` ⚠ ${prop}: not set or empty`));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 7. Verify entity persistence properties
|
|
137
|
+
console.log(chalk.gray('\n6. Verifying entity properties (apiPropertiesToPersist.entity)...'));
|
|
138
|
+
const entityProps = definition.requiredAuthMethods?.apiPropertiesToPersist?.entity || [];
|
|
139
|
+
results.entityProps.total = entityProps.length;
|
|
140
|
+
|
|
141
|
+
if (entityProps.length === 0) {
|
|
142
|
+
console.log(chalk.gray(' (no entity properties defined)'));
|
|
143
|
+
} else {
|
|
144
|
+
for (const prop of entityProps) {
|
|
145
|
+
const value = api[prop];
|
|
146
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
147
|
+
console.log(chalk.green(` ✓ ${prop}: ${maskSensitive(prop, value)}`));
|
|
148
|
+
results.entityProps.set++;
|
|
149
|
+
} else {
|
|
150
|
+
console.log(chalk.yellow(` ⚠ ${prop}: not set or empty`));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 8. Summary
|
|
156
|
+
console.log(chalk.blue('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'));
|
|
157
|
+
console.log(chalk.blue('Summary'));
|
|
158
|
+
console.log(chalk.blue('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'));
|
|
159
|
+
|
|
160
|
+
printSummaryLine('testAuthRequest', results.testAuthRequest);
|
|
161
|
+
printSummaryLine('getEntityDetails', results.getEntityDetails);
|
|
162
|
+
printSummaryLine('getCredentialDetails', results.getCredentialDetails);
|
|
163
|
+
printSummaryLine('tokenRefresh', results.tokenRefresh);
|
|
164
|
+
|
|
165
|
+
const credPropsStatus = results.credentialProps.total === 0
|
|
166
|
+
? chalk.gray('n/a')
|
|
167
|
+
: (results.credentialProps.set === results.credentialProps.total
|
|
168
|
+
? chalk.green(`${results.credentialProps.set}/${results.credentialProps.total} set`)
|
|
169
|
+
: chalk.yellow(`${results.credentialProps.set}/${results.credentialProps.total} set`));
|
|
170
|
+
console.log(` credentialProps: ${credPropsStatus}`);
|
|
171
|
+
|
|
172
|
+
const entityPropsStatus = results.entityProps.total === 0
|
|
173
|
+
? chalk.gray('n/a')
|
|
174
|
+
: (results.entityProps.set === results.entityProps.total
|
|
175
|
+
? chalk.green(`${results.entityProps.set}/${results.entityProps.total} set`)
|
|
176
|
+
: chalk.yellow(`${results.entityProps.set}/${results.entityProps.total} set`));
|
|
177
|
+
console.log(` entityProps: ${entityPropsStatus}`);
|
|
178
|
+
|
|
179
|
+
console.log('');
|
|
180
|
+
|
|
181
|
+
// Check if any critical tests failed
|
|
182
|
+
const criticalFailed = results.testAuthRequest.status === 'failed';
|
|
183
|
+
if (criticalFailed) {
|
|
184
|
+
throw new Error('Critical authentication tests failed');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
console.log(chalk.green('✓ All authentication tests passed'));
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
testAuthRequestPassed: results.testAuthRequest.status === 'passed',
|
|
191
|
+
getEntityDetailsPassed: results.getEntityDetails.status === 'passed',
|
|
192
|
+
getCredentialDetailsPassed: results.getCredentialDetails.status === 'passed',
|
|
193
|
+
tokenRefreshPassed: results.tokenRefresh.status === 'passed',
|
|
194
|
+
credentialPropertiesValid: results.credentialProps.set === results.credentialProps.total,
|
|
195
|
+
entityPropertiesValid: results.entityProps.set === results.entityProps.total,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function printSummaryLine(name, result) {
|
|
200
|
+
const paddedName = (name + ':').padEnd(22);
|
|
201
|
+
let statusText;
|
|
202
|
+
|
|
203
|
+
switch (result.status) {
|
|
204
|
+
case 'passed':
|
|
205
|
+
statusText = chalk.green('✓ passed');
|
|
206
|
+
break;
|
|
207
|
+
case 'failed':
|
|
208
|
+
statusText = chalk.red('✗ failed');
|
|
209
|
+
break;
|
|
210
|
+
case 'skipped':
|
|
211
|
+
statusText = chalk.yellow(`⚠ skipped${result.reason ? ` (${result.reason})` : ''}`);
|
|
212
|
+
break;
|
|
213
|
+
case 'warning':
|
|
214
|
+
statusText = chalk.yellow(`⚠ ${result.message || 'warning'}`);
|
|
215
|
+
break;
|
|
216
|
+
default:
|
|
217
|
+
statusText = chalk.gray('pending');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
console.log(` ${paddedName}${statusText}`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async function testGetEntityDetails(definition, api, savedCredentials, options) {
|
|
224
|
+
if (!definition.requiredAuthMethods?.getEntityDetails) {
|
|
225
|
+
return { skipped: true, reason: 'not defined' };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
const freshEntity = await definition.requiredAuthMethods.getEntityDetails(
|
|
230
|
+
api,
|
|
231
|
+
{}, // callbackParams
|
|
232
|
+
{}, // tokenResponse
|
|
233
|
+
'cli-test-user'
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
const savedId = savedCredentials.entity?.identifiers?.externalId;
|
|
237
|
+
const freshId = freshEntity?.identifiers?.externalId;
|
|
238
|
+
const consistent = !savedId || !freshId || savedId === freshId;
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
success: true,
|
|
242
|
+
consistent,
|
|
243
|
+
freshId,
|
|
244
|
+
savedId,
|
|
245
|
+
freshEntity
|
|
246
|
+
};
|
|
247
|
+
} catch (error) {
|
|
248
|
+
return { error: error.message };
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
async function testGetCredentialDetails(definition, api, options) {
|
|
253
|
+
if (!definition.requiredAuthMethods?.getCredentialDetails) {
|
|
254
|
+
return { skipped: true, reason: 'not defined' };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
try {
|
|
258
|
+
const credentials = await definition.requiredAuthMethods.getCredentialDetails(
|
|
259
|
+
api,
|
|
260
|
+
'cli-test-user'
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
const valid = credentials && typeof credentials.identifiers === 'object';
|
|
264
|
+
return { success: true, valid, credentials };
|
|
265
|
+
} catch (error) {
|
|
266
|
+
return { error: error.message };
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async function testTokenRefresh(api, savedCredentials, options) {
|
|
271
|
+
// Check if refresh token exists
|
|
272
|
+
if (!savedCredentials.tokens?.refresh_token) {
|
|
273
|
+
return { skipped: true, reason: 'no refresh token' };
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Check if API supports refresh
|
|
277
|
+
if (typeof api.refreshAccessToken !== 'function') {
|
|
278
|
+
return { skipped: true, reason: 'refreshAccessToken not implemented' };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
try {
|
|
282
|
+
const oldToken = api.access_token;
|
|
283
|
+
await api.refreshAccessToken({ refresh_token: api.refresh_token });
|
|
284
|
+
const newToken = api.access_token;
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
success: true,
|
|
288
|
+
tokenChanged: newToken !== oldToken
|
|
289
|
+
};
|
|
290
|
+
} catch (error) {
|
|
291
|
+
return { error: error.message };
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async function tryCommonTestMethods(api) {
|
|
296
|
+
const methodsToTry = [
|
|
297
|
+
'getUserDetails',
|
|
298
|
+
'getUser',
|
|
299
|
+
'getCurrentUser',
|
|
300
|
+
'getMe',
|
|
301
|
+
'getAccount',
|
|
302
|
+
'getProfile',
|
|
303
|
+
];
|
|
304
|
+
|
|
305
|
+
for (const method of methodsToTry) {
|
|
306
|
+
if (typeof api[method] === 'function') {
|
|
307
|
+
return await api[method]();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
throw new Error('No testAuthRequest method defined and no common test methods available');
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function maskSensitive(prop, value) {
|
|
315
|
+
const sensitiveProps = [
|
|
316
|
+
'access_token',
|
|
317
|
+
'refresh_token',
|
|
318
|
+
'api_key',
|
|
319
|
+
'apiKey',
|
|
320
|
+
'client_secret',
|
|
321
|
+
'password',
|
|
322
|
+
'secret',
|
|
323
|
+
'token',
|
|
324
|
+
];
|
|
325
|
+
|
|
326
|
+
const propLower = prop.toLowerCase();
|
|
327
|
+
const isSensitive = sensitiveProps.some(sp => propLower.includes(sp.toLowerCase()));
|
|
328
|
+
|
|
329
|
+
if (isSensitive && typeof value === 'string') {
|
|
330
|
+
if (value.length <= 8) {
|
|
331
|
+
return '***';
|
|
332
|
+
}
|
|
333
|
+
return value.slice(0, 4) + '...' + value.slice(-4);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const strValue = String(value);
|
|
337
|
+
if (strValue.length > 50) {
|
|
338
|
+
return strValue.slice(0, 47) + '...';
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return strValue;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
module.exports = { runAuthTests };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
class CredentialStorage {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
// Global storage in user home directory
|
|
8
|
+
this.globalPath = path.join(os.homedir(), '.frigg-credentials.json');
|
|
9
|
+
// Project-local storage (if in a Frigg project)
|
|
10
|
+
this.localPath = path.join(process.cwd(), '.frigg-credentials.json');
|
|
11
|
+
// Allow override via options
|
|
12
|
+
this.customPath = options.path || null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getStoragePath() {
|
|
16
|
+
// Priority: custom > local (if exists) > global
|
|
17
|
+
if (this.customPath) {
|
|
18
|
+
return this.customPath;
|
|
19
|
+
}
|
|
20
|
+
if (fs.existsSync(this.localPath)) {
|
|
21
|
+
return this.localPath;
|
|
22
|
+
}
|
|
23
|
+
return this.globalPath;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getWritePath() {
|
|
27
|
+
// Priority: custom > local (if in project) > global
|
|
28
|
+
if (this.customPath) {
|
|
29
|
+
return this.customPath;
|
|
30
|
+
}
|
|
31
|
+
if (this.isInProject()) {
|
|
32
|
+
return this.localPath;
|
|
33
|
+
}
|
|
34
|
+
return this.globalPath;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async load() {
|
|
38
|
+
const filePath = this.getStoragePath();
|
|
39
|
+
|
|
40
|
+
if (!fs.existsSync(filePath)) {
|
|
41
|
+
return {
|
|
42
|
+
_meta: {
|
|
43
|
+
version: 1,
|
|
44
|
+
warning: 'DO NOT COMMIT THIS FILE - contains sensitive credentials'
|
|
45
|
+
},
|
|
46
|
+
modules: {}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
52
|
+
return JSON.parse(content);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.warn(`Warning: Could not read credentials file: ${err.message}`);
|
|
55
|
+
return { _meta: { version: 1 }, modules: {} };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async save(moduleName, credentials, authType) {
|
|
60
|
+
const data = await this.load();
|
|
61
|
+
|
|
62
|
+
data.modules[moduleName] = {
|
|
63
|
+
...credentials,
|
|
64
|
+
authType,
|
|
65
|
+
savedAt: new Date().toISOString(),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const targetPath = this.getWritePath();
|
|
69
|
+
|
|
70
|
+
// Ensure directory exists
|
|
71
|
+
const dir = path.dirname(targetPath);
|
|
72
|
+
if (!fs.existsSync(dir)) {
|
|
73
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
fs.writeFileSync(targetPath, JSON.stringify(data, null, 2));
|
|
77
|
+
|
|
78
|
+
// Add to .gitignore if saving locally
|
|
79
|
+
if (targetPath === this.localPath) {
|
|
80
|
+
this.ensureGitIgnore();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return targetPath;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async get(moduleName) {
|
|
87
|
+
const data = await this.load();
|
|
88
|
+
return data.modules[moduleName] || null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async list() {
|
|
92
|
+
const data = await this.load();
|
|
93
|
+
return Object.entries(data.modules).map(([name, creds]) => ({
|
|
94
|
+
module: name,
|
|
95
|
+
authType: creds.authType,
|
|
96
|
+
savedAt: creds.savedAt,
|
|
97
|
+
entity: creds.entity?.details?.name || creds.entity?.identifiers?.externalId || 'Unknown',
|
|
98
|
+
hasAccessToken: !!(creds.tokens?.access_token || creds.apiKey),
|
|
99
|
+
hasRefreshToken: !!creds.tokens?.refresh_token,
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async delete(moduleName) {
|
|
104
|
+
const data = await this.load();
|
|
105
|
+
|
|
106
|
+
if (!data.modules[moduleName]) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
delete data.modules[moduleName];
|
|
111
|
+
|
|
112
|
+
const targetPath = this.getStoragePath();
|
|
113
|
+
fs.writeFileSync(targetPath, JSON.stringify(data, null, 2));
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async deleteAll() {
|
|
118
|
+
const data = {
|
|
119
|
+
_meta: {
|
|
120
|
+
version: 1,
|
|
121
|
+
warning: 'DO NOT COMMIT THIS FILE - contains sensitive credentials'
|
|
122
|
+
},
|
|
123
|
+
modules: {}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const targetPath = this.getStoragePath();
|
|
127
|
+
fs.writeFileSync(targetPath, JSON.stringify(data, null, 2));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
isInProject() {
|
|
131
|
+
// Check for indicators of a Frigg project
|
|
132
|
+
const indicators = [
|
|
133
|
+
path.join(process.cwd(), 'backend', 'index.js'),
|
|
134
|
+
path.join(process.cwd(), 'infrastructure.js'),
|
|
135
|
+
path.join(process.cwd(), 'backend', 'infrastructure.js'),
|
|
136
|
+
path.join(process.cwd(), 'package.json'),
|
|
137
|
+
];
|
|
138
|
+
|
|
139
|
+
for (const indicator of indicators) {
|
|
140
|
+
if (fs.existsSync(indicator)) {
|
|
141
|
+
// Additional check: look for frigg-related content in package.json
|
|
142
|
+
if (indicator.endsWith('package.json')) {
|
|
143
|
+
try {
|
|
144
|
+
const pkg = JSON.parse(fs.readFileSync(indicator, 'utf8'));
|
|
145
|
+
if (pkg.dependencies?.['@friggframework/core'] ||
|
|
146
|
+
pkg.devDependencies?.['@friggframework/core'] ||
|
|
147
|
+
pkg.name?.includes('frigg')) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
} catch {
|
|
151
|
+
// Ignore parse errors
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
ensureGitIgnore() {
|
|
163
|
+
const gitignorePath = path.join(process.cwd(), '.gitignore');
|
|
164
|
+
const entry = '.frigg-credentials.json';
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
if (fs.existsSync(gitignorePath)) {
|
|
168
|
+
const content = fs.readFileSync(gitignorePath, 'utf8');
|
|
169
|
+
if (!content.includes(entry)) {
|
|
170
|
+
fs.appendFileSync(gitignorePath, `\n# Frigg auth credentials (DO NOT COMMIT)\n${entry}\n`);
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
// Create new .gitignore
|
|
174
|
+
fs.writeFileSync(gitignorePath, `# Frigg auth credentials (DO NOT COMMIT)\n${entry}\n`);
|
|
175
|
+
}
|
|
176
|
+
} catch (err) {
|
|
177
|
+
console.warn(`Warning: Could not update .gitignore: ${err.message}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
module.exports = { CredentialStorage };
|