@forge/lint 6.0.2-next.3-experimental-bd3d812 → 6.0.2-next.3-experimental-c6a3916
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/CHANGELOG.md +12 -4
- package/out/lint/lint.d.ts +3 -2
- package/out/lint/lint.d.ts.map +1 -1
- package/out/lint/lint.js +22 -7
- package/out/lint/linter-interface.d.ts +3 -1
- package/out/lint/linter-interface.d.ts.map +1 -1
- package/out/lint/linter-interface.js +6 -1
- package/out/lint/linters/server-side-linter/server-side-linter.d.ts +62 -0
- package/out/lint/linters/server-side-linter/server-side-linter.d.ts.map +1 -0
- package/out/lint/linters/server-side-linter/server-side-linter.js +209 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
# @forge/lint
|
|
2
2
|
|
|
3
|
-
## 6.0.2-next.3-experimental-
|
|
3
|
+
## 6.0.2-next.3-experimental-c6a3916
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 342098d: Implement server-side linter logic to prevent accidental major app version deployments
|
|
4
8
|
|
|
5
9
|
### Patch Changes
|
|
6
10
|
|
|
11
|
+
- 9cd0e0e: Update Forge CLI output rendering to incorporate pre-deployment API rules
|
|
7
12
|
- Updated dependencies [4c5ba1c]
|
|
13
|
+
- Updated dependencies [903d6c1]
|
|
14
|
+
- Updated dependencies [9cd0e0e]
|
|
15
|
+
- Updated dependencies [342098d]
|
|
8
16
|
- Updated dependencies [757223b]
|
|
9
17
|
- Updated dependencies [7195f29]
|
|
10
18
|
- Updated dependencies [3252a62]
|
|
11
19
|
- Updated dependencies [3991f92]
|
|
12
|
-
- @forge/manifest@13.1.1-next.2-experimental-
|
|
13
|
-
- @forge/cli-shared@9.2.0-next.3-experimental-
|
|
14
|
-
- @forge/csp@6.1.0-experimental-
|
|
20
|
+
- @forge/manifest@13.1.1-next.2-experimental-c6a3916
|
|
21
|
+
- @forge/cli-shared@9.2.0-next.3-experimental-c6a3916
|
|
22
|
+
- @forge/csp@6.1.0-experimental-c6a3916
|
|
15
23
|
|
|
16
24
|
## 6.0.2-next.3
|
|
17
25
|
|
package/out/lint/lint.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StatsigService } from '@forge/cli-shared';
|
|
1
|
+
import { StatsigService, GraphQLClient } from '@forge/cli-shared';
|
|
2
2
|
import { ManifestSchema as Manifest } from '@forge/manifest';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import { tsParser } from '../parse';
|
|
@@ -6,10 +6,11 @@ import { LinterInterface, LintInput, LintLogger, LintResult } from './linter-int
|
|
|
6
6
|
export interface ProblemCount {
|
|
7
7
|
errors: number;
|
|
8
8
|
warnings: number;
|
|
9
|
+
approvals: number;
|
|
9
10
|
}
|
|
10
11
|
export declare const reportLintResults: (logger: LintLogger, lintResults: LintResult[], showSummary?: boolean) => void;
|
|
11
12
|
export declare const problemCount: (lintResults: LintResult[]) => ProblemCount;
|
|
12
13
|
export declare const parseSourceFile: (filepath: string, parser: typeof tsParser, readFilePromise?: typeof fs.readFile.__promisify__) => Promise<LintInput>;
|
|
13
|
-
export declare const lint: (filesToLint: string[], manifest: Manifest, environment: string, logger: LintLogger, statsigService: StatsigService, parseFunction?: (filepath: string, parser: typeof tsParser, readFilePromise?: typeof fs.readFile.__promisify__) => Promise<LintInput>,
|
|
14
|
+
export declare const lint: (filesToLint: string[], manifest: Manifest, environment: string, logger: LintLogger, statsigService: StatsigService, graphqlClient: GraphQLClient, approveRule?: string[], parseFunction?: (filepath: string, parser: typeof tsParser, readFilePromise?: typeof fs.readFile.__promisify__) => Promise<LintInput>, lintersOverride?: LinterInterface[]) => Promise<LintResult[]>;
|
|
14
15
|
export declare const litelint: (logger: LintLogger, statsigService: StatsigService, linter?: LinterInterface) => Promise<LintResult[]>;
|
|
15
16
|
//# sourceMappingURL=lint.d.ts.map
|
package/out/lint/lint.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../../src/lint/lint.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,cAAc,
|
|
1
|
+
{"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../../src/lint/lint.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,cAAc,EACd,aAAa,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,IAAI,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,MAAM,IAAI,CAAC;AAIpB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AAmBxG,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,iBAAiB,GAAI,QAAQ,UAAU,EAAE,aAAa,UAAU,EAAE,EAAE,qBAAkB,KAAG,IAuDrG,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,aAAa,UAAU,EAAE,KAAG,YASxD,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,UAAU,MAAM,EAChB,QAAQ,OAAO,QAAQ,EACvB,kBAAiB,OAAO,EAAE,CAAC,QAAQ,CAAC,aAAsC,KACzE,OAAO,CAAC,SAAS,CAOnB,CAAC;AA4BF,eAAO,MAAM,IAAI,GACf,aAAa,MAAM,EAAE,EACrB,UAAU,QAAQ,EAClB,aAAa,MAAM,EACnB,QAAQ,UAAU,EAClB,gBAAgB,cAAc,EAC9B,eAAe,aAAa,EAC5B,cAAc,MAAM,EAAE,EACtB,2BA9CU,MAAM,UACR,OAAO,QAAQ,oBACN,OAAO,EAAE,CAAC,QAAQ,CAAC,aAAa,KAChD,OAAO,CAAC,SAAS,CA2Ca,EAC/B,kBAAiB,eAAe,EAAO,KACtC,OAAO,CAAC,UAAU,EAAE,CA+CtB,CAAC;AAwBF,eAAO,MAAM,QAAQ,GACnB,QAAQ,UAAU,EAClB,gBAAgB,cAAc,EAC9B,SAAQ,eAAiE,KACxE,OAAO,CAAC,UAAU,EAAE,CAGtB,CAAC"}
|
package/out/lint/lint.js
CHANGED
|
@@ -23,8 +23,9 @@ const llm_module_linter_1 = require("./linters/llm-module-linter/llm-module-lint
|
|
|
23
23
|
const deprecated_api_module_linter_1 = require("./linters/deprecated-api-module-linter/deprecated-api-module-linter");
|
|
24
24
|
const app_managed_permissions_sdk_linter_1 = require("./linters/app-managed-permissions-sdk-linter/app-managed-permissions-sdk-linter");
|
|
25
25
|
const function_timeout_linter_1 = require("./linters/function-timeout-linter/function-timeout-linter");
|
|
26
|
+
const server_side_linter_1 = require("./linters/server-side-linter/server-side-linter");
|
|
26
27
|
const reportLintResults = (logger, lintResults, showSummary = true) => {
|
|
27
|
-
let numErrors = 0, numWarnings = 0;
|
|
28
|
+
let numErrors = 0, numWarnings = 0, numApprovals = 0;
|
|
28
29
|
let noProblemsFound = true;
|
|
29
30
|
if (lintResults.length) {
|
|
30
31
|
lintResults.forEach((lintResult) => {
|
|
@@ -32,6 +33,7 @@ const reportLintResults = (logger, lintResults, showSummary = true) => {
|
|
|
32
33
|
noProblemsFound = false;
|
|
33
34
|
numErrors += lintResult.errors.length;
|
|
34
35
|
numWarnings += lintResult.warnings.length;
|
|
36
|
+
numApprovals += lintResult.approvals.length;
|
|
35
37
|
logger.info(cli_shared_1.Text.lint.filename(path_1.default.resolve(lintResult.file)));
|
|
36
38
|
lintResult.errors.forEach(({ line, column, message, reference }) => {
|
|
37
39
|
logger.info(cli_shared_1.Text.lint.error(line, column, message, reference));
|
|
@@ -39,6 +41,9 @@ const reportLintResults = (logger, lintResults, showSummary = true) => {
|
|
|
39
41
|
lintResult.warnings.forEach(({ line, column, message, reference }) => {
|
|
40
42
|
logger.info(cli_shared_1.Text.lint.warning(line, column, message, reference));
|
|
41
43
|
});
|
|
44
|
+
lintResult.approvals.forEach(({ line, column, message, reference }) => {
|
|
45
|
+
logger.info(cli_shared_1.Text.lint.approval(line, column, message, reference));
|
|
46
|
+
});
|
|
42
47
|
}
|
|
43
48
|
});
|
|
44
49
|
}
|
|
@@ -51,18 +56,21 @@ const reportLintResults = (logger, lintResults, showSummary = true) => {
|
|
|
51
56
|
const numFixableErrors = resultsWithFixers.reduce((count, result) => count + result.errors.length, 0);
|
|
52
57
|
const numFixableWarnings = resultsWithFixers.reduce((count, result) => count + result.warnings.length, 0);
|
|
53
58
|
if (showSummary) {
|
|
54
|
-
logger.info(cli_shared_1.Text.lint.summary(numErrors, numWarnings, numFixableErrors, numFixableWarnings));
|
|
59
|
+
logger.info(cli_shared_1.Text.lint.summary(numErrors, numWarnings, numApprovals, numFixableErrors, numFixableWarnings));
|
|
55
60
|
if (numFixableErrors + numFixableWarnings > 0) {
|
|
56
61
|
logger.info(cli_shared_1.Text.lint.fixSummary(numErrors, numFixableErrors, numFixableWarnings));
|
|
57
62
|
}
|
|
58
63
|
else if (numErrors + numWarnings === 1) {
|
|
59
64
|
logger.info(cli_shared_1.Text.lint.noFixableProblem);
|
|
60
65
|
}
|
|
66
|
+
else if (numApprovals > 0) {
|
|
67
|
+
logger.info(cli_shared_1.Text.lint.noFixableProblem);
|
|
68
|
+
}
|
|
61
69
|
else {
|
|
62
70
|
logger.info(cli_shared_1.Text.lint.noFixableProblems);
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
|
-
if (numErrors) {
|
|
73
|
+
if (numErrors || numApprovals) {
|
|
66
74
|
process.exitCode = 1;
|
|
67
75
|
}
|
|
68
76
|
}
|
|
@@ -71,8 +79,9 @@ exports.reportLintResults = reportLintResults;
|
|
|
71
79
|
const problemCount = (lintResults) => {
|
|
72
80
|
return lintResults.reduce((prev, curr) => ({
|
|
73
81
|
errors: prev.errors + curr.errors.length,
|
|
74
|
-
warnings: prev.warnings + curr.warnings.length
|
|
75
|
-
|
|
82
|
+
warnings: prev.warnings + curr.warnings.length,
|
|
83
|
+
approvals: prev.approvals + curr.approvals.length
|
|
84
|
+
}), { errors: 0, warnings: 0, approvals: 0 });
|
|
76
85
|
};
|
|
77
86
|
exports.problemCount = problemCount;
|
|
78
87
|
const parseSourceFile = async (filepath, parser, readFilePromise = (0, util_1.promisify)(fs_1.default.readFile)) => {
|
|
@@ -84,8 +93,9 @@ const parseSourceFile = async (filepath, parser, readFilePromise = (0, util_1.pr
|
|
|
84
93
|
};
|
|
85
94
|
};
|
|
86
95
|
exports.parseSourceFile = parseSourceFile;
|
|
87
|
-
const
|
|
96
|
+
const getDefaultLinters = async (manifest, environment, logger, statsigService, graphqlClient, approveRule) => [
|
|
88
97
|
new permission_linter_1.PermissionLinter(environment, manifest, logger),
|
|
98
|
+
await server_side_linter_1.ServerSideLinter.instance(environment, manifest, graphqlClient, logger, approveRule),
|
|
89
99
|
new permissions_manifest_linter_1.PermissionsManifestLinter(logger, statsigService),
|
|
90
100
|
new agent_product_context_permissions_manifest_linter_1.AgentProductContextPermissionsManifestLinter(logger, statsigService),
|
|
91
101
|
new deprecated_csp_permissions_manifest_linter_1.DeprecatedCspPermissionsManifestLinter(logger, statsigService),
|
|
@@ -100,7 +110,11 @@ const lint = async (filesToLint, manifest, environment, logger, statsigService,
|
|
|
100
110
|
new deprecated_egress_permissions_manifest_linter_1.DeprecatedEgressPermissionsManifestLinter(logger, statsigService),
|
|
101
111
|
new app_managed_permissions_sdk_linter_1.AppManagedPermissionsSdkLinter(manifest, logger),
|
|
102
112
|
new function_timeout_linter_1.FunctionTimeoutLinter(manifest, logger)
|
|
103
|
-
]
|
|
113
|
+
];
|
|
114
|
+
const lint = async (filesToLint, manifest, environment, logger, statsigService, graphqlClient, approveRule, parseFunction = exports.parseSourceFile, lintersOverride = []) => {
|
|
115
|
+
const linters = lintersOverride.length > 0
|
|
116
|
+
? lintersOverride
|
|
117
|
+
: await getDefaultLinters(manifest, environment, logger, statsigService, graphqlClient, approveRule);
|
|
104
118
|
const { include, exclude } = await (0, cli_shared_1.listTSConfigIncludeExclude)(new cli_shared_1.FileSystemReader());
|
|
105
119
|
const tsInclude = new Set(include);
|
|
106
120
|
const tsExclude = new Set(exclude);
|
|
@@ -126,6 +140,7 @@ const lint = async (filesToLint, manifest, environment, logger, statsigService,
|
|
|
126
140
|
const comparator = (a, b) => a.line === b.line ? a.column - b.column : a.line - b.line;
|
|
127
141
|
result.errors = result.errors.sort(comparator);
|
|
128
142
|
result.warnings = result.warnings.sort(comparator);
|
|
143
|
+
result.approvals = result.approvals.sort(comparator);
|
|
129
144
|
return result;
|
|
130
145
|
});
|
|
131
146
|
}
|
|
@@ -2,7 +2,8 @@ import { ASTParseResult } from '../parse';
|
|
|
2
2
|
import { ConfigFile, Logger } from '@forge/cli-shared';
|
|
3
3
|
export declare enum LintClass {
|
|
4
4
|
Error = "error",
|
|
5
|
-
Warning = "warning"
|
|
5
|
+
Warning = "warning",
|
|
6
|
+
Approval = "approval"
|
|
6
7
|
}
|
|
7
8
|
export type LintLogger = Pick<Logger, 'info'>;
|
|
8
9
|
export type LintFixer = (errors: LintResultRule[], warnings: LintResultRule[], state: LintFixState) => Promise<LintFixState>;
|
|
@@ -16,6 +17,7 @@ export declare class LintResult {
|
|
|
16
17
|
private fixer?;
|
|
17
18
|
errors: LintResultRule[];
|
|
18
19
|
warnings: LintResultRule[];
|
|
20
|
+
approvals: LintResultRule[];
|
|
19
21
|
constructor(file: string, fixer?: LintFixer | undefined);
|
|
20
22
|
add(rule: LintResultRule): void;
|
|
21
23
|
batchAdd(...rules: LintResultRule[]): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linter-interface.d.ts","sourceRoot":"","sources":["../../src/lint/linter-interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,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SAAS,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,cAAc,GAAG,IAAI,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,YAAY,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -5,12 +5,14 @@ var LintClass;
|
|
|
5
5
|
(function (LintClass) {
|
|
6
6
|
LintClass["Error"] = "error";
|
|
7
7
|
LintClass["Warning"] = "warning";
|
|
8
|
+
LintClass["Approval"] = "approval";
|
|
8
9
|
})(LintClass || (exports.LintClass = LintClass = {}));
|
|
9
10
|
class LintResult {
|
|
10
11
|
file;
|
|
11
12
|
fixer;
|
|
12
13
|
errors = [];
|
|
13
14
|
warnings = [];
|
|
15
|
+
approvals = [];
|
|
14
16
|
constructor(file, fixer) {
|
|
15
17
|
this.file = file;
|
|
16
18
|
this.fixer = fixer;
|
|
@@ -20,6 +22,9 @@ class LintResult {
|
|
|
20
22
|
case LintClass.Error:
|
|
21
23
|
this.errors.push(rule);
|
|
22
24
|
break;
|
|
25
|
+
case LintClass.Approval:
|
|
26
|
+
this.approvals.push(rule);
|
|
27
|
+
break;
|
|
23
28
|
default:
|
|
24
29
|
this.warnings.push(rule);
|
|
25
30
|
break;
|
|
@@ -29,7 +34,7 @@ class LintResult {
|
|
|
29
34
|
rules.forEach(this.add, this);
|
|
30
35
|
}
|
|
31
36
|
size() {
|
|
32
|
-
return this.errors.length + this.warnings.length;
|
|
37
|
+
return this.errors.length + this.warnings.length + this.approvals.length;
|
|
33
38
|
}
|
|
34
39
|
hasFixer() {
|
|
35
40
|
return !!this.fixer;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ManifestSchema as Manifest } from '@forge/manifest';
|
|
2
|
+
import { LintFixState, LintLogger, LintResult, LintResultRule } from '../../linter-interface';
|
|
3
|
+
import { AbstractLinter } from '../../abstract-linter';
|
|
4
|
+
import { FileSystemReader, FileUploader, GraphQLClient, UserError } from '@forge/cli-shared';
|
|
5
|
+
interface ManifestCheckChange {
|
|
6
|
+
added?: string[];
|
|
7
|
+
key: string;
|
|
8
|
+
removed?: string[];
|
|
9
|
+
}
|
|
10
|
+
interface ServerSideOutcome {
|
|
11
|
+
changes?: ManifestCheckChange[];
|
|
12
|
+
reason: string;
|
|
13
|
+
category: string;
|
|
14
|
+
rule: string;
|
|
15
|
+
value: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare class NoManifestURLError extends Error {
|
|
18
|
+
constructor();
|
|
19
|
+
}
|
|
20
|
+
export declare class MissingManifestError extends UserError {
|
|
21
|
+
constructor();
|
|
22
|
+
}
|
|
23
|
+
export declare class InvalidManifestError extends UserError {
|
|
24
|
+
constructor();
|
|
25
|
+
}
|
|
26
|
+
declare class ZipArchiver {
|
|
27
|
+
private readonly archive;
|
|
28
|
+
private readonly tempFile;
|
|
29
|
+
private readonly resolves;
|
|
30
|
+
private readonly rejects;
|
|
31
|
+
private constructor();
|
|
32
|
+
static create(): Promise<ZipArchiver>;
|
|
33
|
+
addFile(fileName: string, contents: Buffer): void;
|
|
34
|
+
finalise(): Promise<string>;
|
|
35
|
+
private readonly onArchiveError;
|
|
36
|
+
private readonly onClose;
|
|
37
|
+
}
|
|
38
|
+
declare class ManifestCheckGraphqlClient {
|
|
39
|
+
private readonly graphqlClient;
|
|
40
|
+
constructor(graphqlClient: GraphQLClient);
|
|
41
|
+
createAppManifestUploadUrl(appId: string, environmentKey: string): Promise<string>;
|
|
42
|
+
getAppPreDeploymentCheck(appId: string, environmentKey: string, manifestUrl: string, bypassRules: string[]): Promise<ServerSideOutcome[]>;
|
|
43
|
+
}
|
|
44
|
+
export declare class ServerSideLinter extends AbstractLinter {
|
|
45
|
+
private readonly environment;
|
|
46
|
+
private readonly manifest;
|
|
47
|
+
private readonly client;
|
|
48
|
+
private readonly fileReader;
|
|
49
|
+
private readonly archiver;
|
|
50
|
+
private readonly fileUploader;
|
|
51
|
+
private readonly approveRule;
|
|
52
|
+
private manifestUploadUrl;
|
|
53
|
+
constructor(environment: string, manifest: Manifest, client: ManifestCheckGraphqlClient, fileReader: FileSystemReader, archiver: ZipArchiver, fileUploader: FileUploader, logger: LintLogger, approveRule: string[] | undefined);
|
|
54
|
+
static instance(environment: string, manifest: Manifest, graphqlClient: GraphQLClient, logger: LintLogger, approveRule?: string[]): Promise<ServerSideLinter>;
|
|
55
|
+
private mapServerSideResponse;
|
|
56
|
+
batchExecuteImpl(): Promise<LintResult[]>;
|
|
57
|
+
bootstrap(): Promise<void>;
|
|
58
|
+
protected getFixer(): ((errors: LintResultRule[], warnings: LintResultRule[], state: LintFixState) => Promise<LintFixState>) | undefined;
|
|
59
|
+
protected getResultsForFixer(results: ServerSideOutcome[]): ServerSideOutcome[];
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=server-side-linter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-side-linter.d.ts","sourceRoot":"","sources":["../../../../src/lint/linters/server-side-linter/server-side-linter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,cAAc,IAAI,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAa,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACzG,OAAO,EAAE,cAAc,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
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerSideLinter = exports.InvalidManifestError = exports.MissingManifestError = exports.NoManifestURLError = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const manifest_1 = require("@forge/manifest");
|
|
6
|
+
const linter_interface_1 = require("../../linter-interface");
|
|
7
|
+
const abstract_linter_1 = require("../../abstract-linter");
|
|
8
|
+
const cli_shared_1 = require("@forge/cli-shared");
|
|
9
|
+
const tmp_1 = tslib_1.__importDefault(require("tmp"));
|
|
10
|
+
const node_fs_1 = require("node:fs");
|
|
11
|
+
class NoManifestURLError extends Error {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(cli_shared_1.Text.artifact.error.noManifestUrl);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.NoManifestURLError = NoManifestURLError;
|
|
17
|
+
class MissingManifestError extends cli_shared_1.UserError {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(cli_shared_1.Text.lint.errorMissingManifest);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.MissingManifestError = MissingManifestError;
|
|
23
|
+
class InvalidManifestError extends cli_shared_1.UserError {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(cli_shared_1.Text.lint.errorInvalidManifest);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.InvalidManifestError = InvalidManifestError;
|
|
29
|
+
class ZipArchiver {
|
|
30
|
+
archive;
|
|
31
|
+
tempFile = tmp_1.default.fileSync({ postfix: '.zip' });
|
|
32
|
+
resolves = [];
|
|
33
|
+
rejects = [];
|
|
34
|
+
constructor(archive) {
|
|
35
|
+
this.archive = archive;
|
|
36
|
+
const output = (0, node_fs_1.createWriteStream)(this.tempFile.name).on('close', this.onClose);
|
|
37
|
+
this.archive.pipe(output);
|
|
38
|
+
this.archive.on('warning', this.onArchiveError);
|
|
39
|
+
this.archive.on('error', this.onArchiveError);
|
|
40
|
+
}
|
|
41
|
+
static async create() {
|
|
42
|
+
const { ZipArchive } = await Promise.resolve().then(() => tslib_1.__importStar(require('archiver')));
|
|
43
|
+
return new ZipArchiver(new ZipArchive());
|
|
44
|
+
}
|
|
45
|
+
addFile(fileName, contents) {
|
|
46
|
+
this.archive.append(contents, { name: fileName });
|
|
47
|
+
}
|
|
48
|
+
finalise() {
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
this.resolves.push(resolve);
|
|
51
|
+
this.rejects.push(reject);
|
|
52
|
+
return this.archive.finalize();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
onArchiveError = (err) => {
|
|
56
|
+
const error = new Error(err.message);
|
|
57
|
+
for (const reject of this.rejects) {
|
|
58
|
+
reject(error);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
onClose = () => {
|
|
62
|
+
for (const resolve of this.resolves) {
|
|
63
|
+
resolve(this.tempFile.name);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
class ManifestCheckGraphqlClient {
|
|
68
|
+
graphqlClient;
|
|
69
|
+
constructor(graphqlClient) {
|
|
70
|
+
this.graphqlClient = graphqlClient;
|
|
71
|
+
}
|
|
72
|
+
async createAppManifestUploadUrl(appId, environmentKey) {
|
|
73
|
+
const mutation = `
|
|
74
|
+
mutation forge_cli_createAppManifestUploadUrl($input: CreateAppManifestUploadUrlInput!) {
|
|
75
|
+
createAppManifestUploadUrl(input: $input) {
|
|
76
|
+
success
|
|
77
|
+
preSignedUrl
|
|
78
|
+
errors {
|
|
79
|
+
message
|
|
80
|
+
extensions {
|
|
81
|
+
errorType
|
|
82
|
+
statusCode
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}`;
|
|
87
|
+
const { response: { createAppManifestUploadUrl: { success, preSignedUrl, errors } }, requestId } = await this.graphqlClient.mutate(mutation, {
|
|
88
|
+
input: {
|
|
89
|
+
appId,
|
|
90
|
+
environmentKey
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
if (!success) {
|
|
94
|
+
const error = (0, cli_shared_1.getError)(errors);
|
|
95
|
+
throw new cli_shared_1.GraphQlMutationError(`${error.message} (requestId: ${requestId || 'unknown'})`, {
|
|
96
|
+
requestId,
|
|
97
|
+
code: error.code,
|
|
98
|
+
statusCode: error.statusCode
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (!preSignedUrl) {
|
|
102
|
+
throw new NoManifestURLError();
|
|
103
|
+
}
|
|
104
|
+
return preSignedUrl;
|
|
105
|
+
}
|
|
106
|
+
async getAppPreDeploymentCheck(appId, environmentKey, manifestUrl, bypassRules) {
|
|
107
|
+
const query = `
|
|
108
|
+
query forge_cli_appPreDeploymentCheck($input: AppPreDeploymentCheckInput!) {
|
|
109
|
+
appPreDeploymentCheck(input: $input) {
|
|
110
|
+
outcome {
|
|
111
|
+
rule
|
|
112
|
+
category
|
|
113
|
+
value
|
|
114
|
+
reason
|
|
115
|
+
changes {
|
|
116
|
+
key
|
|
117
|
+
added
|
|
118
|
+
removed
|
|
119
|
+
}
|
|
120
|
+
errors {
|
|
121
|
+
key
|
|
122
|
+
message
|
|
123
|
+
line
|
|
124
|
+
column
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
`;
|
|
130
|
+
const result = await this.graphqlClient.query(query, {
|
|
131
|
+
input: {
|
|
132
|
+
appId,
|
|
133
|
+
environmentKey,
|
|
134
|
+
manifestUrl,
|
|
135
|
+
bypassRules
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
if (!result.appPreDeploymentCheck) {
|
|
139
|
+
throw new MissingManifestError();
|
|
140
|
+
}
|
|
141
|
+
if (!result.appPreDeploymentCheck.outcome) {
|
|
142
|
+
throw new InvalidManifestError();
|
|
143
|
+
}
|
|
144
|
+
return result.appPreDeploymentCheck.outcome.filter((p) => p !== null);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
class ServerSideLinter extends abstract_linter_1.AbstractLinter {
|
|
148
|
+
environment;
|
|
149
|
+
manifest;
|
|
150
|
+
client;
|
|
151
|
+
fileReader;
|
|
152
|
+
archiver;
|
|
153
|
+
fileUploader;
|
|
154
|
+
approveRule;
|
|
155
|
+
manifestUploadUrl;
|
|
156
|
+
constructor(environment, manifest, client, fileReader, archiver, fileUploader, logger, approveRule) {
|
|
157
|
+
super(logger);
|
|
158
|
+
this.environment = environment;
|
|
159
|
+
this.manifest = manifest;
|
|
160
|
+
this.client = client;
|
|
161
|
+
this.fileReader = fileReader;
|
|
162
|
+
this.archiver = archiver;
|
|
163
|
+
this.fileUploader = fileUploader;
|
|
164
|
+
this.approveRule = approveRule;
|
|
165
|
+
}
|
|
166
|
+
static async instance(environment, manifest, graphqlClient, logger, approveRule) {
|
|
167
|
+
const fileSystemReader = new cli_shared_1.FileSystemReader();
|
|
168
|
+
return new ServerSideLinter(environment, manifest, new ManifestCheckGraphqlClient(graphqlClient), fileSystemReader, await ZipArchiver.create(), new cli_shared_1.HttpFileUploader(fileSystemReader), logger, approveRule);
|
|
169
|
+
}
|
|
170
|
+
mapServerSideResponse(results, fixer) {
|
|
171
|
+
const manifestLintResults = new linter_interface_1.LintResult(manifest_1.MANIFEST_FILE, fixer);
|
|
172
|
+
manifestLintResults.batchAdd(...(this.getResultsForFixer(results).map(({ rule, reason, category }) => {
|
|
173
|
+
return {
|
|
174
|
+
class: category.toLowerCase(),
|
|
175
|
+
message: reason,
|
|
176
|
+
reference: rule,
|
|
177
|
+
line: 0,
|
|
178
|
+
column: 0,
|
|
179
|
+
metadata: {}
|
|
180
|
+
};
|
|
181
|
+
}) ?? []).sort((a, b) => a.line - b.line));
|
|
182
|
+
return manifestLintResults;
|
|
183
|
+
}
|
|
184
|
+
async batchExecuteImpl() {
|
|
185
|
+
if (!this.manifestUploadUrl) {
|
|
186
|
+
throw new Error('Bootstrap failed');
|
|
187
|
+
}
|
|
188
|
+
const results = await this.client.getAppPreDeploymentCheck(this.manifest.app.id, this.environment, this.manifestUploadUrl, this.approveRule ? this.approveRule : []);
|
|
189
|
+
return [this.mapServerSideResponse(results, this.getFixer())];
|
|
190
|
+
}
|
|
191
|
+
async bootstrap() {
|
|
192
|
+
const manifestContent = this.fileReader.readBinaryFile(cli_shared_1.manifestFileName);
|
|
193
|
+
if (!manifestContent) {
|
|
194
|
+
throw new Error('No Manifest content found');
|
|
195
|
+
}
|
|
196
|
+
this.archiver.addFile(cli_shared_1.manifestFileName, manifestContent);
|
|
197
|
+
const archivePath = await this.archiver.finalise();
|
|
198
|
+
const uploadUrl = await this.client.createAppManifestUploadUrl(this.manifest.app.id, this.environment);
|
|
199
|
+
await this.fileUploader.uploadFromPath(uploadUrl, archivePath);
|
|
200
|
+
this.manifestUploadUrl = uploadUrl;
|
|
201
|
+
}
|
|
202
|
+
getFixer() {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
getResultsForFixer(results) {
|
|
206
|
+
return results?.filter((outcome) => outcome.value) || [];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
exports.ServerSideLinter = ServerSideLinter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/lint",
|
|
3
|
-
"version": "6.0.2-next.3-experimental-
|
|
3
|
+
"version": "6.0.2-next.3-experimental-c6a3916",
|
|
4
4
|
"description": "Linting for forge apps",
|
|
5
5
|
"main": "out/index.js",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@atlassian/xen-test-util": "^4.2.0",
|
|
14
|
-
"@forge/api": "^8.0.2-next.0-experimental-
|
|
14
|
+
"@forge/api": "^8.0.2-next.0-experimental-c6a3916",
|
|
15
15
|
"@types/array.prototype.flatmap": "^1.2.6",
|
|
16
16
|
"@types/cross-spawn": "^6.0.6",
|
|
17
17
|
"@types/eslint": "8.56.12",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"eslint-plugin-import": "^2.29.1"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@forge/cli-shared": "9.2.0-next.3-experimental-
|
|
23
|
-
"@forge/csp": "6.1.0-experimental-
|
|
22
|
+
"@forge/cli-shared": "9.2.0-next.3-experimental-c6a3916",
|
|
23
|
+
"@forge/csp": "6.1.0-experimental-c6a3916",
|
|
24
24
|
"@forge/egress": "3.0.0",
|
|
25
|
-
"@forge/manifest": "13.1.1-next.2-experimental-
|
|
25
|
+
"@forge/manifest": "13.1.1-next.2-experimental-c6a3916",
|
|
26
26
|
"@typescript-eslint/typescript-estree": "^5.62.0",
|
|
27
27
|
"array.prototype.flatmap": "^1.3.3",
|
|
28
28
|
"@atlassian/atlassian-openapi": "^1.0.6",
|