@dpc-sdp/ripple-tide-api
Advanced tools
Comparing version 2.1.0-alpha.52 to 2.1.0-alpha.57
@@ -6,2 +6,26 @@ # Change Log | ||
# [2.1.0-alpha.57](https://github.com/dpc-sdp/ripple-framework/compare/v2.1.0-alpha.56...v2.1.0-alpha.57) (2023-01-09) | ||
**Note:** Version bump only for package @dpc-sdp/ripple-tide-api | ||
# [2.1.0-alpha.56](https://github.com/dpc-sdp/ripple-framework/compare/v2.1.0-alpha.55...v2.1.0-alpha.56) (2023-01-06) | ||
### Bug Fixes | ||
* fix package versions ([02536db](https://github.com/dpc-sdp/ripple-framework/commit/02536dbfba12aeb7e88f40ef6fc3efeac714d969)) | ||
### Features | ||
* **@dpc-sdp/ripple-tide-api:** :sparkles: give fallback default value of undefined ([d70e298](https://github.com/dpc-sdp/ripple-framework/commit/d70e2986ef5208d9bc7d6b91fcded6166f9a1e7d)) | ||
# [2.1.0-alpha.52](https://github.com/dpc-sdp/ripple-framework/compare/v2.1.0-alpha.51...v2.1.0-alpha.52) (2022-12-22) | ||
@@ -8,0 +32,0 @@ |
@@ -6,3 +6,3 @@ export * from './utils/mapping-utils.js'; | ||
export { default as logger } from './logger/logger.js'; | ||
export { default as createHandler } from './nuxt/handlers/createHandler.js'; | ||
export { default as createHandler } from './utils/createHandler.js'; | ||
export { tidePageBaseMapping, tidePageBaseIncludes } from './mapping/tide-page-base-mapping.js'; | ||
@@ -9,0 +9,0 @@ export * from './mapping/index.js'; |
@@ -7,3 +7,5 @@ import { map as topicTagsMapping, includes as topicTagsIncludes } from './topic-tags/topic-tags-mapping.js'; | ||
import { map as sidebarSiteSectionNavMapping, includes as sidebarSiteSectionNavIncludes } from './sidebar-site-section-nav/sidebar-site-section-nav-mapping.js'; | ||
export const tidePageBaseMapping = ({ withTopicTags = false, withSidebarContacts = false, withSidebarRelatedLinks = false, withSidebarWhatsNext = false, withSidebarSocialShare = false, withSidebarSiteSectionNav = false } = {}) => { | ||
export const tidePageBaseMapping = ({ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
withTopicTags = false, withSidebarContacts = false, withSidebarRelatedLinks = false, withSidebarWhatsNext = false, withSidebarSocialShare = false, withSidebarSiteSectionNav = false } = {}) => { | ||
const sidebar = {}; | ||
@@ -10,0 +12,0 @@ if (withSidebarContacts) { |
@@ -28,8 +28,6 @@ import { expect, describe, it } from '@jest/globals'; | ||
debug: false, | ||
contentApi: exampleApiConfig, | ||
config: exampleApiConfig, | ||
mapping: { | ||
site: exampleMapping, | ||
content: { | ||
event: exampleMapping | ||
} | ||
event: exampleMapping | ||
} | ||
@@ -71,9 +69,7 @@ }, mockLogger); | ||
const tideApiBase = new TideApiBase({ | ||
contentApi: exampleApiConfig, | ||
config: exampleApiConfig, | ||
debug: false, | ||
mapping: { | ||
site: exampleMapping, | ||
content: { | ||
event: exampleMapping | ||
} | ||
event: exampleMapping | ||
} | ||
@@ -80,0 +76,0 @@ }, mockLogger); |
export { default as TideApiBase } from './tide-api-base.js'; | ||
export { default as TidePage } from './tide-page.js'; | ||
export { default as TideSite } from './tide-site.js'; | ||
export { default as TidePageApi } from './tide-page.js'; | ||
export { default as TideSiteApi } from './tide-site.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -8,12 +8,12 @@ import HttpClient from './http-client.js'; | ||
debug; | ||
constructor(config, logger) { | ||
if (!config) { | ||
constructor(tide, logger) { | ||
if (!tide) { | ||
throw new Error('Error - No configuration specified'); | ||
} | ||
super({ | ||
client: config.client, | ||
baseUrl: `${config.contentApi.baseUrl}${config.contentApi.apiPrefix}`, | ||
auth: config.contentApi.auth | ||
client: tide.client, | ||
baseUrl: `${tide.config.baseUrl}${tide.config.apiPrefix}`, | ||
auth: tide.config.auth | ||
}, logger); | ||
this.debug = config.debug; | ||
this.debug = tide.debug; | ||
} | ||
@@ -20,0 +20,0 @@ async getMappedDataAux(mapping = {}, resource = {}) { |
@@ -5,3 +5,3 @@ import jsonapiParse from 'jsonapi-parse'; | ||
import { ApplicationError, NotFoundError } from '../errors/errors.js'; | ||
export default class TidePage extends TideApiBase { | ||
export default class TidePageApi extends TideApiBase { | ||
contentTypes; | ||
@@ -11,10 +11,16 @@ site; | ||
path; | ||
constructor(config, logger) { | ||
super(config, logger); | ||
this.site = config.contentApi.site; | ||
constructor(tide, logger) { | ||
super(tide, logger); | ||
this.site = tide.config.site; | ||
this.sectionId = ''; | ||
this.path = ''; | ||
this.contentTypes = config.mapping.content; | ||
this.contentTypes = {}; | ||
this.logLabel = 'TidePage'; | ||
} | ||
getContentTypes() { | ||
return this.contentTypes; | ||
} | ||
setContentType(key, value) { | ||
this.contentTypes[key] = value; | ||
} | ||
async getRouteByPath(path, site = this.site) { | ||
@@ -163,3 +169,3 @@ this.path = path; | ||
if (!contentTypeMapping) { | ||
throw new ApplicationError(`Unable to resolve content type - ${route.type}`); | ||
throw new ApplicationError(`Unable to resolve content type - ${route.bundle}`); | ||
} | ||
@@ -194,4 +200,3 @@ return this.getMappedData({ ...defaultMapping.mapping, ...contentTypeMapping }, resource); | ||
getContentTypeField(key, route) { | ||
let contentType = this.contentTypes?.[route.bundle] || | ||
this.contentTypes?.[route.entity_type]; | ||
let contentType = this.contentTypes[route.bundle] || this.contentTypes[route.entity_type]; | ||
// Check for "submodules", i.e. modules that are packaged together | ||
@@ -198,0 +203,0 @@ // for example embedded video and audio are packaged under "media" |
@@ -7,9 +7,9 @@ import jsonapiParse from 'jsonapi-parse'; | ||
siteMapping; | ||
constructor(config, logger) { | ||
super(config, logger); | ||
this.site = config.contentApi.site; | ||
if (typeof config?.mapping?.site === 'string') { | ||
constructor(tide, siteMapping, logger) { | ||
super(tide, logger); | ||
this.site = tide.config.site; | ||
if (!siteMapping) { | ||
throw new Error('Error loading site mapping'); | ||
} | ||
this.siteMapping = config?.mapping?.site; | ||
this.siteMapping = siteMapping; | ||
this.logLabel = 'TideSite'; | ||
@@ -16,0 +16,0 @@ } |
export const defineRplTideModule = async (config) => { | ||
const content = {}; | ||
for (const key in config.mapping?.content) { | ||
const contentTypePath = config.mapping?.content[`${key}`]; | ||
for (const key in config.mapping) { | ||
const contentTypePath = config.mapping[`${key}`]; | ||
if (typeof contentTypePath !== 'string') { | ||
@@ -13,7 +13,16 @@ throw new Error(`unable to load ${key} mapping`); | ||
} | ||
const site = await loadRplTideModule(config.mapping?.site); | ||
delete content.site; | ||
return { | ||
site: await loadRplTideModule(config.mapping?.site), | ||
site, | ||
content | ||
}; | ||
}; | ||
export const registerTideContentType = (event, contentType, contentTypeModule) => { | ||
if (event.node.req?.url?.includes('/api/tide/page')) { | ||
if (!event.context.tide?.pageApi?.contentTypes.hasOwnProperty(contentType)) { | ||
event.context.tide?.pageApi.setContentType(contentType, contentTypeModule); | ||
} | ||
} | ||
}; | ||
export const loadRplTideModule = async (path) => { | ||
@@ -20,0 +29,0 @@ return import(path).then((mdl) => mdl.default); |
@@ -139,6 +139,6 @@ import { get } from 'lodash-es'; | ||
}; | ||
export const getField = (field, path, fallback) => { | ||
export const getField = (field, path, fallback = undefined) => { | ||
return get(field, path, fallback); | ||
}; | ||
export const getBodyFromField = (field, path, fallback) => { | ||
export const getBodyFromField = (field, path, fallback = undefined) => { | ||
return getBody(getField(field, [path, 'processed'], fallback)); | ||
@@ -145,0 +145,0 @@ }; |
{ | ||
"name": "@dpc-sdp/ripple-tide-api", | ||
"version": "2.1.0-alpha.52", | ||
"version": "2.1.0-alpha.57", | ||
"description": "Ripple API endpoints for Tide Drupal backend", | ||
@@ -57,3 +57,3 @@ "main": "./dist/index.js", | ||
], | ||
"gitHead": "5d54142fb32a1fa54b67f2542bd1ceab4509259d" | ||
"gitHead": "168bd1a62709a037c2cfa8d9ef63b487a0cd5f9c" | ||
} |
@@ -6,3 +6,3 @@ export * from './utils/mapping-utils.js' | ||
export { default as logger } from './logger/logger.js' | ||
export { default as createHandler } from './nuxt/handlers/createHandler.js' | ||
export { default as createHandler } from './utils/createHandler.js' | ||
export { | ||
@@ -9,0 +9,0 @@ tidePageBaseMapping, |
@@ -27,2 +27,3 @@ import { | ||
export const tidePageBaseMapping = ({ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
withTopicTags = false, | ||
@@ -29,0 +30,0 @@ withSidebarContacts = false, |
@@ -32,8 +32,6 @@ import { expect, describe, it } from '@jest/globals' | ||
debug: false, | ||
contentApi: exampleApiConfig, | ||
config: exampleApiConfig, | ||
mapping: { | ||
site: exampleMapping, | ||
content: { | ||
event: exampleMapping | ||
} | ||
event: exampleMapping | ||
} | ||
@@ -79,9 +77,7 @@ }, | ||
{ | ||
contentApi: exampleApiConfig, | ||
config: exampleApiConfig, | ||
debug: false, | ||
mapping: { | ||
site: exampleMapping, | ||
content: { | ||
event: exampleMapping | ||
} | ||
event: exampleMapping | ||
} | ||
@@ -88,0 +84,0 @@ }, |
export { default as TideApiBase } from './tide-api-base.js' | ||
export { default as TidePage } from './tide-page.js' | ||
export { default as TideSite } from './tide-site.js' | ||
export { default as TidePageApi } from './tide-page.js' | ||
export { default as TideSiteApi } from './tide-site.js' |
@@ -11,4 +11,4 @@ import HttpClient from './http-client.js' | ||
debug: boolean | undefined | ||
constructor(config: RplTideModuleConfig, logger: ILogger) { | ||
if (!config) { | ||
constructor(tide: RplTideModuleConfig, logger: ILogger) { | ||
if (!tide) { | ||
throw new Error('Error - No configuration specified') | ||
@@ -18,9 +18,9 @@ } | ||
{ | ||
client: config.client, | ||
baseUrl: `${config.contentApi.baseUrl}${config.contentApi.apiPrefix}`, | ||
auth: config.contentApi.auth | ||
client: tide.client, | ||
baseUrl: `${tide.config.baseUrl}${tide.config.apiPrefix}`, | ||
auth: tide.config.auth | ||
}, | ||
logger | ||
) | ||
this.debug = config.debug | ||
this.debug = tide.debug | ||
} | ||
@@ -27,0 +27,0 @@ |
@@ -7,4 +7,4 @@ import jsonapiParse from 'jsonapi-parse' | ||
import { ILogger } from '../logger/logger' | ||
export default class TidePage extends TideApiBase { | ||
contentTypes: object | ||
export default class TidePageApi extends TideApiBase { | ||
contentTypes: any | ||
site: string | ||
@@ -14,11 +14,19 @@ sectionId: string | ||
constructor(config: RplTideModuleConfig, logger: ILogger) { | ||
super(config, logger) | ||
this.site = config.contentApi.site | ||
constructor(tide: RplTideModuleConfig, logger: ILogger) { | ||
super(tide, logger) | ||
this.site = tide.config.site | ||
this.sectionId = '' | ||
this.path = '' | ||
this.contentTypes = config.mapping.content | ||
this.contentTypes = {} | ||
this.logLabel = 'TidePage' | ||
} | ||
getContentTypes() { | ||
return this.contentTypes | ||
} | ||
setContentType(key, value) { | ||
this.contentTypes[key] = value | ||
} | ||
async getRouteByPath(path: string, site: string = this.site) { | ||
@@ -188,3 +196,3 @@ this.path = path | ||
throw new ApplicationError( | ||
`Unable to resolve content type - ${route.type}` | ||
`Unable to resolve content type - ${route.bundle}` | ||
) | ||
@@ -227,4 +235,3 @@ } | ||
let contentType = | ||
this.contentTypes?.[route.bundle] || | ||
this.contentTypes?.[route.entity_type] | ||
this.contentTypes[route.bundle] || this.contentTypes[route.entity_type] | ||
@@ -231,0 +238,0 @@ // Check for "submodules", i.e. modules that are packaged together |
@@ -11,9 +11,13 @@ import jsonapiParse from 'jsonapi-parse' | ||
constructor(config: RplTideModuleConfig, logger: ILogger) { | ||
super(config, logger) | ||
this.site = config.contentApi.site | ||
if (typeof config?.mapping?.site === 'string') { | ||
constructor( | ||
tide: RplTideModuleConfig, | ||
siteMapping: RplTideMapping, | ||
logger: ILogger | ||
) { | ||
super(tide, logger) | ||
this.site = tide.config.site | ||
if (!siteMapping) { | ||
throw new Error('Error loading site mapping') | ||
} | ||
this.siteMapping = config?.mapping?.site | ||
this.siteMapping = siteMapping | ||
this.logLabel = 'TideSite' | ||
@@ -20,0 +24,0 @@ } |
import type { RplTideModuleConfig, RplTideMapping } from './../../types' | ||
import { H3Event } from 'h3' | ||
export interface RplTideModuleMapping { | ||
@@ -16,4 +16,4 @@ site: RplTideMapping | ||
} | ||
for (const key in config.mapping?.content) { | ||
const contentTypePath = config.mapping?.content[`${key}`] | ||
for (const key in config.mapping) { | ||
const contentTypePath = config.mapping[`${key}`] | ||
if (typeof contentTypePath !== 'string') { | ||
@@ -28,4 +28,6 @@ throw new Error(`unable to load ${key} mapping`) | ||
} | ||
const site = await loadRplTideModule(config.mapping?.site) | ||
delete content.site | ||
return { | ||
site: await loadRplTideModule(config.mapping?.site), | ||
site, | ||
content | ||
@@ -35,2 +37,16 @@ } | ||
export const registerTideContentType = ( | ||
event: H3Event, | ||
contentType: string, | ||
contentTypeModule: RplTideMapping | ||
) => { | ||
if (event.node.req?.url?.includes('/api/tide/page')) { | ||
if ( | ||
!event.context.tide?.pageApi?.contentTypes.hasOwnProperty(contentType) | ||
) { | ||
event.context.tide?.pageApi.setContentType(contentType, contentTypeModule) | ||
} | ||
} | ||
} | ||
export const loadRplTideModule = async ( | ||
@@ -37,0 +53,0 @@ path: string |
@@ -210,7 +210,7 @@ import { get } from 'lodash-es' | ||
export const getField = (field, path, fallback) => { | ||
export const getField = (field, path, fallback = undefined) => { | ||
return get(field, path, fallback) | ||
} | ||
export const getBodyFromField = (field, path, fallback) => { | ||
export const getBodyFromField = (field, path, fallback = undefined) => { | ||
return getBody(getField(field, [path, 'processed'], fallback)) | ||
@@ -217,0 +217,0 @@ } |
@@ -134,3 +134,3 @@ import type { NuxtProxyOptions as ModuleOptions } from 'nuxt-proxy' | ||
export interface RplTideModuleConfig { | ||
contentApi: { | ||
config: { | ||
/** | ||
@@ -160,9 +160,3 @@ * Site taxonomy id or name | ||
*/ | ||
content: { | ||
[key: string]: string | RplTideMapping | ||
} | ||
/** | ||
* Site Mapping or path to file | ||
*/ | ||
site: string | RplTideMapping | ||
[key: string]: string | RplTideMapping | ||
} | ||
@@ -169,0 +163,0 @@ /** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
614877
4
163
11976