Skip to content

Commit f774f0c

Browse files
authored
Merge pull request #116 from amazon-ospo/addNameField
feat: Adding name field in installation API responses
2 parents d31f996 + 7d8b995 commit f774f0c

File tree

10 files changed

+199
-28
lines changed

10 files changed

+199
-28
lines changed

src/packages/app-framework/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/packages/app-framework/src/credential-manager/installation-tracker/index.handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export const handlerImpl: Handler = async ({
104104
appId: appId,
105105
nodeId: installation.account ? installation.account.node_id : '',
106106
targetType: installation.target_type,
107+
name: installation.account ? installation.account.login : '',
107108
};
108109
}),
109110
);

src/packages/app-framework/src/credential-manager/refresh/refreshCachedData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export const refreshCachedDataImpl: RefreshCachedData = async ({
8787
appId: appId,
8888
nodeId: installation.account ? installation.account.node_id : '',
8989
targetType: installation.target_type,
90+
name: installation.account ? installation.account.login : '',
9091
};
9192
}),
9293
);

src/packages/app-framework/src/data.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type InstallationRecord = {
1515
installationId: number;
1616
nodeId: string;
1717
targetType: string;
18+
name: string;
1819
};
1920

2021
type AppInstallations = {
@@ -118,13 +119,15 @@ export type PutInstallation = ({
118119
nodeId,
119120
installationId,
120121
targetType,
122+
name,
121123
lastRefreshed,
122124
}: {
123125
tableName: string;
124126
appId: number;
125127
nodeId: string;
126128
installationId: number;
127129
targetType: string;
130+
name: string;
128131
lastRefreshed?: string;
129132
}) => Promise<void>;
130133

@@ -134,6 +137,7 @@ export const putInstallationImpl: PutInstallation = async ({
134137
nodeId,
135138
installationId,
136139
targetType,
140+
name,
137141
lastRefreshed,
138142
}): Promise<void> => {
139143
const tableOperations = new TableOperations({
@@ -145,6 +149,7 @@ export const putInstallationImpl: PutInstallation = async ({
145149
NodeId: { S: nodeId },
146150
InstallationId: { N: installationId.toString() },
147151
TargetType: { S: targetType },
152+
Name: { S: name },
148153
LastRefreshed: { S: lastRefreshed || '' },
149154
};
150155

@@ -248,12 +253,14 @@ export const getInstallationsImpl: GetInstallations = async ({ tableName }) => {
248253
const appId: number = item.AppId;
249254
const installationId: number = item.InstallationId;
250255
const targetType: string = item.targetType;
256+
const name: string = item.Name ?? '';
251257
const nodeId: string = item.NodeId ?? '';
252258
result.push({
253259
appId,
254260
nodeId,
255261
installationId,
256262
targetType,
263+
name,
257264
});
258265
});
259266
return result;
@@ -286,12 +293,14 @@ export const getInstallationsDataByNodeId: GetInstallationsByNodeId = async ({
286293
const appId: number = item.AppId;
287294
const itemNodeId: string = item.NodeId;
288295
const installationId: number = item.InstallationId;
289-
const targetType: string = item.targetType;
296+
const targetType: string = item.TargetType;
297+
const name: string = item.Name ?? '';
290298
result.push({
291299
appId,
292300
nodeId: itemNodeId,
293301
installationId,
294302
targetType,
303+
name,
295304
});
296305
});
297306

@@ -353,13 +362,16 @@ export const getPaginatedInstallationsImpl: GetPaginatedInstallations = async ({
353362
const appId: number = item.AppId;
354363
const installationId: number = item.InstallationId;
355364
const targetType: string = item.TargetType;
365+
const name: string = item.Name ?? '';
356366
const nodeId: string = item.NodeId ?? '';
357367
installations.push({
358368
appId,
359369
nodeId,
360370
installationId,
361371
targetType,
372+
name,
362373
});
363374
});
375+
console.log(installations);
364376
return { installations, LastEvaluatedKey };
365377
};

src/packages/app-framework/test/data.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const mockInstallationId = 123456;
2828
const mockAppId2 = 12346;
2929
const mockInstallationId2 = 123457;
3030
const mockTargetType = 'Organization';
31+
const mockName = 'test-org';
3132
const mockArn = 'arn:aws:kms:region:account:key/mock-key-id';
3233
describe('getKeyArnByID', () => {
3334
it('should successfully retrieve KMS ARN from DynamoDB', async () => {
@@ -229,6 +230,7 @@ describe('getInstallationId', () => {
229230
installationId: mockInstallationId,
230231
nodeId: mockNodeId,
231232
targetType: mockTargetType,
233+
name: mockName,
232234
});
233235

234236
expect(TableOperations).toHaveBeenCalledWith({
@@ -240,6 +242,7 @@ describe('getInstallationId', () => {
240242
LastRefreshed: { S: '' },
241243
NodeId: { S: mockNodeId },
242244
TargetType: { S: mockTargetType },
245+
Name: { S: mockName },
243246
});
244247
});
245248

@@ -255,6 +258,7 @@ describe('getInstallationId', () => {
255258
installationId: mockInstallationId,
256259
nodeId: mockNodeId,
257260
targetType: mockTargetType,
261+
name: mockName,
258262
}),
259263
).rejects.toThrow('DynamoDB service error');
260264
});
@@ -308,6 +312,8 @@ describe('getInstallationId', () => {
308312
appId: mockAppId,
309313
nodeId: mockNodeId,
310314
installationId: mockInstallationId,
315+
targetType: undefined,
316+
name: '',
311317
},
312318
]);
313319
expect(TableOperations).toHaveBeenCalledWith({
@@ -351,11 +357,15 @@ describe('getInstallationId', () => {
351357
appId: mockAppId,
352358
nodeId: mockNodeId,
353359
installationId: mockInstallationId,
360+
targetType: undefined,
361+
name: '',
354362
},
355363
{
356364
appId: mockAppId2,
357365
nodeId: mockNodeId,
358366
installationId: mockInstallationId2,
367+
targetType: undefined,
368+
name: '',
359369
},
360370
]);
361371
expect(TableOperations).toHaveBeenCalledWith({
@@ -457,12 +467,14 @@ describe('getInstallationId', () => {
457467
nodeId: '',
458468
installationId: mockInstallationId,
459469
targetType: mockTargetType,
470+
name: '',
460471
},
461472
{
462473
appId: mockAppId2,
463474
nodeId: mockNodeId,
464475
installationId: mockInstallationId2,
465476
targetType: mockTargetType,
477+
name: '',
466478
},
467479
]);
468480
expect(TableOperations).toHaveBeenCalledWith({

src/packages/app-framework/test/get-installation-data/getInstallationData.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ describe('getInstallationsDataImpl', () => {
1515
installationId: 67890,
1616
nodeId: mockNodeId,
1717
targetType: 'Organization',
18+
name: 'test-org-1',
1819
},
1920
{
2021
appId: 54321,
2122
installationId: 98765,
2223
nodeId: mockNodeId,
2324
targetType: 'Organization',
25+
name: 'test-org-2',
2426
},
2527
];
2628

@@ -97,18 +99,21 @@ describe('getInstallationsDataImpl', () => {
9799
installationId: 67890,
98100
nodeId: mockNodeId,
99101
targetType: 'Organization',
102+
name: 'test-org-1',
100103
},
101104
{
102105
appId: 54321,
103106
installationId: 98765,
104107
nodeId: mockNodeId,
105108
targetType: 'Organization',
109+
name: 'test-org-2',
106110
},
107111
{
108112
appId: 11111,
109113
installationId: 22222,
110114
nodeId: mockNodeId,
111115
targetType: 'Organization',
116+
name: 'test-org-3',
112117
},
113118
];
114119
const mockGetInstallationsDataByNodeId = jest

src/packages/app-framework/test/get-installations/getInstallations.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ describe('getInstallationRecordsImpl', () => {
1414
installationId: 67890,
1515
nodeId: mockNodeId,
1616
targetType: 'Organization',
17+
name: 'test-org-1',
1718
},
1819
{
1920
appId: 54321,
2021
installationId: 98765,
2122
nodeId: mockNodeId,
2223
targetType: 'Organization',
24+
name: 'test-org-2',
2325
},
2426
];
2527

0 commit comments

Comments
 (0)