@nordcraft/search 1.0.19 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rules/apis/invalidApiProxyBodySettingRule.js +22 -0
- package/dist/rules/apis/invalidApiProxyBodySettingRule.js.map +1 -0
- package/dist/rules/apis/invalidApiProxyBodySettingRule.test.js +73 -0
- package/dist/rules/apis/invalidApiProxyBodySettingRule.test.js.map +1 -0
- package/dist/rules/components/noReferenceComponentRule.js +4 -2
- package/dist/rules/components/noReferenceComponentRule.js.map +1 -1
- package/dist/rules/components/noReferenceComponentRule.test.js +66 -0
- package/dist/rules/components/noReferenceComponentRule.test.js.map +1 -1
- package/package.json +2 -2
- package/src/rules/apis/invalidApiProxyBodySettingRule.test.ts +80 -0
- package/src/rules/apis/invalidApiProxyBodySettingRule.ts +25 -0
- package/src/rules/components/noReferenceComponentRule.test.ts +74 -0
- package/src/rules/components/noReferenceComponentRule.ts +6 -2
- package/src/types.d.ts +3 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isLegacyApi } from '@nordcraft/core/dist/api/api';
|
|
2
|
+
export const invalidApiProxyBodySettingRule = {
|
|
3
|
+
code: 'invalid api proxy body setting',
|
|
4
|
+
level: 'warning',
|
|
5
|
+
category: 'Quality',
|
|
6
|
+
visit: (report, args) => {
|
|
7
|
+
if (args.nodeType !== 'component-api') {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const { path, value } = args;
|
|
11
|
+
if (isLegacyApi(value) ||
|
|
12
|
+
value.server?.proxy?.useTemplatesInBody?.formula.type !== 'value' ||
|
|
13
|
+
value.server.proxy.useTemplatesInBody.formula.value === false ||
|
|
14
|
+
(value.server.proxy.enabled.formula.type === 'value' &&
|
|
15
|
+
value.server.proxy.enabled.formula.value === true)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
// Report an issue if useTemplatesInBody is set to true while the API is not set to be proxied
|
|
19
|
+
report(path, { api: value.name });
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=invalidApiProxyBodySettingRule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalidApiProxyBodySettingRule.js","sourceRoot":"","sources":["../../../src/rules/apis/invalidApiProxyBodySettingRule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAG1D,MAAM,CAAC,MAAM,8BAA8B,GAA0B;IACnE,IAAI,EAAE,gCAAgC;IACtC,KAAK,EAAE,SAAS;IAChB,QAAQ,EAAE,SAAS;IACnB,KAAK,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;QACtB,IAAI,IAAI,CAAC,QAAQ,KAAK,eAAe,EAAE,CAAC;YACtC,OAAM;QACR,CAAC;QACD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAA;QAC5B,IACE,WAAW,CAAC,KAAK,CAAC;YAClB,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,CAAC,IAAI,KAAK,OAAO;YACjE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,KAAK,KAAK,KAAK;YAC7D,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,OAAO;gBAClD,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,KAAK,IAAI,CAAC,EACpD,CAAC;YACD,OAAM;QACR,CAAC;QACD,8FAA8F;QAC9F,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;IACnC,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { valueFormula } from '@nordcraft/core/dist/formula/formulaUtils';
|
|
2
|
+
import { describe, expect, test } from 'bun:test';
|
|
3
|
+
import { searchProject } from '../../searchProject';
|
|
4
|
+
import { invalidApiProxyBodySettingRule } from './invalidApiProxyBodySettingRule';
|
|
5
|
+
describe('invalidApiProxyBodySetting', () => {
|
|
6
|
+
test('should report invalid proxy body settings for an API with proxying disabled', () => {
|
|
7
|
+
const problems = Array.from(searchProject({
|
|
8
|
+
files: {
|
|
9
|
+
components: {
|
|
10
|
+
test: {
|
|
11
|
+
name: 'test',
|
|
12
|
+
nodes: {},
|
|
13
|
+
formulas: {},
|
|
14
|
+
apis: {
|
|
15
|
+
'my-api': {
|
|
16
|
+
name: 'my-api',
|
|
17
|
+
type: 'http',
|
|
18
|
+
version: 2,
|
|
19
|
+
autoFetch: valueFormula(true),
|
|
20
|
+
inputs: {},
|
|
21
|
+
server: {
|
|
22
|
+
proxy: {
|
|
23
|
+
enabled: { formula: valueFormula(false) },
|
|
24
|
+
useTemplatesInBody: { formula: valueFormula(true) },
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
attributes: {},
|
|
30
|
+
variables: {},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
rules: [invalidApiProxyBodySettingRule],
|
|
35
|
+
}));
|
|
36
|
+
expect(problems).toHaveLength(1);
|
|
37
|
+
expect(problems[0].code).toBe('invalid api proxy body setting');
|
|
38
|
+
expect(problems[0].details).toEqual({ api: 'my-api' });
|
|
39
|
+
});
|
|
40
|
+
test('should not report valid body proxy settings', () => {
|
|
41
|
+
const problems = Array.from(searchProject({
|
|
42
|
+
files: {
|
|
43
|
+
components: {
|
|
44
|
+
test: {
|
|
45
|
+
name: 'test',
|
|
46
|
+
nodes: {},
|
|
47
|
+
formulas: {},
|
|
48
|
+
apis: {
|
|
49
|
+
'my-api': {
|
|
50
|
+
name: 'my-api',
|
|
51
|
+
type: 'http',
|
|
52
|
+
version: 2,
|
|
53
|
+
autoFetch: valueFormula(true),
|
|
54
|
+
inputs: {},
|
|
55
|
+
server: {
|
|
56
|
+
proxy: {
|
|
57
|
+
enabled: { formula: valueFormula(true) },
|
|
58
|
+
useTemplatesInBody: { formula: valueFormula(true) },
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
attributes: {},
|
|
64
|
+
variables: {},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
rules: [invalidApiProxyBodySettingRule],
|
|
69
|
+
}));
|
|
70
|
+
expect(problems).toEqual([]);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=invalidApiProxyBodySettingRule.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalidApiProxyBodySettingRule.test.js","sourceRoot":"","sources":["../../../src/rules/apis/invalidApiProxyBodySettingRule.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAA;AAEjF,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC1C,IAAI,CAAC,6EAA6E,EAAE,GAAG,EAAE;QACvF,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CACzB,aAAa,CAAC;YACZ,KAAK,EAAE;gBACL,UAAU,EAAE;oBACV,IAAI,EAAE;wBACJ,IAAI,EAAE,MAAM;wBACZ,KAAK,EAAE,EAAE;wBACT,QAAQ,EAAE,EAAE;wBACZ,IAAI,EAAE;4BACJ,QAAQ,EAAE;gCACR,IAAI,EAAE,QAAQ;gCACd,IAAI,EAAE,MAAM;gCACZ,OAAO,EAAE,CAAC;gCACV,SAAS,EAAE,YAAY,CAAC,IAAI,CAA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CAAC,IAAI,CAAC,EAAE;qCACpD;iCACF;6BACF;yBACF;wBACD,UAAU,EAAE,EAAE;wBACd,SAAS,EAAE,EAAE;qBACd;iBACF;aACF;YACD,KAAK,EAAE,CAAC,8BAA8B,CAAC;SACxC,CAAC,CACH,CAAA;QAED,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAC9B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -3,9 +3,11 @@ export const noReferenceComponentRule = {
|
|
|
3
3
|
code: 'no-reference component',
|
|
4
4
|
level: 'warning',
|
|
5
5
|
category: 'No References',
|
|
6
|
-
visit: (report, { path, nodeType, files, value }) => {
|
|
6
|
+
visit: (report, { path, nodeType, files, value }, state) => {
|
|
7
7
|
// We need a way to flag if a component is exported as a web component, as it would be a valid orphan
|
|
8
|
-
if (nodeType !== 'component' ||
|
|
8
|
+
if (nodeType !== 'component' ||
|
|
9
|
+
isPage(value) ||
|
|
10
|
+
(state?.projectDetails?.type === 'package' && value.exported === true)) {
|
|
9
11
|
return;
|
|
10
12
|
}
|
|
11
13
|
for (const component of Object.values(files.components)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noReferenceComponentRule.js","sourceRoot":"","sources":["../../../src/rules/components/noReferenceComponentRule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAG3D,MAAM,CAAC,MAAM,wBAAwB,GAAe;IAClD,IAAI,EAAE,wBAAwB;IAC9B,KAAK,EAAE,SAAS;IAChB,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"noReferenceComponentRule.js","sourceRoot":"","sources":["../../../src/rules/components/noReferenceComponentRule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAG3D,MAAM,CAAC,MAAM,wBAAwB,GAAe;IAClD,IAAI,EAAE,wBAAwB;IAC9B,KAAK,EAAE,SAAS;IAChB,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE;QACzD,qGAAqG;QACrG,IACE,QAAQ,KAAK,WAAW;YACxB,MAAM,CAAC,KAAK,CAAC;YACb,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC,EACtE,CAAC;YACD,OAAM;QACR,CAAC;QAED,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;YACxD,oEAAoE;YACpE,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,SAAU,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;gBACzD,IACE,IAAI,CAAC,IAAI,KAAK,WAAW;oBACzB,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;oBACxB,wDAAwD;oBACxD,2BAA2B;oBAC3B,IAAI,CAAC,IAAI,KAAK,SAAU,CAAC,IAAI,EAC7B,CAAC;oBACD,OAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,CAAA;IACd,CAAC;CACF,CAAA;AAED,MAAM,MAAM,GAAG,CACb,KAAgB,EAC8C,EAAE,CAChE,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA"}
|
|
@@ -40,6 +40,14 @@ describe('noReferenceComponentRule', () => {
|
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
42
|
rules: [noReferenceComponentRule],
|
|
43
|
+
state: {
|
|
44
|
+
projectDetails: {
|
|
45
|
+
type: 'package',
|
|
46
|
+
id: 'test-project-id',
|
|
47
|
+
name: 'test-project',
|
|
48
|
+
short_id: 'test-project-id',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
43
51
|
}));
|
|
44
52
|
expect(problems).toHaveLength(1);
|
|
45
53
|
expect(problems[0].code).toBe('no-reference component');
|
|
@@ -127,5 +135,63 @@ describe('noReferenceComponentRule', () => {
|
|
|
127
135
|
}));
|
|
128
136
|
expect(problems).toEqual([]);
|
|
129
137
|
});
|
|
138
|
+
test('should not report exported components for package projects', () => {
|
|
139
|
+
const problems = Array.from(searchProject({
|
|
140
|
+
files: {
|
|
141
|
+
formulas: {},
|
|
142
|
+
components: {
|
|
143
|
+
orphan: {
|
|
144
|
+
name: 'test',
|
|
145
|
+
nodes: {},
|
|
146
|
+
formulas: {},
|
|
147
|
+
apis: {},
|
|
148
|
+
attributes: {},
|
|
149
|
+
variables: {},
|
|
150
|
+
exported: true,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
state: {
|
|
155
|
+
projectDetails: {
|
|
156
|
+
type: 'package',
|
|
157
|
+
id: 'test-package-id',
|
|
158
|
+
name: 'test-package',
|
|
159
|
+
short_id: 'test-package-id',
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
rules: [noReferenceComponentRule],
|
|
163
|
+
}));
|
|
164
|
+
expect(problems).toEqual([]);
|
|
165
|
+
});
|
|
166
|
+
test('should still report exported components for non-package projects', () => {
|
|
167
|
+
const problems = Array.from(searchProject({
|
|
168
|
+
files: {
|
|
169
|
+
formulas: {},
|
|
170
|
+
components: {
|
|
171
|
+
exportedOrphan: {
|
|
172
|
+
name: 'test',
|
|
173
|
+
nodes: {},
|
|
174
|
+
formulas: {},
|
|
175
|
+
apis: {},
|
|
176
|
+
attributes: {},
|
|
177
|
+
variables: {},
|
|
178
|
+
exported: true,
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
state: {
|
|
183
|
+
projectDetails: {
|
|
184
|
+
type: 'app',
|
|
185
|
+
id: 'test-project-id',
|
|
186
|
+
name: 'test-project',
|
|
187
|
+
short_id: 'test-project-id',
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
rules: [noReferenceComponentRule],
|
|
191
|
+
}));
|
|
192
|
+
expect(problems).toHaveLength(1);
|
|
193
|
+
expect(problems[0].code).toBe('no-reference component');
|
|
194
|
+
expect(problems[0].path).toEqual(['components', 'exportedOrphan']);
|
|
195
|
+
});
|
|
130
196
|
});
|
|
131
197
|
//# sourceMappingURL=noReferenceComponentRule.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noReferenceComponentRule.test.js","sourceRoot":"","sources":["../../../src/rules/components/noReferenceComponentRule.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAErE,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,IAAI,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACvD,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CACzB,aAAa,CAAC;YACZ,KAAK,EAAE;gBACL,QAAQ,EAAE,EAAE;gBACZ,UAAU,EAAE;oBACV,MAAM,EAAE;wBACN,IAAI,EAAE,MAAM;wBACZ,KAAK,EAAE,EAAE;wBACT,QAAQ,EAAE,EAAE;wBACZ,IAAI,EAAE,EAAE;wBACR,UAAU,EAAE,EAAE;wBACd,SAAS,EAAE,EAAE;qBACd;oBACD,cAAc,EAAE;wBACd,IAAI,EAAE,MAAM;wBACZ,KAAK,EAAE,EAAE;wBACT,QAAQ,EAAE,EAAE;wBACZ,IAAI,EAAE,EAAE;wBACR,UAAU,EAAE,EAAE;wBACd,SAAS,EAAE,EAAE;wBACb,QAAQ,EAAE,IAAI;qBACf;oBACD,IAAI,EAAE;wBACJ,IAAI,EAAE,SAAS;wBACf,KAAK,EAAE,EAAE;wBACT,QAAQ,EAAE,EAAE;wBACZ,IAAI,EAAE,EAAE;wBACR,UAAU,EAAE,EAAE;wBACd,SAAS,EAAE,EAAE;wBACb,KAAK,EAAE;4BACL,IAAI,EAAE,EAAE;4BACR,IAAI,EAAE,EAAE;4BACR,KAAK,EAAE,EAAE;yBACV;qBACF;iBACF;aACF;YACD,KAAK,EAAE,CAAC,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"noReferenceComponentRule.test.js","sourceRoot":"","sources":["../../../src/rules/components/noReferenceComponentRule.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAErE,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,IAAI,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACvD,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CACzB,aAAa,CAAC;YACZ,KAAK,EAAE;gBACL,QAAQ,EAAE,EAAE;gBACZ,UAAU,EAAE;oBACV,MAAM,EAAE;wBACN,IAAI,EAAE,MAAM;wBACZ,KAAK,EAAE,EAAE;wBACT,QAAQ,EAAE,EAAE;wBACZ,IAAI,EAAE,EAAE;wBACR,UAAU,EAAE,EAAE;wBACd,SAAS,EAAE,EAAE;qBACd;oBACD,cAAc,EAAE;wBACd,IAAI,EAAE,MAAM;wBACZ,KAAK,EAAE,EAAE;wBACT,QAAQ,EAAE,EAAE;wBACZ,IAAI,EAAE,EAAE;wBACR,UAAU,EAAE,EAAE;wBACd,SAAS,EAAE,EAAE;wBACb,QAAQ,EAAE,IAAI;qBACf;oBACD,IAAI,EAAE;wBACJ,IAAI,EAAE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c,EAAE;wBACd,IAAI,EAAE,MAAM;wBACZ,KAAK,EAAE,EAAE;wBACT,QAAQ,EAAE,EAAE;wBACZ,IAAI,EAAE,EAAE;wBACR,UAAU,EAAE,EAAE;wBACd,SAAS,EAAE,EAAE;wBACb,QAAQ,EAAE,IAAI;qBACf;iBACF;aACF;YACD,KAAK,EAAE;gBACL,cAAc,EAAE;oBACd,IAAI,EAAE,KAAK;oBACX,EAAE,EAAE,iBAAiB;oBACrB,IAAI,EAAE,cAAc;oBACpB,QAAQ,EAAE,iBAAiB;iBAC5B;aACF;YACD,KAAK,EAAE,CAAC,wBAAwB,CAAC;SAClC,CAAC,CACH,CAAA;QAED,MAAM,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;QAChC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA;QACvD,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC,CAAA;IACpE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/nordcraftengine/nordcraft",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@nordcraft/ssr": "1.0.
|
|
8
|
+
"@nordcraft/ssr": "1.0.21"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc",
|
|
@@ -17,5 +17,5 @@
|
|
|
17
17
|
"test:watch:only": "bun test --watch --only"
|
|
18
18
|
},
|
|
19
19
|
"files": ["dist", "src"],
|
|
20
|
-
"version": "1.0.
|
|
20
|
+
"version": "1.0.21"
|
|
21
21
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { valueFormula } from '@nordcraft/core/dist/formula/formulaUtils'
|
|
2
|
+
import { describe, expect, test } from 'bun:test'
|
|
3
|
+
import { searchProject } from '../../searchProject'
|
|
4
|
+
import { invalidApiProxyBodySettingRule } from './invalidApiProxyBodySettingRule'
|
|
5
|
+
|
|
6
|
+
describe('invalidApiProxyBodySetting', () => {
|
|
7
|
+
test('should report invalid proxy body settings for an API with proxying disabled', () => {
|
|
8
|
+
const problems = Array.from(
|
|
9
|
+
searchProject({
|
|
10
|
+
files: {
|
|
11
|
+
components: {
|
|
12
|
+
test: {
|
|
13
|
+
name: 'test',
|
|
14
|
+
nodes: {},
|
|
15
|
+
formulas: {},
|
|
16
|
+
apis: {
|
|
17
|
+
'my-api': {
|
|
18
|
+
name: 'my-api',
|
|
19
|
+
type: 'http',
|
|
20
|
+
version: 2,
|
|
21
|
+
autoFetch: valueFormula(true),
|
|
22
|
+
inputs: {},
|
|
23
|
+
server: {
|
|
24
|
+
proxy: {
|
|
25
|
+
enabled: { formula: valueFormula(false) },
|
|
26
|
+
useTemplatesInBody: { formula: valueFormula(true) },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
attributes: {},
|
|
32
|
+
variables: {},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
rules: [invalidApiProxyBodySettingRule],
|
|
37
|
+
}),
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
expect(problems).toHaveLength(1)
|
|
41
|
+
expect(problems[0].code).toBe('invalid api proxy body setting')
|
|
42
|
+
expect(problems[0].details).toEqual({ api: 'my-api' })
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('should not report valid body proxy settings', () => {
|
|
46
|
+
const problems = Array.from(
|
|
47
|
+
searchProject({
|
|
48
|
+
files: {
|
|
49
|
+
components: {
|
|
50
|
+
test: {
|
|
51
|
+
name: 'test',
|
|
52
|
+
nodes: {},
|
|
53
|
+
formulas: {},
|
|
54
|
+
apis: {
|
|
55
|
+
'my-api': {
|
|
56
|
+
name: 'my-api',
|
|
57
|
+
type: 'http',
|
|
58
|
+
version: 2,
|
|
59
|
+
autoFetch: valueFormula(true),
|
|
60
|
+
inputs: {},
|
|
61
|
+
server: {
|
|
62
|
+
proxy: {
|
|
63
|
+
enabled: { formula: valueFormula(true) },
|
|
64
|
+
useTemplatesInBody: { formula: valueFormula(true) },
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
attributes: {},
|
|
70
|
+
variables: {},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
rules: [invalidApiProxyBodySettingRule],
|
|
75
|
+
}),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
expect(problems).toEqual([])
|
|
79
|
+
})
|
|
80
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isLegacyApi } from '@nordcraft/core/dist/api/api'
|
|
2
|
+
import type { Rule } from '../../types'
|
|
3
|
+
|
|
4
|
+
export const invalidApiProxyBodySettingRule: Rule<{ api: string }> = {
|
|
5
|
+
code: 'invalid api proxy body setting',
|
|
6
|
+
level: 'warning',
|
|
7
|
+
category: 'Quality',
|
|
8
|
+
visit: (report, args) => {
|
|
9
|
+
if (args.nodeType !== 'component-api') {
|
|
10
|
+
return
|
|
11
|
+
}
|
|
12
|
+
const { path, value } = args
|
|
13
|
+
if (
|
|
14
|
+
isLegacyApi(value) ||
|
|
15
|
+
value.server?.proxy?.useTemplatesInBody?.formula.type !== 'value' ||
|
|
16
|
+
value.server.proxy.useTemplatesInBody.formula.value === false ||
|
|
17
|
+
(value.server.proxy.enabled.formula.type === 'value' &&
|
|
18
|
+
value.server.proxy.enabled.formula.value === true)
|
|
19
|
+
) {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
// Report an issue if useTemplatesInBody is set to true while the API is not set to be proxied
|
|
23
|
+
report(path, { api: value.name })
|
|
24
|
+
},
|
|
25
|
+
}
|
|
@@ -42,6 +42,14 @@ describe('noReferenceComponentRule', () => {
|
|
|
42
42
|
},
|
|
43
43
|
},
|
|
44
44
|
rules: [noReferenceComponentRule],
|
|
45
|
+
state: {
|
|
46
|
+
projectDetails: {
|
|
47
|
+
type: 'package',
|
|
48
|
+
id: 'test-project-id',
|
|
49
|
+
name: 'test-project',
|
|
50
|
+
short_id: 'test-project-id',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
45
53
|
}),
|
|
46
54
|
)
|
|
47
55
|
|
|
@@ -138,4 +146,70 @@ describe('noReferenceComponentRule', () => {
|
|
|
138
146
|
|
|
139
147
|
expect(problems).toEqual([])
|
|
140
148
|
})
|
|
149
|
+
|
|
150
|
+
test('should not report exported components for package projects', () => {
|
|
151
|
+
const problems = Array.from(
|
|
152
|
+
searchProject({
|
|
153
|
+
files: {
|
|
154
|
+
formulas: {},
|
|
155
|
+
components: {
|
|
156
|
+
orphan: {
|
|
157
|
+
name: 'test',
|
|
158
|
+
nodes: {},
|
|
159
|
+
formulas: {},
|
|
160
|
+
apis: {},
|
|
161
|
+
attributes: {},
|
|
162
|
+
variables: {},
|
|
163
|
+
exported: true,
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
state: {
|
|
168
|
+
projectDetails: {
|
|
169
|
+
type: 'package',
|
|
170
|
+
id: 'test-package-id',
|
|
171
|
+
name: 'test-package',
|
|
172
|
+
short_id: 'test-package-id',
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
rules: [noReferenceComponentRule],
|
|
176
|
+
}),
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
expect(problems).toEqual([])
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
test('should still report exported components for non-package projects', () => {
|
|
183
|
+
const problems = Array.from(
|
|
184
|
+
searchProject({
|
|
185
|
+
files: {
|
|
186
|
+
formulas: {},
|
|
187
|
+
components: {
|
|
188
|
+
exportedOrphan: {
|
|
189
|
+
name: 'test',
|
|
190
|
+
nodes: {},
|
|
191
|
+
formulas: {},
|
|
192
|
+
apis: {},
|
|
193
|
+
attributes: {},
|
|
194
|
+
variables: {},
|
|
195
|
+
exported: true,
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
state: {
|
|
200
|
+
projectDetails: {
|
|
201
|
+
type: 'app',
|
|
202
|
+
id: 'test-project-id',
|
|
203
|
+
name: 'test-project',
|
|
204
|
+
short_id: 'test-project-id',
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
rules: [noReferenceComponentRule],
|
|
208
|
+
}),
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
expect(problems).toHaveLength(1)
|
|
212
|
+
expect(problems[0].code).toBe('no-reference component')
|
|
213
|
+
expect(problems[0].path).toEqual(['components', 'exportedOrphan'])
|
|
214
|
+
})
|
|
141
215
|
})
|
|
@@ -6,9 +6,13 @@ export const noReferenceComponentRule: Rule<void> = {
|
|
|
6
6
|
code: 'no-reference component',
|
|
7
7
|
level: 'warning',
|
|
8
8
|
category: 'No References',
|
|
9
|
-
visit: (report, { path, nodeType, files, value }) => {
|
|
9
|
+
visit: (report, { path, nodeType, files, value }, state) => {
|
|
10
10
|
// We need a way to flag if a component is exported as a web component, as it would be a valid orphan
|
|
11
|
-
if (
|
|
11
|
+
if (
|
|
12
|
+
nodeType !== 'component' ||
|
|
13
|
+
isPage(value) ||
|
|
14
|
+
(state?.projectDetails?.type === 'package' && value.exported === true)
|
|
15
|
+
) {
|
|
12
16
|
return
|
|
13
17
|
}
|
|
14
18
|
|
package/src/types.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
PluginAction,
|
|
20
20
|
ProjectFiles,
|
|
21
21
|
Route,
|
|
22
|
+
ToddleProject,
|
|
22
23
|
} from '@nordcraft/ssr/dist/ssr.types'
|
|
23
24
|
|
|
24
25
|
type Code =
|
|
@@ -27,6 +28,7 @@ type Code =
|
|
|
27
28
|
| 'duplicate workflow parameter'
|
|
28
29
|
| 'duplicate route'
|
|
29
30
|
| 'invalid api parser mode'
|
|
31
|
+
| 'invalid api proxy body setting'
|
|
30
32
|
| 'legacy action'
|
|
31
33
|
| 'legacy api'
|
|
32
34
|
| 'legacy formula'
|
|
@@ -129,6 +131,7 @@ type NonHttpOnlyCookie = ApplicationCookie & {
|
|
|
129
131
|
export interface ApplicationState {
|
|
130
132
|
cookiesAvailable?: Array<HttpOnlyCookie | NonHttpOnlyCookie>
|
|
131
133
|
isBrowserExtensionAvailable?: boolean
|
|
134
|
+
projectDetails?: ToddleProject
|
|
132
135
|
}
|
|
133
136
|
|
|
134
137
|
type Base = {
|