Skip to content

Commit

Permalink
Added user-agent and versioning. (#32)
Browse files Browse the repository at this point in the history
* Added user agent.
* Added versioning.
  • Loading branch information
bre1470 authored Sep 13, 2024
1 parent fab4ddc commit d05a0d8
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package-build.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"version": "0.4.0",
"version": "0.4.1",
"name": "@highcharts/connectors-morningstar",
"license": "UNLICENSED",
"description": "Highcharts connectors for Morningstar Direct Web Services",
Expand All @@ -27,7 +27,7 @@
"Morningstar",
"Time Series"
],
"peerDependencies": {
"@highcharts/dashboards": "^2.2.0"
"optionalDependencies": {
"@highcharts/dashboards": ">=2.3.0"
}
}
9 changes: 9 additions & 0 deletions src/Shared/MorningstarAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import MorningstarAuthentication from './MorningstarAccess';
import MorningstarError from './MorningstarError';
import MorningstarRegion from './MorningstarRegion';
import MorningstarURL from './MorningstarURL';
import { version } from '../version';


/* *
Expand Down Expand Up @@ -144,6 +145,14 @@ export class MorningstarAPI {
requestInit = this.access.authorizeRequest(requestInit);
}

const headers = (
requestInit.headers instanceof Headers ?
requestInit.headers :
new Headers(requestInit.headers)
);

headers.set('User-Agent', `HighchartsConnectorsMorningstar/${version}`);

const response = await window.fetch(url, requestInit);

if (!response.url.startsWith('https')) {
Expand Down
4 changes: 3 additions & 1 deletion src/Shared/MorningstarAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import type { MorningstarAccessOptions } from './MorningstarOptions';

import MorningstarRegion from './MorningstarRegion';
import { version } from '../version';


/* *
Expand Down Expand Up @@ -221,7 +222,8 @@ export class MorningstarAccess {
cache: 'no-cache',
credentials: 'omit',
headers: new Headers({
Authorization: `Basic ${payload}`
Authorization: `Basic ${payload}`,
'User-Agent': `HighchartsConnectorsMorningstar/${version}`
}),
method: 'POST',
redirect: 'error'
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import RNANews from './RNANews/index';
import * as Shared from './Shared/index';
import TimeSeries from './TimeSeries/index';
import { version } from './version';


/* *
Expand All @@ -37,6 +38,7 @@ import TimeSeries from './TimeSeries/index';
export * from './RNANews/index';
export * as Shared from './Shared/index';
export * from './TimeSeries/index';
export { version } from './version';


/* *
Expand All @@ -49,5 +51,6 @@ export * from './TimeSeries/index';
export default {
RNANews,
Shared,
TimeSeries
TimeSeries,
version
};
3 changes: 3 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Generated by tools/dist. !!!!!!! DO NOT EDIT !!!!!!!
export const version = '0.4.1';
export default version;
2 changes: 1 addition & 1 deletion test/unit-tests/Shared/MorningstarAPI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as MC from '../../../code/connectors-morningstar.src';

export async function apiAccess (
apiOptions: MC.Shared.MorningstarAPIOptions
) {
): Promise<void> {
const api = new MC.Shared.MorningstarAPI(apiOptions);

Assert.ok(
Expand Down
18 changes: 18 additions & 0 deletions test/unit-tests/version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as Assert from 'node:assert/strict';
import * as MC from '../../code/connectors-morningstar.src';

export function version (): void {

Assert.strictEqual(
typeof MC.version,
'string',
'Morningstar API version should be a string.'
);

Assert.strictEqual(
MC.version.split('.').length,
3,
'Morningstar API version should be valid.'
);

}
8 changes: 8 additions & 0 deletions tools/dist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ async function build (): Promise<void> {
const packageJSON =
JSON.parse(await FSP.readFile(packagePath, 'utf8')) as Record<string, string>;
const originalVersion = packageJSON.version;
const versionPath = Path.join(__dirname, '..', 'src', 'version.ts');

try {

Expand All @@ -144,6 +145,13 @@ async function build (): Promise<void> {
JSON.stringify(packageJSON, null, ' ') + '\n',
'utf8'
);
await FSP.writeFile(
versionPath,
'// Generated by tools/dist. !!!!!!! DO NOT EDIT !!!!!!!\n' +
`export const version = '${ARGS.release.replace(/'/gu, '"')}';\n` +
'export default version;\n',
'utf8'
);

log('⏳', 'Build', '...');
ChildProcess.execFileSync('npm', [ 'run', 'build' ], { stdio: 'inherit' });
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const sharedConfiguration: Configuration = {

mode: 'production',

devtool: 'hidden-source-map',
devtool: 'source-map',

performance: {
hints: 'error',
Expand Down

0 comments on commit d05a0d8

Please sign in to comment.