@friggframework/devtools 2.0.0--canary.667.a0620c7.0 → 2.0.0--canary.702.d5e6de1.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.
Files changed (87) hide show
  1. package/README.md +1 -0
  2. package/frigg-cli/README.md +76 -78
  3. package/frigg-cli/__tests__/unit/commands/build.test.js +3 -0
  4. package/frigg-cli/__tests__/unit/commands/deploy.test.js +27 -30
  5. package/frigg-cli/__tests__/unit/commands/doctor.test.js +6 -10
  6. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +0 -18
  7. package/frigg-cli/__tests__/unit/commands/install.test.js +341 -601
  8. package/frigg-cli/__tests__/unit/commands/ui.test.js +30 -31
  9. package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +92 -0
  10. package/frigg-cli/__tests__/unit/dependencies.test.js +2 -6
  11. package/frigg-cli/build-command/index.js +6 -0
  12. package/frigg-cli/deploy-command/index.js +6 -0
  13. package/frigg-cli/generate-command/index.js +0 -1
  14. package/frigg-cli/generate-iam-command.js +0 -1
  15. package/frigg-cli/index.js +23 -10
  16. package/frigg-cli/index.test.js +158 -0
  17. package/frigg-cli/init-command/backend-first-handler.js +531 -395
  18. package/frigg-cli/init-command/index.js +35 -82
  19. package/frigg-cli/install-command/commit-changes.js +8 -40
  20. package/frigg-cli/install-command/environment-variables.js +0 -15
  21. package/frigg-cli/install-command/index.js +21 -96
  22. package/frigg-cli/install-command/install-package.js +4 -77
  23. package/frigg-cli/install-command/integration-file.js +11 -20
  24. package/frigg-cli/install-command/template.js +75 -102
  25. package/frigg-cli/install-command/validate-package.js +4 -36
  26. package/frigg-cli/package.json +1 -1
  27. package/frigg-cli/start-command/index.js +4 -0
  28. package/frigg-cli/start-command/start-command.test.js +3 -0
  29. package/frigg-cli/test/init-command.test.js +2 -9
  30. package/frigg-cli/validate-command/__tests__/init-validation.test.js +63 -0
  31. package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +133 -0
  32. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +326 -0
  33. package/frigg-cli/validate-command/__tests__/validate-command.test.js +241 -0
  34. package/frigg-cli/validate-command/__tests__/validate-module-command.test.js +119 -0
  35. package/frigg-cli/validate-command/checks/config.js +468 -0
  36. package/frigg-cli/validate-command/checks/integrations.js +274 -0
  37. package/frigg-cli/validate-command/fixtures/bad-module/index.js +18 -0
  38. package/frigg-cli/validate-command/fixtures/fathom-module/definition.js +76 -0
  39. package/frigg-cli/validate-command/fixtures/fathom-module/index.js +6 -0
  40. package/frigg-cli/validate-command/format-report.js +60 -0
  41. package/frigg-cli/validate-command/index.js +151 -0
  42. package/frigg-cli/validate-command/load-app-definition.js +93 -0
  43. package/frigg-cli/validate-command/load-module-definition.js +64 -0
  44. package/frigg-cli/validate-command/schema-issues.js +154 -0
  45. package/frigg-cli/validate-command/validate-app-definition.js +60 -0
  46. package/frigg-cli/validate-command/validate-module-definition.js +46 -0
  47. package/infrastructure/__tests__/postgres-config.test.js +835 -241
  48. package/infrastructure/__tests__/template-generation.test.js +8 -36
  49. package/infrastructure/app-definition-schema-contract.test.js +607 -0
  50. package/infrastructure/create-frigg-infrastructure.js +4 -1
  51. package/infrastructure/create-frigg-infrastructure.test.js +51 -0
  52. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +60 -118
  53. package/infrastructure/domains/database/aurora-builder.js +2 -13
  54. package/infrastructure/domains/database/aurora-builder.test.js +0 -22
  55. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +8 -12
  56. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +7 -19
  57. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +8 -12
  58. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +18 -17
  59. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +2 -12
  60. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +1 -8
  61. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +2 -4
  62. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +0 -10
  63. package/infrastructure/domains/networking/vpc-builder.js +8 -18
  64. package/infrastructure/domains/networking/vpc-builder.test.js +12 -26
  65. package/infrastructure/domains/security/iam-generator.js +5 -112
  66. package/infrastructure/domains/security/iam-generator.test.js +0 -94
  67. package/infrastructure/domains/shared/cloudformation-discovery.test.js +6 -36
  68. package/infrastructure/domains/shared/utilities/base-definition-factory.js +2 -26
  69. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +1 -34
  70. package/infrastructure/infrastructure-composer.test.js +794 -268
  71. package/infrastructure/integration.test.js +381 -0
  72. package/infrastructure/scripts/build-prisma-layer.test.js +7 -28
  73. package/infrastructure/scripts/build-time-discovery.test.js +3 -18
  74. package/package.json +8 -10
  75. package/frigg-cli/__tests__/unit/commands/init.test.js +0 -688
  76. package/frigg-cli/init-command/deployment-modes.js +0 -7
  77. package/frigg-cli/init-command/safe-path.js +0 -58
  78. package/frigg-cli/init-command/scaffold-dependencies.js +0 -202
  79. package/frigg-cli/install-command/app-definition.js +0 -174
  80. package/frigg-cli/install-command/resolve-module.js +0 -69
  81. package/frigg-cli/templates/backend/README.md +0 -267
  82. package/frigg-cli/templates/backend/env.example +0 -20
  83. package/frigg-cli/templates/backend/gitignore +0 -10
  84. package/frigg-cli/templates/backend/index.js +0 -114
  85. package/frigg-cli/templates/backend/infrastructure.js +0 -20
  86. package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -281
  87. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -148
@@ -1,117 +1,90 @@
1
- /**
2
- * Source for a new integration class (`src/integrations/<Name>Integration.js`)
3
- * that wraps one installed API module.
4
- *
5
- * It follows the current IntegrationBase contract: a static `Definition`
6
- * (name, version, display, `modules: { <key>: { definition } }`) and event
7
- * handlers registered on `this.events` in the constructor. Calls to the API
8
- * module go through `this.<key>.api.<method>()`.
9
- */
1
+ const path = require('path');
10
2
 
11
- /** Turn an arbitrary label (e.g. "Google Drive", "Monday.com") into a JS identifier. */
12
- function toIdentifier(label) {
13
- const words = String(label)
14
- .split(/[^A-Za-z0-9]+/)
15
- .filter(Boolean);
16
- let identifier = words
17
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
18
- .join('');
19
- if (!identifier) {
20
- identifier = 'Module';
21
- }
22
- if (/^[0-9]/.test(identifier)) {
23
- identifier = `Module${identifier}`;
24
- }
25
- return identifier;
26
- }
3
+ function getIntegrationTemplate(apiModuleName, backendPath, ApiClass) {
4
+ // Find the sample data method
5
+ const apiMethods = Object.getOwnPropertyNames(ApiClass.prototype);
6
+ const sampleDataMethod =
7
+ apiMethods.find(
8
+ (method) =>
9
+ method.toLowerCase().includes('search') ||
10
+ method.toLowerCase().includes('list') ||
11
+ method.toLowerCase().includes('get')
12
+ ) || 'searchDeals';
27
13
 
28
- /** camelCase key for `Definition.modules` (e.g. "google-drive" -> "googleDrive"). */
29
- function toModuleKey(moduleName) {
30
- const words = String(moduleName)
31
- .split(/[^A-Za-z0-9]+/)
32
- .filter(Boolean);
33
- if (words.length === 0) {
34
- return 'module';
35
- }
36
- const key = words
37
- .map((word, i) =>
38
- i === 0
39
- ? word.charAt(0).toLowerCase() + word.slice(1)
40
- : word.charAt(0).toUpperCase() + word.slice(1)
41
- )
42
- .join('');
43
- return /^[0-9]/.test(key) ? `module${key}` : key;
44
- }
14
+ return `const { get, IntegrationBase, Options } = require('@friggframework/core');
15
+ const { Definition: ${apiModuleName}Module, Config: defaultConfig } = require('@friggframework/api-module-${apiModuleName.toLowerCase()}');
45
16
 
46
- const quote = (value) => JSON.stringify(value === undefined ? '' : value);
17
+ class ${apiModuleName}Integration extends IntegrationBase {
18
+ static Config = {
19
+ name: defaultConfig.name || '${apiModuleName.toLowerCase()}',
20
+ version: '1.0.0',
21
+ supportedVersions: ['1.0.0'],
22
+ events: ['SEARCH_DEALS'],
23
+ };
47
24
 
48
- /**
49
- * @param {object} params
50
- * @param {string} params.className - e.g. `HubSpotIntegration`
51
- * @param {string} params.packageName - e.g. `@friggframework/api-module-hubspot`
52
- * @param {string} params.moduleName - The module's `Definition.getName()`
53
- * @param {string} params.label - Human-readable name
54
- * @param {string} [params.description]
55
- * @param {string} [params.detailsUrl]
56
- * @param {string} [params.icon]
57
- * @param {string[]} [params.categories]
58
- * @returns {string}
59
- */
60
- function getIntegrationTemplate({
61
- className,
62
- packageName,
63
- moduleName,
64
- label,
65
- description,
66
- detailsUrl,
67
- icon,
68
- categories,
69
- }) {
70
- const moduleKey = toModuleKey(moduleName);
71
- const moduleVar = `${moduleKey}Module`;
72
- const category = Array.isArray(categories) ? categories.join(', ') : '';
25
+ static Options =
26
+ new Options({
27
+ module: ${apiModuleName}Module,
28
+ integrations: [${apiModuleName}Module],
29
+ display: {
30
+ name: defaultConfig.displayName || '${apiModuleName}',
31
+ description: defaultConfig.description || 'Sales & CRM, Marketing',
32
+ category: defaultConfig.category || 'Sales & CRM, Marketing',
33
+ detailsUrl: defaultConfig.detailsUrl || 'https://www.${apiModuleName.toLowerCase()}.com',
34
+ icon: defaultConfig.icon || 'https://friggframework.org/assets/img/${apiModuleName.toLowerCase()}.jpeg',
35
+ },
36
+ hasUserConfig: true,
37
+ });
73
38
 
74
- return `const { IntegrationBase } = require('@friggframework/core');
75
- const ${moduleVar} = require(${quote(packageName)});
39
+ static modules = {
40
+ ${apiModuleName.toLowerCase()}: ${apiModuleName}Module,
41
+ }
76
42
 
77
- class ${className} extends IntegrationBase {
78
- static Definition = {
79
- name: ${quote(moduleName)},
80
- version: '1.0.0',
81
- supportedVersions: ['1.0.0'],
82
- hasUserConfig: false,
43
+ /**
44
+ * HANDLE EVENTS
45
+ */
46
+ async receiveNotification(notifier, event, object = null) {
47
+ if (event === 'SEARCH_DEALS') {
48
+ return this.target.api.searchDeals(object);
49
+ }
50
+ }
83
51
 
84
- display: {
85
- label: ${quote(label)},
86
- description: ${quote(description)},
87
- category: ${quote(category)},
88
- detailsUrl: ${quote(detailsUrl)},
89
- icon: ${quote(icon)},
90
- },
52
+ /**
53
+ * ALL CUSTOM/OPTIONAL METHODS FOR AN INTEGRATION MANAGER
54
+ */
55
+ async getSampleData() {
56
+ const res = await this.target.api.${sampleDataMethod}();
57
+ return { data: res };
58
+ }
91
59
 
92
- // The API modules this integration uses. Each key becomes
93
- // \`this.<key>\` on an integration instance, e.g.
94
- // \`this.${moduleKey}.api\`.
95
- modules: {
96
- ${moduleKey}: { definition: ${moduleVar}.Definition },
97
- },
60
+ /**
61
+ * ALL REQUIRED METHODS FOR AN INTEGRATION MANAGER
62
+ */
63
+ async onCreate(params) {
64
+ // Validate that we have all of the data we need
65
+ // Set integration status as makes sense. Default ENABLED
66
+ // TODO turn this into a validateConfig method/function
67
+ this.record.status = 'ENABLED';
68
+ await this.record.save();
69
+ return this.record;
70
+ }
98
71
 
99
- // HTTP routes, served under /api/${moduleName}-integration/...
100
- // e.g. { path: '/sample', method: 'GET', event: 'GET_SAMPLE_DATA' }
101
- routes: [],
102
- };
72
+ async onUpdate(params) {
73
+ const newConfig = get(params, 'config');
74
+ const oldConfig = this.record.config;
75
+ // Just save whatever
76
+ this.record.markModified('config');
77
+ await this.record.save();
78
+ return this.validateConfig();
79
+ }
103
80
 
104
- constructor(params) {
105
- super(params);
106
- this.events = {
107
- // Map event names to handlers, e.g.
108
- // GET_SAMPLE_DATA: { handler: this.getSampleData.bind(this) },
109
- };
81
+ async getConfigOptions() {
82
+ const options = {}
83
+ return options;
110
84
  }
111
85
  }
112
86
 
113
- module.exports = ${className};
114
- `;
87
+ module.exports = ${apiModuleName}Integration;`;
115
88
  }
116
89
 
117
- module.exports = { getIntegrationTemplate, toIdentifier, toModuleKey };
90
+ module.exports = { getIntegrationTemplate };
@@ -1,28 +1,12 @@
1
- const spawn = require('cross-spawn');
1
+ const { execSync } = require('child_process');
2
2
  const axios = require('axios');
3
3
  const { logError } = require('./logger');
4
4
  const { checkbox } = require('@inquirer/prompts');
5
5
 
6
- const API_MODULE_PREFIX = '@friggframework/api-module-';
7
-
8
6
  async function searchPackages(apiModuleName) {
9
- // Arguments are passed as an array (no shell), so the search term can
10
- // never be interpreted as a command.
11
- const result = spawn.sync(
12
- 'npm',
13
- ['search', `${API_MODULE_PREFIX}${apiModuleName}`, '--json'],
14
- { encoding: 'utf8' }
15
- );
16
- if (result.error) {
17
- throw result.error;
18
- }
19
- if (result.status !== 0) {
20
- throw new Error(`npm search failed: ${result.stderr || result.status}`);
21
- }
22
- // npm search is a full-text search; keep only Frigg API modules.
23
- return JSON.parse(result.stdout || '[]').filter(
24
- (pkg) => pkg && pkg.name && pkg.name.startsWith(API_MODULE_PREFIX)
25
- );
7
+ const searchCommand = `npm search @friggframework/api-module-${apiModuleName} --json`;
8
+ const result = execSync(searchCommand, { encoding: 'utf8' });
9
+ return JSON.parse(result);
26
10
  }
27
11
 
28
12
  async function checkPackageExists(packageName) {
@@ -74,21 +58,6 @@ const searchAndSelectPackage = async (apiModuleName) => {
74
58
  };
75
59
  });
76
60
 
77
- // Without a terminal to prompt on, take the exact match
78
- // (`frigg install hubspot` -> @friggframework/api-module-hubspot).
79
- if (!process.stdin.isTTY) {
80
- const exact = `${API_MODULE_PREFIX}${apiModuleName}`;
81
- if (filteredResults.some((pkg) => pkg.name === exact)) {
82
- return [exact];
83
- }
84
- logError(
85
- `No exact match for ${exact}, and there is no terminal to choose from: ${filteredResults
86
- .map((pkg) => pkg.name)
87
- .join(', ')}`
88
- );
89
- process.exit(1);
90
- }
91
-
92
61
  const selectedPackages = await checkbox({
93
62
  message: 'Select the packages to install:',
94
63
  choices,
@@ -99,7 +68,6 @@ const searchAndSelectPackage = async (apiModuleName) => {
99
68
  };
100
69
 
101
70
  module.exports = {
102
- API_MODULE_PREFIX,
103
71
  validatePackageExists,
104
72
  checkPackageExists,
105
73
  searchPackages,
@@ -26,7 +26,7 @@
26
26
  "lodash": "4.18.1",
27
27
  "node-cache": "^5.1.2",
28
28
  "open": "^8.4.2",
29
- "osls": "^3.78.0",
29
+ "osls": "^3.58.0",
30
30
  "semver": "^7.6.0",
31
31
  "validate-npm-package-name": "^5.0.0"
32
32
  },
@@ -12,6 +12,7 @@ const {
12
12
  getDatabaseTypeNotConfiguredError,
13
13
  getPrismaClientNotGeneratedError
14
14
  } = require('../utils/error-messages');
15
+ const { preflightValidation } = require('../validate-command');
15
16
 
16
17
  async function startCommand(options) {
17
18
  if (options.verbose) {
@@ -25,6 +26,9 @@ async function startCommand(options) {
25
26
  const envPath = path.join(process.cwd(), '.env');
26
27
  dotenv.config({ path: envPath });
27
28
 
29
+ // Validate the app definition (ADR-051); local development only warns.
30
+ preflightValidation({ command: 'start', options, failOnErrors: false });
31
+
28
32
  // Pre-flight database checks
29
33
  try {
30
34
  await performDatabaseChecks(options.verbose);
@@ -23,6 +23,9 @@ jest.mock('node:child_process', () => ({
23
23
  }));
24
24
 
25
25
  jest.mock('../utils/database-validator', () => mockValidator);
26
+ // The app definition validation step is tested in validate-command/.
27
+ jest.mock('../validate-command', () => ({ preflightValidation: jest.fn(() => true) }));
28
+
26
29
  jest.mock('dotenv');
27
30
 
28
31
  const { spawn } = require('node:child_process');
@@ -123,19 +123,12 @@ describe('Init Command', () => {
123
123
  );
124
124
  });
125
125
 
126
- it('forwards every supported init flag to BackendFirstHandler', async () => {
127
- // The flags `frigg init` registers and initCommand forwards
128
- // (see init-command/index.js). `yes` is the non-interactive flag
129
- // (`--yes`: accept defaults, no prompts); `install: false` and
130
- // `git: false` are what `--no-install` / `--no-git` produce. The
131
- // old `frontend` option is gone: init scaffolds a backend only.
126
+ it('should pass options to BackendFirstHandler', async () => {
132
127
  const options = {
133
128
  force: true,
134
129
  verbose: true,
135
130
  mode: 'standalone',
136
- yes: true,
137
- install: false,
138
- git: false
131
+ frontend: false
139
132
  };
140
133
 
141
134
  await initCommand(mockProjectName, options);
@@ -0,0 +1,63 @@
1
+ /**
2
+ * `frigg init` validates the generated app with the same code path as
3
+ * `frigg validate`, and never fails because of it (ADR-051).
4
+ */
5
+ const fs = require('fs');
6
+ const os = require('os');
7
+ const path = require('path');
8
+
9
+ jest.mock('@inquirer/prompts', () => ({}));
10
+
11
+ const BackendFirstHandler = require('../../init-command/backend-first-handler');
12
+
13
+ function writeApp(source) {
14
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-init-'));
15
+ fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"backend"}');
16
+ fs.writeFileSync(path.join(dir, 'index.js'), source);
17
+ return dir;
18
+ }
19
+
20
+ describe('frigg init validation', () => {
21
+ const dirs = [];
22
+ let log;
23
+
24
+ beforeEach(() => {
25
+ log = jest.spyOn(console, 'log').mockImplementation(() => {});
26
+ });
27
+
28
+ afterEach(() => {
29
+ jest.restoreAllMocks();
30
+ for (const dir of dirs.splice(0))
31
+ fs.rmSync(dir, { recursive: true, force: true });
32
+ });
33
+
34
+ it('validates the real generated definition, not a stand-in', async () => {
35
+ const dir = writeApp(
36
+ "module.exports = { Definition: { integrations: [], database: { postgres: { enable: true, management: 'create-new' } } } };"
37
+ );
38
+ dirs.push(dir);
39
+ const handler = new BackendFirstHandler(dir, {});
40
+
41
+ const ok = await handler.validateGeneratedAppDefinition(
42
+ path.join(dir, 'index.js')
43
+ );
44
+
45
+ expect(ok).toBe(false);
46
+ expect(log.mock.calls.flat().join('\n')).toContain(
47
+ '/database/postgres/management'
48
+ );
49
+ });
50
+
51
+ it('stays quiet before npm install, when index.js cannot load its dependencies', async () => {
52
+ const dir = writeApp(
53
+ "require('@friggframework/api-module-does-not-exist');"
54
+ );
55
+ dirs.push(dir);
56
+ const handler = new BackendFirstHandler(dir, {});
57
+
58
+ await expect(
59
+ handler.validateGeneratedAppDefinition(path.join(dir, 'index.js'))
60
+ ).resolves.toBe(true);
61
+ expect(log).not.toHaveBeenCalled();
62
+ });
63
+ });
@@ -0,0 +1,133 @@
1
+ const { checkIntegrations } = require('../checks/integrations');
2
+
3
+ class FakeApi {
4
+ static requesterType = 'oauth2';
5
+ }
6
+
7
+ const moduleDefinition = () => ({
8
+ moduleName: 'acme',
9
+ API: FakeApi,
10
+ requiredAuthMethods: {
11
+ getToken: async () => {},
12
+ getEntityDetails: async () => {},
13
+ getCredentialDetails: async () => {},
14
+ testAuthRequest: async () => {},
15
+ apiPropertiesToPersist: { credential: [], entity: [] },
16
+ },
17
+ });
18
+
19
+ function integrationClass(definition) {
20
+ return class Integration {
21
+ static Definition = definition;
22
+ };
23
+ }
24
+
25
+ const goodIntegration = () =>
26
+ integrationClass({
27
+ name: 'acme',
28
+ version: '1.0.0',
29
+ modules: { acme: { definition: moduleDefinition() } },
30
+ });
31
+
32
+ const codes = (issues) =>
33
+ issues.map((i) => `${i.severity}:${i.code}:${i.pointer}`);
34
+
35
+ describe('checkIntegrations', () => {
36
+ it('accepts a well-formed integration class', () => {
37
+ expect(
38
+ checkIntegrations({ integrations: [goodIntegration()] })
39
+ ).toEqual([]);
40
+ });
41
+
42
+ it('warns when the app lists no integrations', () => {
43
+ expect(codes(checkIntegrations({ integrations: [] }))).toEqual([
44
+ 'warning:no-integrations:/integrations',
45
+ ]);
46
+ });
47
+
48
+ it('rejects an entry that is not a class', () => {
49
+ expect(
50
+ codes(
51
+ checkIntegrations({
52
+ integrations: [{ Definition: { name: 'x' } }],
53
+ })
54
+ )
55
+ ).toEqual(['error:integration-not-a-class:/integrations/0']);
56
+ });
57
+
58
+ it('rejects a class without a static Definition', () => {
59
+ class Bare {}
60
+ expect(codes(checkIntegrations({ integrations: [Bare] }))).toEqual([
61
+ 'error:integration-definition-missing:/integrations/0/Definition',
62
+ ]);
63
+ });
64
+
65
+ it('requires a valid name and modules, and warns on a missing version', () => {
66
+ const Cls = integrationClass({ name: '1 bad name' });
67
+ expect(codes(checkIntegrations({ integrations: [Cls] }))).toEqual([
68
+ 'error:integration-name-invalid:/integrations/0/Definition/name',
69
+ 'warning:integration-version-missing:/integrations/0/Definition/version',
70
+ 'error:integration-modules-missing:/integrations/0/Definition/modules',
71
+ ]);
72
+ });
73
+
74
+ it('reports duplicate integration names', () => {
75
+ expect(
76
+ codes(
77
+ checkIntegrations({
78
+ integrations: [goodIntegration(), goodIntegration()],
79
+ })
80
+ )
81
+ ).toEqual([
82
+ 'error:integration-name-duplicate:/integrations/1/Definition/name',
83
+ ]);
84
+ });
85
+
86
+ it('checks module definitions the way Module.validateDefinition does', () => {
87
+ const definition = moduleDefinition();
88
+ delete definition.requiredAuthMethods.getToken;
89
+ delete definition.moduleName;
90
+ const Cls = integrationClass({
91
+ name: 'acme',
92
+ version: '1',
93
+ modules: { acme: { definition }, other: {} },
94
+ });
95
+
96
+ expect(codes(checkIntegrations({ integrations: [Cls] }))).toEqual([
97
+ 'error:module-name-missing:/integrations/0/Definition/modules/acme/definition/moduleName',
98
+ 'error:module-auth-method-missing:/integrations/0/Definition/modules/acme/definition/requiredAuthMethods/getToken',
99
+ 'error:module-definition-missing:/integrations/0/Definition/modules/other/definition',
100
+ ]);
101
+ });
102
+
103
+ it('does not require getToken for non-OAuth2 modules', () => {
104
+ const definition = moduleDefinition();
105
+ definition.API = class {
106
+ static requesterType = 'apiKey';
107
+ };
108
+ delete definition.requiredAuthMethods.getToken;
109
+ const Cls = integrationClass({
110
+ name: 'acme',
111
+ version: '1',
112
+ modules: { acme: { definition } },
113
+ });
114
+
115
+ expect(checkIntegrations({ integrations: [Cls] })).toEqual([]);
116
+ });
117
+
118
+ it('warns that a module rateLimit is not applied', () => {
119
+ const definition = {
120
+ ...moduleDefinition(),
121
+ rateLimit: { requests: 10, period: 'second' },
122
+ };
123
+ const Cls = integrationClass({
124
+ name: 'acme',
125
+ version: '1',
126
+ modules: { acme: { definition } },
127
+ });
128
+
129
+ expect(codes(checkIntegrations({ integrations: [Cls] }))).toEqual([
130
+ 'warning:module-rate-limit-ignored:/integrations/0/Definition/modules/acme/definition/rateLimit',
131
+ ]);
132
+ });
133
+ });