Browse Source
Bugfix/jsonpath import in manual service (#6129)
* Fix jsonpath import
* Update changelog
pull/6124/head
Thomas Kaul
5 days ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with
55 additions and
4 deletions
-
CHANGELOG.md
-
apps/api/src/helper/object.helper.spec.ts
-
apps/api/src/helper/object.helper.ts
-
apps/api/src/services/data-provider/manual/manual.service.ts
-
package-lock.json
-
package.json
|
|
|
@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. |
|
|
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), |
|
|
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
|
|
|
|
|
|
|
## Unreleased |
|
|
|
|
|
|
|
### Fixed |
|
|
|
|
|
|
|
- Fixed the import of `jsonpath` to support REST APIs (`JSON`) via the scraper configuration |
|
|
|
|
|
|
|
## 2.226.0 - 2026-01-01 |
|
|
|
|
|
|
|
### Added |
|
|
|
|
|
|
|
@ -1,4 +1,24 @@ |
|
|
|
import { redactAttributes } from './object.helper'; |
|
|
|
import { query, redactAttributes } from './object.helper'; |
|
|
|
|
|
|
|
describe('query', () => { |
|
|
|
it('should get market price from stock API response', () => { |
|
|
|
const object = { |
|
|
|
currency: 'USD', |
|
|
|
market: { |
|
|
|
previousClose: 273.04, |
|
|
|
price: 271.86 |
|
|
|
}, |
|
|
|
symbol: 'AAPL' |
|
|
|
}; |
|
|
|
|
|
|
|
const result = query({ |
|
|
|
object, |
|
|
|
pathExpression: '$.market.price' |
|
|
|
})[0]; |
|
|
|
|
|
|
|
expect(result).toBe(271.86); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe('redactAttributes', () => { |
|
|
|
it('should redact provided attributes', () => { |
|
|
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
import { Big } from 'big.js'; |
|
|
|
import jsonpath from 'jsonpath'; |
|
|
|
import { cloneDeep, isArray, isObject } from 'lodash'; |
|
|
|
|
|
|
|
export function hasNotDefinedValuesInObject(aObject: Object): boolean { |
|
|
|
@ -31,6 +32,16 @@ export function nullifyValuesInObjects<T>(aObjects: T[], keys: string[]): T[] { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
export function query({ |
|
|
|
object, |
|
|
|
pathExpression |
|
|
|
}: { |
|
|
|
object: object; |
|
|
|
pathExpression: string; |
|
|
|
}) { |
|
|
|
return jsonpath.query(object, pathExpression); |
|
|
|
} |
|
|
|
|
|
|
|
export function redactAttributes({ |
|
|
|
isFirstRun = true, |
|
|
|
object, |
|
|
|
|
|
|
|
@ -1,3 +1,4 @@ |
|
|
|
import { query } from '@ghostfolio/api/helper/object.helper'; |
|
|
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; |
|
|
|
import { |
|
|
|
DataProviderInterface, |
|
|
|
@ -26,7 +27,6 @@ import { Injectable, Logger } from '@nestjs/common'; |
|
|
|
import { DataSource, SymbolProfile } from '@prisma/client'; |
|
|
|
import * as cheerio from 'cheerio'; |
|
|
|
import { addDays, format, isBefore } from 'date-fns'; |
|
|
|
import * as jsonpath from 'jsonpath'; |
|
|
|
|
|
|
|
@Injectable() |
|
|
|
export class ManualService implements DataProviderInterface { |
|
|
|
@ -286,9 +286,14 @@ export class ManualService implements DataProviderInterface { |
|
|
|
let value: string; |
|
|
|
|
|
|
|
if (response.headers.get('content-type')?.includes('application/json')) { |
|
|
|
const data = await response.json(); |
|
|
|
const object = await response.json(); |
|
|
|
|
|
|
|
value = String(jsonpath.query(data, scraperConfiguration.selector)[0]); |
|
|
|
value = String( |
|
|
|
query({ |
|
|
|
object, |
|
|
|
pathExpression: scraperConfiguration.selector |
|
|
|
})[0] |
|
|
|
); |
|
|
|
} else { |
|
|
|
const $ = cheerio.load(await response.text()); |
|
|
|
|
|
|
|
|
|
|
|
@ -124,6 +124,7 @@ |
|
|
|
"@types/big.js": "6.2.2", |
|
|
|
"@types/google-spreadsheet": "3.1.5", |
|
|
|
"@types/jest": "30.0.0", |
|
|
|
"@types/jsonpath": "0.2.4", |
|
|
|
"@types/lodash": "4.17.20", |
|
|
|
"@types/node": "22.15.17", |
|
|
|
"@types/papaparse": "5.3.7", |
|
|
|
@ -12436,6 +12437,13 @@ |
|
|
|
"dev": true, |
|
|
|
"license": "MIT" |
|
|
|
}, |
|
|
|
"node_modules/@types/jsonpath": { |
|
|
|
"version": "0.2.4", |
|
|
|
"resolved": "https://registry.npmjs.org/@types/jsonpath/-/jsonpath-0.2.4.tgz", |
|
|
|
"integrity": "sha512-K3hxB8Blw0qgW6ExKgMbXQv2UPZBoE2GqLpVY+yr7nMD2Pq86lsuIzyAaiQ7eMqFL5B6di6pxSkogLJEyEHoGA==", |
|
|
|
"dev": true, |
|
|
|
"license": "MIT" |
|
|
|
}, |
|
|
|
"node_modules/@types/jsonwebtoken": { |
|
|
|
"version": "9.0.10", |
|
|
|
"resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.10.tgz", |
|
|
|
|
|
|
|
@ -168,6 +168,7 @@ |
|
|
|
"@types/big.js": "6.2.2", |
|
|
|
"@types/google-spreadsheet": "3.1.5", |
|
|
|
"@types/jest": "30.0.0", |
|
|
|
"@types/jsonpath": "0.2.4", |
|
|
|
"@types/lodash": "4.17.20", |
|
|
|
"@types/node": "22.15.17", |
|
|
|
"@types/papaparse": "5.3.7", |
|
|
|
|