Skip to content

Commit a2008c6

Browse files
authored
Merge pull request #1275 from finos/1193-consolidate-ts-types
refactor: consolidate TS types
2 parents df6406b + 3f1d41e commit a2008c6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+531
-578
lines changed

config.schema.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,14 @@
196196
},
197197
"links": {
198198
"type": "array",
199-
"items": { "type": "string", "format": "url" }
199+
"items": {
200+
"type": "object",
201+
"additionalProperties": false,
202+
"properties": {
203+
"text": { "type": "string" },
204+
"url": { "type": "string", "format": "url" }
205+
}
206+
}
200207
}
201208
},
202209
"required": ["text"]
@@ -466,7 +473,14 @@
466473
"description": "Additional JWT configuration.",
467474
"properties": {
468475
"clientID": { "type": "string" },
469-
"authorityURL": { "type": "string" }
476+
"authorityURL": { "type": "string" },
477+
"expectedAudience": { "type": "string" },
478+
"roleMapping": {
479+
"type": "object",
480+
"properties": {
481+
"admin": { "type": "object" }
482+
}
483+
}
470484
},
471485
"required": ["clientID", "authorityURL"]
472486
}

package.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,25 @@
2020
"require": "./dist/src/db/index.js",
2121
"types": "./dist/src/db/index.d.ts"
2222
},
23+
"./plugin": {
24+
"import": "./dist/src/plugin.js",
25+
"require": "./dist/src/plugin.js",
26+
"types": "./dist/src/plugin.d.ts"
27+
},
2328
"./proxy": {
2429
"import": "./dist/src/proxy/index.js",
2530
"require": "./dist/src/proxy/index.js",
2631
"types": "./dist/src/proxy/index.d.ts"
2732
},
28-
"./types": {
29-
"import": "./dist/src/types/models.js",
30-
"require": "./dist/src/types/models.js",
31-
"types": "./dist/src/types/models.d.ts"
33+
"./proxy/actions": {
34+
"import": "./dist/src/proxy/actions/index.js",
35+
"require": "./dist/src/proxy/actions/index.js",
36+
"types": "./dist/src/proxy/actions/index.d.ts"
3237
},
33-
"./plugin": {
34-
"import": "./dist/src/plugin.js",
35-
"require": "./dist/src/plugin.js",
36-
"types": "./dist/src/plugin.d.ts"
38+
"./ui": {
39+
"import": "./dist/src/ui/index.js",
40+
"require": "./dist/src/ui/index.js",
41+
"types": "./dist/src/ui/index.d.ts"
3742
}
3843
},
3944
"scripts": {

packages/git-proxy-cli/index.ts

Lines changed: 72 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { hideBin } from 'yargs/helpers';
55
import fs from 'fs';
66
import util from 'util';
77

8-
import { CommitData, PushData } from '@finos/git-proxy/types';
98
import { PushQuery } from '@finos/git-proxy/db';
9+
import { Action } from '@finos/git-proxy/proxy/actions';
1010

1111
const GIT_PROXY_COOKIE_FILE = 'git-proxy-cookie';
1212
// GitProxy UI HOST and PORT (configurable via environment variable)
@@ -88,74 +88,86 @@ async function getGitPushes(filters: Partial<PushQuery>) {
8888

8989
try {
9090
const cookies = JSON.parse(fs.readFileSync(GIT_PROXY_COOKIE_FILE, 'utf8'));
91-
92-
const response = await axios.get(`${baseUrl}/api/v1/push/`, {
91+
const { data } = await axios.get<Action[]>(`${baseUrl}/api/v1/push/`, {
9392
headers: { Cookie: cookies },
9493
params: filters,
9594
});
9695

97-
const records: PushData[] = [];
98-
response.data.forEach((push: PushData) => {
99-
const record: PushData = {
100-
id: push.id,
101-
repo: push.repo,
102-
branch: push.branch,
103-
commitFrom: push.commitFrom,
104-
commitTo: push.commitTo,
105-
commitData: push.commitData,
106-
diff: push.diff,
107-
error: push.error,
108-
canceled: push.canceled,
109-
rejected: push.rejected,
110-
blocked: push.blocked,
111-
authorised: push.authorised,
112-
attestation: push.attestation,
113-
autoApproved: push.autoApproved,
114-
timestamp: push.timestamp,
115-
url: push.url,
116-
allowPush: push.allowPush,
96+
const records = data.map((push: Action) => {
97+
const {
98+
id,
99+
repo,
100+
branch,
101+
commitFrom,
102+
commitTo,
103+
commitData,
104+
error,
105+
canceled,
106+
rejected,
107+
blocked,
108+
authorised,
109+
attestation,
110+
autoApproved,
111+
timestamp,
112+
url,
113+
allowPush,
114+
lastStep,
115+
} = push;
116+
117+
return {
118+
id,
119+
repo,
120+
branch,
121+
commitFrom,
122+
commitTo,
123+
commitData: commitData?.map(
124+
({
125+
message,
126+
committer,
127+
committerEmail,
128+
author,
129+
authorEmail,
130+
commitTimestamp,
131+
tree,
132+
parent,
133+
}) => ({
134+
message,
135+
committer,
136+
committerEmail,
137+
author,
138+
authorEmail,
139+
commitTimestamp,
140+
tree,
141+
parent,
142+
}),
143+
),
144+
error,
145+
canceled,
146+
rejected,
147+
blocked,
148+
authorised,
149+
attestation,
150+
autoApproved,
151+
timestamp,
152+
url,
153+
allowPush,
154+
lastStep: lastStep && {
155+
id: lastStep.id,
156+
content: lastStep.content,
157+
logs: lastStep.logs,
158+
stepName: lastStep.stepName,
159+
error: lastStep.error,
160+
errorMessage: lastStep.errorMessage,
161+
blocked: lastStep.blocked,
162+
blockedMessage: lastStep.blockedMessage,
163+
},
117164
};
118-
119-
if (push.lastStep) {
120-
record.lastStep = {
121-
id: push.lastStep?.id,
122-
content: push.lastStep?.content,
123-
logs: push.lastStep?.logs,
124-
stepName: push.lastStep?.stepName,
125-
error: push.lastStep?.error,
126-
errorMessage: push.lastStep?.errorMessage,
127-
blocked: push.lastStep?.blocked,
128-
blockedMessage: push.lastStep?.blockedMessage,
129-
};
130-
}
131-
132-
if (push.commitData) {
133-
const commitData: CommitData[] = [];
134-
push.commitData.forEach((pushCommitDataRecord: CommitData) => {
135-
commitData.push({
136-
message: pushCommitDataRecord.message,
137-
committer: pushCommitDataRecord.committer,
138-
committerEmail: pushCommitDataRecord.committerEmail,
139-
author: pushCommitDataRecord.author,
140-
authorEmail: pushCommitDataRecord.authorEmail,
141-
commitTimestamp: pushCommitDataRecord.commitTimestamp,
142-
tree: pushCommitDataRecord.tree,
143-
parent: pushCommitDataRecord.parent,
144-
commitTs: pushCommitDataRecord.commitTs,
145-
});
146-
});
147-
record.commitData = commitData;
148-
}
149-
150-
records.push(record);
151165
});
152166

153-
console.log(`${util.inspect(records, false, null, false)}`);
167+
console.log(util.inspect(records, false, null, false));
154168
} catch (error: any) {
155-
// default error
156-
const errorMessage = `Error: List: '${error.message}'`;
169+
console.error(`Error: List: '${error.message}'`);
157170
process.exitCode = 2;
158-
console.error(errorMessage);
159171
}
160172
}
161173

packages/git-proxy-cli/test/testCliUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ async function addGitPushToDb(
221221
parent: 'parent',
222222
author: 'author',
223223
committer: 'committer',
224-
commitTs: 'commitTs',
225224
message: 'message',
226225
authorEmail: 'authorEmail',
227226
committerEmail: 'committerEmail',

src/config/ConfigLoader.ts

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,10 @@ import { promisify } from 'util';
66
import { EventEmitter } from 'events';
77
import envPaths from 'env-paths';
88
import { GitProxyConfig, Convert } from './generated/config';
9+
import { Configuration, ConfigurationSource, FileSource, HttpSource, GitSource } from './types';
910

1011
const execFileAsync = promisify(execFile);
1112

12-
interface GitAuth {
13-
type: 'ssh';
14-
privateKeyPath: string;
15-
}
16-
17-
interface HttpAuth {
18-
type: 'bearer';
19-
token: string;
20-
}
21-
22-
interface BaseSource {
23-
type: 'file' | 'http' | 'git';
24-
enabled: boolean;
25-
}
26-
27-
interface FileSource extends BaseSource {
28-
type: 'file';
29-
path: string;
30-
}
31-
32-
interface HttpSource extends BaseSource {
33-
type: 'http';
34-
url: string;
35-
headers?: Record<string, string>;
36-
auth?: HttpAuth;
37-
}
38-
39-
interface GitSource extends BaseSource {
40-
type: 'git';
41-
repository: string;
42-
branch?: string;
43-
path: string;
44-
auth?: GitAuth;
45-
}
46-
47-
type ConfigurationSource = FileSource | HttpSource | GitSource;
48-
49-
export interface ConfigurationSources {
50-
enabled: boolean;
51-
sources: ConfigurationSource[];
52-
reloadIntervalSeconds: number;
53-
merge?: boolean;
54-
}
55-
56-
export interface Configuration extends GitProxyConfig {
57-
configurationSources?: ConfigurationSources;
58-
}
59-
6013
// Add path validation helper
6114
function isValidPath(filePath: string): boolean {
6215
if (!filePath || typeof filePath !== 'string') return false;

src/config/env.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
export type ServerConfig = {
2-
GIT_PROXY_SERVER_PORT: string | number;
3-
GIT_PROXY_HTTPS_SERVER_PORT: string | number;
4-
GIT_PROXY_UI_HOST: string;
5-
GIT_PROXY_UI_PORT: string | number;
6-
GIT_PROXY_COOKIE_SECRET: string | undefined;
7-
GIT_PROXY_MONGO_CONNECTION_STRING: string;
8-
};
1+
import { ServerConfig } from './types';
92

103
const {
114
GIT_PROXY_SERVER_PORT = 8000,

src/config/generated/config.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ export interface AdConfig {
225225
export interface JwtConfig {
226226
authorityURL: string;
227227
clientID: string;
228+
expectedAudience?: string;
229+
roleMapping?: RoleMapping;
230+
[property: string]: any;
231+
}
232+
233+
export interface RoleMapping {
234+
admin?: { [key: string]: any };
228235
[property: string]: any;
229236
}
230237

@@ -275,10 +282,15 @@ export interface Question {
275282
* and used to provide additional guidance to the reviewer.
276283
*/
277284
export interface QuestionTooltip {
278-
links?: string[];
285+
links?: Link[];
279286
text: string;
280287
}
281288

289+
export interface Link {
290+
text?: string;
291+
url?: string;
292+
}
293+
282294
export interface AuthorisedRepo {
283295
name: string;
284296
project: string;
@@ -754,9 +766,12 @@ const typeMap: any = {
754766
[
755767
{ json: 'authorityURL', js: 'authorityURL', typ: '' },
756768
{ json: 'clientID', js: 'clientID', typ: '' },
769+
{ json: 'expectedAudience', js: 'expectedAudience', typ: u(undefined, '') },
770+
{ json: 'roleMapping', js: 'roleMapping', typ: u(undefined, r('RoleMapping')) },
757771
],
758772
'any',
759773
),
774+
RoleMapping: o([{ json: 'admin', js: 'admin', typ: u(undefined, m('any')) }], 'any'),
760775
OidcConfig: o(
761776
[
762777
{ json: 'callbackURL', js: 'callbackURL', typ: '' },
@@ -780,11 +795,18 @@ const typeMap: any = {
780795
),
781796
QuestionTooltip: o(
782797
[
783-
{ json: 'links', js: 'links', typ: u(undefined, a('')) },
798+
{ json: 'links', js: 'links', typ: u(undefined, a(r('Link'))) },
784799
{ json: 'text', js: 'text', typ: '' },
785800
],
786801
false,
787802
),
803+
Link: o(
804+
[
805+
{ json: 'text', js: 'text', typ: u(undefined, '') },
806+
{ json: 'url', js: 'url', typ: u(undefined, '') },
807+
],
808+
false,
809+
),
788810
AuthorisedRepo: o(
789811
[
790812
{ json: 'name', js: 'name', typ: '' },

src/config/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { existsSync, readFileSync } from 'fs';
22

33
import defaultSettings from '../../proxy.config.json';
44
import { GitProxyConfig, Convert } from './generated/config';
5-
import { ConfigLoader, Configuration } from './ConfigLoader';
5+
import { ConfigLoader } from './ConfigLoader';
6+
import { Configuration } from './types';
67
import { serverConfig } from './env';
78
import { configFile } from './file';
89

0 commit comments

Comments
 (0)