-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from dimitrov-d/master
Implement RPC module
- Loading branch information
Showing
13 changed files
with
270 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ApillonModel } from '../../lib/apillon'; | ||
|
||
export class RpcApiKey extends ApillonModel { | ||
/** | ||
* Unique identifier of the RPC API key. | ||
*/ | ||
public id: number = null; | ||
|
||
/** | ||
* Name of the RPC API key. | ||
*/ | ||
public name: string = null; | ||
|
||
/** | ||
* Description of the RPC API key. | ||
*/ | ||
public description: string = null; | ||
|
||
/** | ||
* Unique identifier of the project. | ||
*/ | ||
public projectUuid: string = null; | ||
|
||
/** | ||
* Unique identifier of the RPC API key, used for RPC calls. | ||
*/ | ||
public uuid: string = null; | ||
|
||
/** | ||
* Array of favorite URLs for the RPC API key. | ||
*/ | ||
public urls: string[] = []; | ||
|
||
/** | ||
* Constructor which should only be called via Rpc class. | ||
* @param id Unique identifier of the RPC API key. | ||
* @param data Data to populate RPC API key with. | ||
*/ | ||
constructor(id: number, data?: Partial<RpcApiKey>) { | ||
super(id.toString()); | ||
this.API_PREFIX = `/rpc/api-key/${id}`; | ||
this.populate(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { ApillonModule, ICreateApillonModel } from '../../lib/apillon'; | ||
import { ApillonApi } from '../../lib/apillon-api'; | ||
import { constructUrlWithQueryParams } from '../../lib/common'; | ||
import { IApillonList, IApillonPagination } from '../../types/apillon'; | ||
import { RpcEndpoint } from '../../types/rpc'; | ||
import { RpcApiKey } from './rpc-api-key'; | ||
|
||
export class Rpc extends ApillonModule { | ||
/** | ||
* API URL for RPC module. | ||
*/ | ||
private API_PREFIX = '/rpc'; | ||
|
||
/** | ||
* List all API keys for RPC. | ||
* @param {IApillonPagination} params - The query parameters for filtering API keys. | ||
* @returns The list of API keys. | ||
*/ | ||
public async listApiKeys( | ||
params?: IApillonPagination, | ||
): Promise<IApillonList<RpcApiKey>> { | ||
const url = constructUrlWithQueryParams( | ||
`${this.API_PREFIX}/api-key`, | ||
params, | ||
); | ||
|
||
const data = await ApillonApi.get<IApillonList<RpcApiKey>>(url); | ||
|
||
return { | ||
...data, | ||
items: data.items.map((apiKey) => new RpcApiKey(apiKey.id, apiKey)), | ||
}; | ||
} | ||
|
||
/** | ||
* Create a new API key for RPC module. | ||
* @param {ApillonApiCreateRpcApiKeyDto} data - The data for creating an API key. | ||
* @returns The created API key. | ||
*/ | ||
public async createApiKey(data: ICreateApillonModel): Promise<RpcApiKey> { | ||
const apiKey = await ApillonApi.post<any>( | ||
`${this.API_PREFIX}/api-key`, | ||
data, | ||
); | ||
return new RpcApiKey(apiKey.uuid, apiKey); | ||
} | ||
|
||
/** | ||
* Get all available endpoints for the RPC service. | ||
* @returns The list of endpoints. | ||
*/ | ||
public async listEndpoints(): Promise<RpcEndpoint[]> { | ||
return await ApillonApi.get<RpcEndpoint[]>(`${this.API_PREFIX}/endpoints`); | ||
} | ||
|
||
/** | ||
* @param id Unique API key identifier. | ||
* @returns An empty instance of RpcApiKey. | ||
*/ | ||
public apiKey(id: number): RpcApiKey { | ||
return new RpcApiKey(id, null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Rpc } from '../modules/rpc/rpc'; | ||
import { RpcApiKey } from '../modules/rpc/rpc-api-key'; | ||
import { getConfig } from './helpers/helper'; | ||
|
||
describe('Rpc Module tests', () => { | ||
let rpc: Rpc; | ||
let apiKeyId: number; | ||
|
||
beforeAll(() => { | ||
rpc = new Rpc(getConfig()); | ||
}); | ||
|
||
test('Create new API key', async () => { | ||
const apiKeyData = { | ||
name: 'Test API Key', | ||
description: 'Test Description', | ||
}; | ||
const apiKey = await rpc.createApiKey(apiKeyData); | ||
|
||
expect(apiKey).toBeInstanceOf(RpcApiKey); | ||
expect(apiKey.name).toEqual(apiKeyData.name); | ||
expect(apiKey.description).toEqual(apiKeyData.description); | ||
expect(apiKey.uuid).toBeTruthy(); | ||
expect(apiKey.id).toBeTruthy(); | ||
|
||
apiKeyId = apiKey.id; | ||
}); | ||
|
||
test('List API keys', async () => { | ||
const { items } = await rpc.listApiKeys(); | ||
|
||
expect(items.length).toBeGreaterThanOrEqual(0); | ||
items.forEach((apiKey) => { | ||
expect(apiKey).toBeInstanceOf(RpcApiKey); | ||
expect(apiKey.name).toBeTruthy(); | ||
expect(apiKey.uuid).toBeTruthy(); | ||
expect(apiKey.id).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
test('Get specific API key', async () => { | ||
const apiKey = await rpc.apiKey(apiKeyId).get(); | ||
|
||
expect(apiKey).toBeInstanceOf(RpcApiKey); | ||
expect(apiKey.id).toEqual(apiKeyId); | ||
}); | ||
|
||
test('List endpoints', async () => { | ||
const endpoints = await rpc.listEndpoints(); | ||
|
||
expect(Array.isArray(endpoints)).toBeTruthy(); | ||
expect(endpoints.length).toBeGreaterThanOrEqual(0); | ||
|
||
endpoints.forEach((endpoint) => { | ||
expect(endpoint).toMatchObject({ | ||
id: expect.any(Number), | ||
name: expect.any(String), | ||
imageUrl: expect.any(String), | ||
type: expect.any(String), | ||
version: expect.any(String), | ||
networkName: expect.any(String), | ||
networkId: expect.any(Number), | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.