Skip to content

Commit

Permalink
Merge pull request #6 from ConsumerDataStandardsAustralia/gh/issue3
Browse files Browse the repository at this point in the history
Gh/issue3
  • Loading branch information
tom-schier authored Feb 22, 2023
2 parents a1258c6 + 9e90e1c commit 8d70a26
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 24 deletions.
4 changes: 3 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { cdrTokenValidator } from './src/cdr-token-validator'
import { cdrJwtScopes} from './src/cdr-jwtscopes';
import defaultEnergyEndpoints from './src/data/default-energy.json';
import defaultBankingEndpoints from './src/data/default-banking.json';
import defaultCommonEndpoints from './src/data/default-common.json';
import { EndpointConfig } from './src/models/endpoint-config';
import { getEndpoint } from './src/cdr-utils';

const DefaultEnergyEndpoints = [...defaultEnergyEndpoints] as EndpointConfig[];
const DefaultBankingEndpoints = [...defaultBankingEndpoints] as EndpointConfig[];
const DefaultCommonEndpoints = [...defaultCommonEndpoints] as EndpointConfig[];

export { DsbAuthConfig } from './src/models/dsb-auth-config';
export { CdrConfig } from './src/models/cdr-config';
Expand All @@ -20,6 +22,6 @@ export { DsbResponse } from './src/models/dsb-response';

export {
cdrHeaderValidator, cdrTokenValidator, cdrJwtScopes,
DefaultEnergyEndpoints, DefaultBankingEndpoints, getEndpoint
DefaultEnergyEndpoints, DefaultBankingEndpoints, DefaultCommonEndpoints, getEndpoint
}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cds-au/holder-sdk",
"version": "1.0.0",
"version": "1.0.1",
"description": "NodeJS middleware to handle error generation in line with Australian Consumer Data Standards technical specifications",
"main": "dist/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/cdr-header-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CdrConfig } from './models/cdr-config';



export function cdrHeaderValidator(options: CdrConfig) {
export function cdrHeaderValidator(options: CdrConfig): any {

return function headers(req: Request, res: DsbResponse, next: NextFunction) {

Expand Down
2 changes: 1 addition & 1 deletion src/cdr-jwtscopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DsbResponse } from './models/dsb-response';



export function cdrJwtScopes(authOptions: DsbAuthConfig) {
export function cdrJwtScopes(authOptions: DsbAuthConfig): any {
// Extend the request object and add scopes based on JWT access token
// This implementation expects the scopes in the JWT to be a space seperated string
return function scopes(req: DsbRequest, res: DsbResponse, next: NextFunction) {
Expand Down
8 changes: 7 additions & 1 deletion src/cdr-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { Request } from 'express';
import { DsbEndpoint } from './models/dsb-endpoint-entity';
import energyEndpoints from './data/cdr-energy-endpoints.json';
import bankingEndpoints from './data/cdr-banking-endpoints.json';
import commonEndpoints from './data/cdr-common-endpoints.json';
import { EndpointConfig } from './models/endpoint-config';
import { ResponseErrorListV2 } from 'consumer-data-standards/common';

const endpoints = [...energyEndpoints, ...bankingEndpoints];
const endpoints = [...energyEndpoints, ...bankingEndpoints, ...commonEndpoints];

export function getEndpoint(req: Request, options: EndpointConfig[], errorList : ResponseErrorListV2 ): DsbEndpoint | null {

Expand All @@ -31,6 +32,11 @@ export function getEndpoint(req: Request, options: EndpointConfig[], errorList :
requestUrlArray = requestUrlArray.slice(2);
requestUrlArray = removeEmptyEntries(requestUrlArray);
// the search array which will change as the search progresses
// remove query parameters from end
let tmp1: string = requestUrlArray[requestUrlArray.length-1];
let newValArray: string[] = tmp1.split('?');
requestUrlArray[requestUrlArray.length-1] = newValArray[0];

let searchArray: string[] = requestUrlArray.slice();

let returnEP = null;
Expand Down
42 changes: 42 additions & 0 deletions src/data/cdr-common-endpoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"requestType": "GET",
"requestPath": "/common/customer",
"requiresXFAPIAuthdate": true,
"authScopesRequired": "common:customer.basic:read",
"requiresCDSClientHeader": false,
"requiresXv": true,
"requiresCDSArrangementID": false,
"requiresXFAPI": true
},
{
"requestType": "GET",
"requestPath": "/common/customer/detail",
"requiresXFAPIAuthdate": true,
"authScopesRequired": "common:customer.detail:read",
"requiresCDSClientHeader": false,
"requiresXv": true,
"requiresCDSArrangementID": false,
"requiresXFAPI": true
},
{
"requestType": "GET",
"requestPath": "/discovery/status",
"requiresXFAPIAuthdate": false,
"authScopesRequired": null,
"requiresCDSClientHeader": false,
"requiresXv": true,
"requiresCDSArrangementID": false,
"requiresXFAPI": false
},
{
"requestType": "GET",
"requestPath": "/discovery/outages",
"requiresXFAPIAuthdate": false,
"authScopesRequired": null,
"requiresCDSClientHeader": false,
"requiresXv": true,
"requiresCDSArrangementID": false,
"requiresXFAPI": false
}
]
26 changes: 26 additions & 0 deletions src/data/default-common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"requestType": "GET",
"requestPath": "/common/customer",
"minSupportedVersion": 1,
"maxSupportedVersion": 1
},
{
"requestType": "GET",
"requestPath": "/common/customer/detail",
"minSupportedVersion": 1,
"maxSupportedVersion": 2
},
{
"requestType": "GET",
"requestPath": "/discover/status",
"minSupportedVersion": 1,
"maxSupportedVersion": 1
},
{
"requestType": "GET",
"requestPath": "/discover/outages",
"minSupportedVersion": 1,
"maxSupportedVersion": 1
}
]
10 changes: 5 additions & 5 deletions src/data/default-energy.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
{
"requestType": "GET",
"requestPath": "/energy/plans",
"minSupportedVersion": 2,
"maxSupportedVersion": 4
"minSupportedVersion": 1,
"maxSupportedVersion": 1
},
{
"requestType": "GET",
Expand All @@ -25,7 +25,7 @@
},
{
"requestType": "GET",
"requestPath": " /energy/electricity/servicepoints/{servicePointId}",
"requestPath": "/energy/electricity/servicepoints/{servicePointId}",
"minSupportedVersion": 1,
"maxSupportedVersion": 1
},
Expand Down Expand Up @@ -69,13 +69,13 @@
"requestType": "GET",
"requestPath": "/energy/accounts",
"minSupportedVersion": 1,
"maxSupportedVersion": 1
"maxSupportedVersion": 2
},
{
"requestType": "GET",
"requestPath": "/energy/accounts/{accountId}",
"minSupportedVersion": 1,
"maxSupportedVersion": 1
"maxSupportedVersion": 2
},
{
"requestType": "GET",
Expand Down
14 changes: 0 additions & 14 deletions src/endpoint.json

This file was deleted.

14 changes: 14 additions & 0 deletions tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,18 @@ describe('Utility functions', () => {
expect(ep).toBeUndefined();

});

test('Find endpoints - with query string', async () => {

const endpoints = [...energyEndpoints, ...bankingEndpoints];
mockRequest = {
method: 'GET',
url: `${standardsVersion}/banking/accounts/1234567?page=2&page-size=5`,
}
let ep = getEndpoint(mockRequest as Request, options, errorList);
expect(ep).not.toBeNull()
expect(ep?.requestPath).toEqual('/banking/accounts/{accountId}');

});

});

0 comments on commit 8d70a26

Please sign in to comment.