Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/docker-and-…
Browse files Browse the repository at this point in the history
…package-upgrades-new
  • Loading branch information
lukehesluke committed Mar 28, 2024
2 parents 7b14853 + a7cf1cd commit 9f57cbc
Show file tree
Hide file tree
Showing 61 changed files with 1,189 additions and 539 deletions.
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@
"NODE_APP_INSTANCE": "dev"
},
},
{
"name": "broker-microservice - jest tests",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}/packages/openactive-broker-microservice",
"runtimeExecutable": "npm",
"runtimeVersion": "18.17.1",
"runtimeArgs": ["run-script", "debug-jest"],
"port": 9229,
},
{
"name": "test-interface-criteria - unit tests",
"type": "node",
Expand Down
5 changes: 3 additions & 2 deletions packages/openactive-broker-microservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/openactive-broker-microservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"validate-feeds": "node app.js --validate-only",
"test": "npm run lint && tsc && jest",
"debug": "node --inspect app.js",
"lint": "eslint \"*.js\" \"src/**/*.js\"",
"debug-jest": "node --inspect ./node_modules/.bin/jest --runInBand",
"lint": "eslint \"*.js\" \"src/**/*.js\" \"test/**/*.js\"",
"lint-fix": "npm run lint -- --fix"
},
"author": "OpenActive Community <hello@openactive.io>",
Expand All @@ -18,7 +19,7 @@
"@openactive/data-model-validator": "^2.0.78",
"@openactive/data-models": "^2.0.316",
"@openactive/dataset-utils": "^1.0.1",
"@openactive/harvesting-utils": "github:openactive/harvesting-utils#3eb7749",
"@openactive/harvesting-utils": "github:openactive/harvesting-utils#1b2877834055549572fa059a491ac17d306942fd",
"@openactive/openactive-openid-browser-automation": "file:../openactive-openid-browser-automation",
"@openactive/openactive-openid-client": "file:../openactive-openid-client",
"@openactive/rpde-validator": "^2.0.20",
Expand Down
164 changes: 87 additions & 77 deletions packages/openactive-broker-microservice/src/broker-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,92 @@
const path = require('path');
const config = require('config');

const PORT = normalizePort(process.env.PORT || '3000');
const MICROSERVICE_BASE_URL = `http://localhost:${PORT}`;

const VALIDATE_ONLY = process.argv.includes('--validate-only');
const ITEM_VALIDATION_MODE = VALIDATE_ONLY ? 'RPDEFeed' : 'BookableRPDEFeed';

const DATASET_SITE_URL = VALIDATE_ONLY ? process.argv[3] : config.get('broker.datasetSiteUrl');
const REQUEST_LOGGING_ENABLED = config.get('broker.requestLogging');
const WAIT_FOR_HARVEST = VALIDATE_ONLY ? false : config.get('broker.waitForHarvestCompletion');
const VERBOSE = config.get('broker.verbose');
const OUTPUT_PATH = config.get('broker.outputPath');
const IS_RUNNING_IN_CI = config.has('ci') ? config.get('ci') : false;
// TODO: move this property to the root of the config as it is used in both
// broker and the integration tests. Broker should only access config from
// either the root or within `.broker`
const USE_RANDOM_OPPORTUNITIES = config.get('integrationTests.useRandomOpportunities');

const HARVEST_START_TIME = (new Date()).toISOString();
/** @type {import('./models/core').OrderFeedIdentifier} */
const ORDERS_FEED_IDENTIFIER = 'OrdersFeed';
/** @type {import('./models/core').OrderFeedIdentifier} */
const ORDER_PROPOSALS_FEED_IDENTIFIER = 'OrderProposalsFeed';

const BOOKING_PARTNER_IDENTIFIERS = Object.entries(config.get('broker.bookingPartners')).map(([key, value]) => {
if (value) return key;
return null;
}).filter(Boolean);

// These options are not recommended for general use, but are available for specific test environment configuration and debugging
const OPPORTUNITY_FEED_REQUEST_HEADERS = config.has('broker.opportunityFeedRequestHeaders') ? config.get('broker.opportunityFeedRequestHeaders') : {};
const DATASET_DISTRIBUTION_OVERRIDE = config.has('broker.datasetDistributionOverride') ? config.get('broker.datasetDistributionOverride') : [];
const DO_NOT_FILL_BUCKETS = config.has('broker.disableBucketAllocation') ? config.get('broker.disableBucketAllocation') : false;
const DO_NOT_HARVEST_ORDERS_FEED = config.has('broker.disableOrdersFeedHarvesting') ? config.get('broker.disableOrdersFeedHarvesting') : false;
const DISABLE_BROKER_TIMEOUT = config.has('broker.disableBrokerMicroserviceTimeout') ? config.get('broker.disableBrokerMicroserviceTimeout') : false;
const LOG_AUTH_CONFIG = config.has('broker.logAuthConfig') ? config.get('broker.logAuthConfig') : false;

const BUTTON_SELECTORS = config.has('broker.loginPagesSelectors') ? config.get('broker.loginPagesSelectors') : {
username: "[name='username' i]",
password: "[name='password' i]",
button: '.btn-primary',
};
const CONSOLE_OUTPUT_LEVEL = config.has('consoleOutputLevel') ? config.get('consoleOutputLevel') : 'detailed';

const HEADLESS_AUTH = config.has('broker.headlessAuth') ? config.get('broker.headlessAuth') : true;

/** Directory for Validator remote JSON cache (https://github.com/openactive/data-model-validator#remotejsoncachepath) */
const VALIDATOR_TMP_DIR = './tmp';
/** Input files for the Validator Worker Pool are saved in this directory */
const VALIDATOR_INPUT_TMP_DIR = path.join(__dirname, '..', 'tmp-validator-input');
/**
* @typedef {typeof brokerConfig} BrokerConfig
*/

const brokerConfig = getBrokerConfig();

function getBrokerConfig() {
const PORT = normalizePort(process.env.PORT || '3000');
const MICROSERVICE_BASE_URL = `http://localhost:${PORT}`;

const VALIDATE_ONLY = process.argv.includes('--validate-only');
const ITEM_VALIDATION_MODE = VALIDATE_ONLY ? 'RPDEFeed' : 'BookableRPDEFeed';

const DATASET_SITE_URL = VALIDATE_ONLY ? process.argv[3] : config.get('broker.datasetSiteUrl');
const REQUEST_LOGGING_ENABLED = config.get('broker.requestLogging');
const WAIT_FOR_HARVEST = VALIDATE_ONLY ? false : config.get('broker.waitForHarvestCompletion');
const VERBOSE = config.get('broker.verbose');
const OUTPUT_PATH = config.get('broker.outputPath');
const IS_RUNNING_IN_CI = config.has('ci') ? config.get('ci') : false;
// TODO: move this property to the root of the config as it is used in both
// broker and the integration tests. Broker should only access config from
// either the root or within `.broker`
const USE_RANDOM_OPPORTUNITIES = config.get('integrationTests.useRandomOpportunities');

const HARVEST_START_TIME = (new Date()).toISOString();
/** @type {import('./models/core').OrderFeedIdentifier} */
const ORDERS_FEED_IDENTIFIER = 'OrdersFeed';
/** @type {import('./models/core').OrderFeedIdentifier} */
const ORDER_PROPOSALS_FEED_IDENTIFIER = 'OrderProposalsFeed';

const BOOKING_PARTNER_IDENTIFIERS = Object.entries(config.get('broker.bookingPartners')).map(([key, value]) => {
if (value) return key;
return null;
}).filter(Boolean);

// These options are not recommended for general use, but are available for specific test environment configuration and debugging
const OPPORTUNITY_FEED_REQUEST_HEADERS = config.has('broker.opportunityFeedRequestHeaders') ? config.get('broker.opportunityFeedRequestHeaders') : {};
const DATASET_DISTRIBUTION_OVERRIDE = config.has('broker.datasetDistributionOverride') ? config.get('broker.datasetDistributionOverride') : [];
const DO_NOT_FILL_BUCKETS = config.has('broker.disableBucketAllocation') ? config.get('broker.disableBucketAllocation') : false;
const DO_NOT_HARVEST_ORDERS_FEED = config.has('broker.disableOrdersFeedHarvesting') ? config.get('broker.disableOrdersFeedHarvesting') : false;
const DISABLE_BROKER_TIMEOUT = config.has('broker.disableBrokerMicroserviceTimeout') ? config.get('broker.disableBrokerMicroserviceTimeout') : false;
const LOG_AUTH_CONFIG = config.has('broker.logAuthConfig') ? config.get('broker.logAuthConfig') : false;

const BUTTON_SELECTORS = config.has('broker.loginPagesSelectors') ? config.get('broker.loginPagesSelectors') : {
username: "[name='username' i]",
password: "[name='password' i]",
button: '.btn-primary',
};
const CONSOLE_OUTPUT_LEVEL = config.has('consoleOutputLevel') ? config.get('consoleOutputLevel') : 'detailed';

const HEADLESS_AUTH = config.has('broker.headlessAuth') ? config.get('broker.headlessAuth') : true;

/** Directory for Validator remote JSON cache (https://github.com/openactive/data-model-validator#remotejsoncachepath) */
const VALIDATOR_TMP_DIR = './tmp';
/** Input files for the Validator Worker Pool are saved in this directory */
const VALIDATOR_INPUT_TMP_DIR = path.join(__dirname, '..', 'tmp-validator-input');

return {
PORT,
MICROSERVICE_BASE_URL,
VALIDATE_ONLY,
ITEM_VALIDATION_MODE,
DATASET_SITE_URL,
REQUEST_LOGGING_ENABLED,
WAIT_FOR_HARVEST,
VERBOSE,
OUTPUT_PATH,
IS_RUNNING_IN_CI,
USE_RANDOM_OPPORTUNITIES,
HARVEST_START_TIME,
ORDERS_FEED_IDENTIFIER,
ORDER_PROPOSALS_FEED_IDENTIFIER,
OPPORTUNITY_FEED_REQUEST_HEADERS,
DATASET_DISTRIBUTION_OVERRIDE,
DO_NOT_FILL_BUCKETS,
DO_NOT_HARVEST_ORDERS_FEED,
DISABLE_BROKER_TIMEOUT,
LOG_AUTH_CONFIG,
BUTTON_SELECTORS,
CONSOLE_OUTPUT_LEVEL,
HEADLESS_AUTH,
VALIDATOR_TMP_DIR,
VALIDATOR_INPUT_TMP_DIR,
BOOKING_PARTNER_IDENTIFIERS,
};
}

/**
* Normalize a port into a number, string, or false.
Expand All @@ -75,31 +112,4 @@ function normalizePort(val) {
return false;
}

module.exports = {
PORT,
MICROSERVICE_BASE_URL,
VALIDATE_ONLY,
ITEM_VALIDATION_MODE,
DATASET_SITE_URL,
REQUEST_LOGGING_ENABLED,
WAIT_FOR_HARVEST,
VERBOSE,
OUTPUT_PATH,
IS_RUNNING_IN_CI,
USE_RANDOM_OPPORTUNITIES,
HARVEST_START_TIME,
ORDERS_FEED_IDENTIFIER,
ORDER_PROPOSALS_FEED_IDENTIFIER,
OPPORTUNITY_FEED_REQUEST_HEADERS,
DATASET_DISTRIBUTION_OVERRIDE,
DO_NOT_FILL_BUCKETS,
DO_NOT_HARVEST_ORDERS_FEED,
DISABLE_BROKER_TIMEOUT,
LOG_AUTH_CONFIG,
BUTTON_SELECTORS,
CONSOLE_OUTPUT_LEVEL,
HEADLESS_AUTH,
VALIDATOR_TMP_DIR,
VALIDATOR_INPUT_TMP_DIR,
BOOKING_PARTNER_IDENTIFIERS,
};
module.exports = brokerConfig;
Loading

0 comments on commit 9f57cbc

Please sign in to comment.