Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## [8.0.0-beta.7](https://github.com/commercelayer/commercelayer-sdk/compare/v8.0.0-beta.6...v8.0.0-beta.7) (2026-06-25)

### ⚠ BREAKING CHANGES

* remove /versions endpoints

### Features

* switch from OpenAPI schema to public resources and publish to pkg-pr-new ([fcc1b8a](https://github.com/commercelayer/commercelayer-sdk/commit/fcc1b8a37666f7c5f4b457f5d9a819cfa9f9f17b))
* update resources to schema v7.10.0 ([c8086f2](https://github.com/commercelayer/commercelayer-sdk/commit/c8086f22f486254d785ea8cac50c76dee6ead224))

### Documentation

* update import guide ([d20dae1](https://github.com/commercelayer/commercelayer-sdk/commit/d20dae1237db7c5456fce21616b5c91a76759985))

## [8.0.0-beta.6](https://github.com/commercelayer/commercelayer-sdk/compare/v8.0.0-beta.5...v8.0.0-beta.6) (2026-05-28)

### Features
Expand Down
82 changes: 35 additions & 47 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,51 +1,39 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"includes": [
"./src/**",
"./test/**",
"./specs/**",
"./gen/**",
"!gen/openapi.json",
"!gen/resources.json"
]
},
"formatter": {
"enabled": false,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 150
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noAssignInExpressions": "off",
"noExplicitAny": "off"
},
"style": {
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"includes": ["./src/**", "./test/**", "./specs/**", "./gen/**", "!gen/openapi.json", "!gen/resources.json"]
},
"formatter": {
"indentStyle": "space",
"lineWidth": 120
},
"linter": {
"rules": {
"suspicious": {
"noAssignInExpressions": "off",
"noExplicitAny": "off"
},
"style": {
"useTemplate": "off"
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"semicolons": "asNeeded"
}
},
"assist": {
"enabled": true,
"actions": {
"source": {
"organizeImports": "on"
}
}
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"semicolons": "asNeeded"
}
},
"assist": {
"actions": {
"source": {
"organizeImports": "on"
}
}
}
}
185 changes: 85 additions & 100 deletions gen/fixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,126 +6,111 @@ import Inflector from './inflector.js'
import resSchema from './resources.js'
import type { ApiSchema } from './schema'



const fixRedundantComponents = (schema: ApiSchema): ApiSchema => {

const fixResMatcher = /(ResponseList|ResponseCreated|ResponseUpdated|Response)$/

Object.values(schema.resources).forEach(res => {

// Remove redundant components and replace them with global resource component
Object.values(res.operations).forEach(op => {
if (op.responseType && (fixResMatcher.test(op.responseType))) {
const rt = op.responseType.replace(fixResMatcher, '')
if (res.components[op.responseType]) delete res.components[op.responseType]
if (!res.components[rt]) res.components[rt] = schema.components[rt]
op.responseType = rt
}
})

// Remove potential redundant operation components
Object.keys(res.components).forEach(key => {
if (fixResMatcher.test(key)) delete res.components[key]
})

// Sort components
res.components = sortObjectFields(res.components)

})

console.log('Redundant components have been replaced')

return schema

const fixResMatcher = /(ResponseList|ResponseCreated|ResponseUpdated|Response)$/

Object.values(schema.resources).forEach((res) => {
// Remove redundant components and replace them with global resource component
Object.values(res.operations).forEach((op) => {
if (op.responseType && fixResMatcher.test(op.responseType)) {
const rt = op.responseType.replace(fixResMatcher, '')
if (res.components[op.responseType]) delete res.components[op.responseType]
if (!res.components[rt]) res.components[rt] = schema.components[rt]
op.responseType = rt
}
})

// Remove potential redundant operation components
Object.keys(res.components).forEach((key) => {
if (fixResMatcher.test(key)) delete res.components[key]
})

// Sort components
res.components = sortObjectFields(res.components)
})

console.log('Redundant components have been replaced')

return schema
}


const enrichSchema = async (schema: ApiSchema): Promise<ApiSchema> => {

const resourcesInfo = CONFIG.LOCAL_SCHEMA? resSchema.load() : await resSchema.download()

if (!resourcesInfo) {
console.log('Error reading reasources data')
process.exit()
}

Object.entries(schema.components).forEach(([key, val]) => {
const resId = Inflector.snakeCase(key)
const resFields = resSchema.getResourceFields(resourcesInfo, resId)
if (resFields) Object.entries(val.attributes).forEach(([name, info]) => {
const field = resFields[name]
if (!field) console.log(`Warning, field not found in resources data: ${resId}.${name}`)
info.sortable = field?.sortable || false
info.filterable = field?.filterable || false
})
})


Object.values(schema.resources).forEach(r => {
Object.entries(r.components).forEach(([key, val]) => {
const resId = Inflector.snakeCase(key)
const resFields = resSchema.getResourceFields(resourcesInfo, resId)
if (resFields) Object.entries(val.attributes).forEach(([name, info]) => {
const field = resFields[name]
if (!field) console.log(`Warning, field not found in resources data: ${resId}.${name}`)
info.sortable = field?.sortable || false
info.filterable = field?.filterable || false
})
})
})


console.log('Api schema has been enriched with resources data')

return schema

const resourcesInfo = CONFIG.LOCAL_SCHEMA ? resSchema.load() : await resSchema.download()

if (!resourcesInfo) {
console.log('Error reading reasources data')
process.exit()
}

Object.entries(schema.components).forEach(([key, val]) => {
const resId = Inflector.snakeCase(key)
const resFields = resSchema.getResourceFields(resourcesInfo, resId)
if (resFields)
Object.entries(val.attributes).forEach(([name, info]) => {
const field = resFields[name]
if (!field) console.log(`Warning, field not found in resources data: ${resId}.${name}`)
info.sortable = field?.sortable || false
info.filterable = field?.filterable || false
})
})

Object.values(schema.resources).forEach((r) => {
Object.entries(r.components).forEach(([key, val]) => {
const resId = Inflector.snakeCase(key)
const resFields = resSchema.getResourceFields(resourcesInfo, resId)
if (resFields)
Object.entries(val.attributes).forEach(([name, info]) => {
const field = resFields[name]
if (!field) console.log(`Warning, field not found in resources data: ${resId}.${name}`)
info.sortable = field?.sortable || false
info.filterable = field?.filterable || false
})
})
})

console.log('Api schema has been enriched with resources data')

return schema
}


const fixResourcesType = (schema: ApiSchema): ApiSchema => {
const resources = {}

const resources = {}

for (const key in schema.resources) {
const type = Inflector.pluralize(key)
if (type === key) resources[key] = schema.resources[key]
else resources[type] = schema.resources[key]
}
for (const key in schema.resources) {
const type = Inflector.pluralize(key)
if (type === key) resources[key] = schema.resources[key]
else resources[type] = schema.resources[key]
}

schema.resources = resources

return schema
schema.resources = resources

return schema
}


export const fixSchema = async (schema: ApiSchema): Promise<ApiSchema> => {
console.log('Fixing parsed schema...')

console.log('Fixing parsed schema...')

let fixedSchema = schema
fixedSchema = fixRedundantComponents(fixedSchema)
fixedSchema = await enrichSchema(fixedSchema)
fixedSchema = fixResourcesType(fixedSchema)

console.log('Schema fixed.')
let fixedSchema = schema
fixedSchema = fixRedundantComponents(fixedSchema)
fixedSchema = await enrichSchema(fixedSchema)
fixedSchema = fixResourcesType(fixedSchema)

return fixedSchema
console.log('Schema fixed.')

return fixedSchema
}


export const fixReservedWord = (word: string): string => {
switch (word) {
case 'exports': return 'exportz'
case 'export': return 'eXport'
default: return word
}
switch (word) {
case 'exports':
return 'exportz'
case 'export':
return 'eXport'
default:
return word
}
}



export default {
fixSchema
fixSchema,
}
Loading
Loading