Skip to content

Commit 72e3f27

Browse files
author
Chris
committed
Merge develop
2 parents 3223612 + 1616fca commit 72e3f27

3 files changed

Lines changed: 45 additions & 24 deletions

File tree

src/api/rest/v1/app/controller.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,53 @@ function serialize(data: any): string {
1818
}
1919

2020
export class AppController {
21+
// TODO: Gracefully handle errors
2122

2223
public async getAccount(req: Request, res: Response) {
23-
const { did } = req.veridaNetworkConnection
24+
try {
25+
const { did } = req.veridaNetworkConnection
26+
27+
const account = await BillingManager.getAccount(did)
2428

25-
const account = await BillingManager.getAccount(did)
29+
if (!account) {
30+
return res.status(404).json({
31+
success: false,
32+
error: "Account not found"
33+
})
34+
}
2635

27-
if (!account) {
28-
return res.status(404).json({
29-
success: false
36+
return res.json({
37+
success: true,
38+
account
39+
})
40+
} catch (error) {
41+
console.error(error)
42+
return res.status(500).json({
43+
success: false,
44+
error: "Something went wrong while retrieving account"
3045
})
3146
}
32-
33-
return res.json({
34-
account
35-
})
3647
}
3748

3849
public async register(req: Request, res: Response) {
3950
const { did } = req.veridaNetworkConnection
40-
51+
4152
return res.json({
4253
success: await BillingManager.registerAccount(did, BillingAccountType.APP)
4354
})
4455
}
4556

4657
public async requests(req: Request, res: Response) {
4758
const { did } = req.veridaNetworkConnection
48-
59+
4960
return res.json({
5061
results: await UsageManager.getRequests(did)
5162
})
5263
}
5364

5465
public async accountCount(req: Request, res: Response) {
5566
const { did } = req.veridaNetworkConnection
56-
67+
5768
return res.json(serialize({
5869
count: await UsageManager.getAccountCount(did)
5970
}))
@@ -63,15 +74,15 @@ export class AppController {
6374
const { did } = req.veridaNetworkConnection
6475
const startDateTime = req.params.start ? req.params.start.toString() : undefined
6576
const endDateTime = req.params.end ? req.params.end.toString() : undefined
66-
77+
6778
return res.json(serialize({
6879
usage: await UsageManager.getUsageStats(did, startDateTime, endDateTime)
6980
}))
7081
}
7182

7283
public async balance(req: Request, res: Response) {
7384
const { did } = req.veridaNetworkConnection
74-
85+
7586
const balance = await BillingManager.getBalance(did)
7687
return res.json(serialize({
7788
balance
@@ -87,7 +98,7 @@ export class AppController {
8798

8899
public async deposits(req: Request, res: Response) {
89100
const { did } = req.veridaNetworkConnection
90-
101+
91102
return res.json(serialize({
92103
deposits: await BillingManager.getDeposits(did)
93104
}))
@@ -130,4 +141,4 @@ export class AppController {
130141
}
131142

132143
const controller = new AppController()
133-
export default controller
144+
export default controller

src/api/rest/v1/app/routes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import auth from "../../../../middleware/auth";
44

55
const router = express.Router()
66
const appAuth = auth({
7+
scopes: ['api:app-developer'],
78
options: {
89
// App DID's don't need to be whitelisted
910
ignoreAccessCheck: true
@@ -20,4 +21,4 @@ router.get('/vda-price', appAuth, Controller.vdaPrice)
2021
router.get('/deposits', appAuth, Controller.deposits)
2122
router.post('/deposit-crypto', appAuth, Controller.depositCrypto)
2223

23-
export default router
24+
export default router

src/api/rest/v1/auth/scopes.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ function appendNewOnly(scopes: string[], newScope: string): string[] {
109109
/**
110110
* Take an array of scopes and expand any short hand scopes (ie: ds:file) to
111111
* the full scope. Convert base64 encoded URL scopes to have the actual URL.
112-
*
112+
*
113113
* If the same datastore or database scope is listed multiple times, merge them.
114-
*
114+
*
115115
* (ie: ds:r:<schema> and ds:rw:<schema>)
116-
*
117-
* @param scopes
116+
*
117+
* @param scopes
118118
*/
119119
export function expandScopes(scopes: string[], expandPermissions: boolean = true): ExpandedScopes {
120120
const scopeValidity: Record<string, boolean> = {}
@@ -251,7 +251,7 @@ const SCOPES: Record<string, Scope> = {
251251

252252
/**
253253
* Datastore Access Scopes
254-
*
254+
*
255255
* Dynamically injected below
256256
*/
257257
"api:llm-prompt": {
@@ -298,7 +298,16 @@ const SCOPES: Record<string, Scope> = {
298298
type: ScopeType.API,
299299
description: "Access status information on connected third party accounts (ie: Google, Telegram)",
300300
userNote: `Access status information on connected third party accounts (ie: Google, Telegram)`
301-
}
301+
},
302+
303+
/**
304+
* App Developer Scopes
305+
*/
306+
"api:app-developer": {
307+
type: ScopeType.API,
308+
description: "Access app developer features",
309+
userNote: "Access app developer features"
310+
},
302311
}
303312

304313
for (const datastoreId in DATASTORE_LOOKUP) {
@@ -349,4 +358,4 @@ for (const scope in SCOPES) {
349358
}
350359
}
351360

352-
export default SCOPES
361+
export default SCOPES

0 commit comments

Comments
 (0)