Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: drop contentId mapping from dts plugin #584

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ingest-pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/checkout@v4

- name: 🏗 Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
uses: actions/checkout@v4

- name: ⛺️ Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ingest-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: actions/checkout@v4

- name: 🏗 Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ lib-cov

# Yarn Integrity file
.yarn-integrity

# IntelliJ Idea
.idea/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ 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).

## [1.7.0] - 2023-10-27

- refactor: drop `contentId` mapping from `dts` plugin

## [1.6.0] - 2023-09-22

- feat: prepare feature flat to toggle `dts` plugin to be opt-out
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ This source code is provided under EUPL v1.2, except for the [`spdx-exceptions`]
| NPM | `@swrlab/utils` | [MIT](https://github.com/swrlab/node-utils/blob/main/LICENSE.md) |
| NPM | `compression` | [MIT](https://github.com/expressjs/compression/blob/master/LICENSE) |
| NPM | `dd-trace` | [Apache-2.0 OR BSD-3-Clause](https://github.com/DataDog/dd-trace-js/blob/master/LICENSE) |
| NPM | `dotenv` | [BSD-2-Clause](https://github.com/motdotla/dotenv/blob/master/LICENSE) |
| NPM | `express` | [MIT](https://github.com/expressjs/express/blob/master/LICENSE) |
| NPM | `express-openapi-validator` | [MIT](https://github.com/cdimascio/express-openapi-validator/blob/master/LICENSE) |
| NPM | `firebase-admin` | [Apache License 2.0](https://github.com/firebase/firebase-admin-node/blob/master/LICENSE) |
Expand All @@ -85,13 +84,13 @@ This source code is provided under EUPL v1.2, except for the [`spdx-exceptions`]
| NPM | `luxon` | [MIT](https://github.com/moment/luxon/blob/master/LICENSE.md) |
| NPM | `slug` | [MIT](https://github.com/Trott/slug/blob/master/LICENSE) |
| NPM | `swagger-ui-express` | [MIT](https://github.com/scottie1984/swagger-ui-express/blob/master/LICENSE) |
| NPM | `uuid` | [MIT](https://github.com/uuidjs/uuid/blob/master/LICENSE.md) |
| NPM | `winston` | [MIT](https://github.com/winstonjs/winston/blob/master/LICENSE) |
| NPM DEV | `@swrlab/eslint-plugin-swr` | [ISC](https://github.com/swrlab/eslint-plugin-swr/blob/main/package.json) |
| NPM DEV | `@swrlab/swr-prettier-config` | [MIT](https://github.com/swrlab/swr-prettier-config/blob/main/LICENSE.txt) |
| NPM DEV | `chai` | [MIT](https://github.com/chaijs/chai/blob/master/LICENSE) |
| NPM DEV | `chai-http` | [MIT](https://github.com/chaijs/chai-http/blob/master/package.json) |
| NPM DEV | `docsify-cli` | [MIT](https://github.com/docsifyjs/docsify-cli/blob/master/LICENSE) |
| NPM DEV | `dotenv` | [BSD-2-Clause](https://github.com/motdotla/dotenv/blob/master/LICENSE) |
| NPM DEV | `eslint` | [MIT](https://github.com/eslint/eslint/blob/master/LICENSE) |
| NPM DEV | `eslint-plugin-chai-friendly` | [MIT](https://github.com/ihordiachenko/eslint-plugin-chai-friendly/blob/master/LICENSE) |
| NPM DEV | `license-compliance` | [MIT](https://github.com/tmorell/license-compliance/blob/master/LICENSE) |
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ard-eventhub",
"version": "1.6.0",
"version": "1.7.0",
"description": "ARD system to distribute real-time (live) metadata for primarily radio broadcasts.",
"main": "./src/ingest/index.js",
"engines": {
Expand All @@ -10,7 +10,7 @@
"docs:serve": "docsify serve . --port 3000",
"coreId": "node ./src/coreId/index.js",
"ingest:local": "nodemon -r dotenv/config ./src/ingest/index.js",
"ingest:cloud": "node -r dotenv/config ./src/ingest/index.js",
"ingest:cloud": "node ./src/ingest/index.js",
"ingest:test": "mocha test/ingest.test.js --timeout 15000 --exit -r dotenv/config",
"ingest:lint": "eslint src",
"docker:build": "docker build . -t swr/ard-eventhub",
Expand All @@ -29,42 +29,42 @@
"author": "SWR Audio Lab <[email protected]>",
"license": "EUPL-1.2",
"dependencies": {
"@google-cloud/datastore": "8.1.0",
"@google-cloud/pubsub": "4.0.6",
"@google-cloud/datastore": "8.2.2",
"@google-cloud/pubsub": "4.0.7",
"@google-cloud/secret-manager": "5.0.1",
"@swrlab/utils": "1.1.3",
"compression": "1.7.4",
"dd-trace": "4.15.0",
"dotenv": "16.3.1",
"dd-trace": "4.19.0",
"express": "4.18.2",
"express-openapi-validator": "5.0.6",
"firebase-admin": "11.10.1",
"google-auth-library": "9.0.0",
"express-openapi-validator": "5.1.0",
"firebase-admin": "11.11.0",
"google-auth-library": "9.2.0",
"jsonwebtoken": "9.0.2",
"luxon": "3.4.3",
"luxon": "3.4.4",
"slug": "8.2.3",
"swagger-ui-express": "5.0.0",
"uuid": "9.0.1",
"winston": "3.10.0"
"winston": "3.11.0"
},
"devDependencies": {
"@swrlab/eslint-plugin-swr": "^0.3.0",
"@swrlab/swr-prettier-config": "^0.3.0",
"chai": "^4.3.8",
"chai": "^4.3.10",
"chai-http": "^4.4.0",
"docsify-cli": "^4.4.4",
"eslint": "^8.50.0",
"dotenv": "16.3.1",
"eslint": "^8.54.0",
"eslint-plugin-chai-friendly": "^0.7.2",
"license-compliance": "^2.0.0",
"license-compliance": "^2.0.1",
"mocha": "^10.2.0",
"nodemon": "^3.0.1",
"prettier": "^3.0.3",
"prettier": "^3.1.0",
"typescript": "^5.2.2"
},
"resolutions": {
"ansi-regex": "^5.0.1",
"got": "^11.8.6",
"strip-ansi": "^6.0.1"
"strip-ansi": "^6.0.1",
"update-notifier": "^5.1.0"
},
"prettier": "@swrlab/swr-prettier-config"
}
4 changes: 2 additions & 2 deletions src/ingest/subscriptions/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// load node utils
const { DateTime } = require('luxon')
const { v4: uuidv4 } = require('uuid')
const { randomUUID } = require('crypto')

// load eventhub utils
const datastore = require('../../utils/datastore')
Expand Down Expand Up @@ -60,7 +60,7 @@ module.exports = async (req, res) => {

// map inputs
let subscription = {
name: `${prefix}${uuidv4()}`,
name: `${prefix}${randomUUID()}`,
type: req.body.type,
method: req.body.method,
url: req.body.url,
Expand Down
49 changes: 5 additions & 44 deletions src/utils/plugins/dts/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const logger = require('../../logger')
const undici = require('../../undici')

// load keys
const { credentials, endpoints, integrationName, permittedExcludedFields } = require('../../../../config/dtsKeys')
const { credentials, endpoints, permittedExcludedFields } = require('../../../../config/dtsKeys')

// load config
const config = require('../../../../config')
Expand All @@ -22,18 +22,9 @@ const source = 'utils/plugins/dts/event'

const DEFAULT_HEADERS = { Accept: 'application/json', 'Content-Type': 'application/json' }
const LIVERADIO_URL = endpoints.liveRadioEvent[config.stage]
const RECORDS_INTEGRATION_URL = endpoints.listIntegrationRecords.replace('{integrationName}', integrationName)
const DASHBOARD_REQUEST_CONFIG = {
timeout: 7e3,
reject: false,
headers: { ...DEFAULT_HEADERS, Authorization: credentials.dashboardToken },
}

// provide remapping helpers
const getCoreIds = (services) => services.map((service) => service.topic.id)
const filterIntegrations = (li, coreIds) =>
li.filter((i) => i.external_system === integrationName && coreIds.includes(i.external_id))
const getContentIds = (li) => li.map((integration) => integration.content_id)

const getUserForInstitution = (institutionId) => {
// get user or reject if not found
Expand Down Expand Up @@ -66,35 +57,6 @@ module.exports = async (job) => {
// collect ARD Core ids
const coreIds = getCoreIds(event.services)

// fetch all externally mapped ids
const integrationsList = await undici(RECORDS_INTEGRATION_URL, DASHBOARD_REQUEST_CONFIG)

// end processing if no integrations were found
if (!integrationsList.ok || !notEmptyArray(integrationsList.json)) {
logger.log({
level: 'error',
message: `failed loading DTS integrations`,
source,
data: { job, ids: { coreIds }, string: integrationsList.string, json: integrationsList.json },
})
return Promise.resolve()
}

// filter integrations matching these ARD Core ids
const matchingIntegrations = filterIntegrations(integrationsList.json, coreIds)
const contentIds = getContentIds(matchingIntegrations)

// catch non-existent mappings
if (!notEmptyArray(contentIds)) {
logger.log({
level: 'notice',
message: `DTS contentIds mapping missing for coreIds`,
source,
data: { job, ids: { coreIds } },
})
return Promise.resolve()
}

// remap playing type
let type = 'other'
if (event.type === 'music') type = event.type
Expand Down Expand Up @@ -162,9 +124,9 @@ module.exports = async (job) => {
return Promise.resolve()
}

// insert contentIds into events
const liveRadioEvents = contentIds.map((contentId) => {
return { ...liveRadioEvent, contentId }
// insert coreId into events
const liveRadioEvents = coreIds.map((coreId) => {
return { ...liveRadioEvent, publisherSourceId: coreId }
})

// post event
Expand All @@ -187,7 +149,6 @@ module.exports = async (job) => {
const message = [
`DTS event done (${event.services[0]?.publisherId})`,
`status ${posted.statusCode}`,
`${contentIds?.length}x contentIds ${JSON.stringify(contentIds)}`,
`${coreIds.length}x Core IDs`,
]
logger.log({
Expand All @@ -196,7 +157,7 @@ module.exports = async (job) => {
source,
data: {
input: job,
ids: { coreIds, contentIds },
coreIds,
dts: {
username,
statusCode: posted.statusCode,
Expand Down
Loading