Skip to content

Commit

Permalink
feat: update resources to schema v5.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Jun 6, 2024
1 parent 3faf05a commit 83c628e
Show file tree
Hide file tree
Showing 11 changed files with 2,413 additions and 1,086 deletions.
1,319 changes: 1,077 additions & 242 deletions gen/openapi.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
"axios": "1.6.7"
},
"devDependencies": {
"@babel/preset-env": "^7.24.6",
"@babel/preset-typescript": "^7.24.6",
"@babel/preset-env": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@commercelayer/eslint-config-ts": "1.3.0",
"@commercelayer/js-auth": "^4.3.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@types/debug": "^4.1.12",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.4",
"@types/node": "^20.12.13",
"@types/node": "^20.14.2",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"inflector-js": "^1.0.1",
Expand Down
1,744 changes: 905 additions & 839 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

272 changes: 272 additions & 0 deletions specs/resources/links.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
/**
* ©2024 Commerce Layer Inc.
* Source code generated automatically by SDK codegen
**/

import { CommerceLayerClient, Link } from '../../src'
import { isEqual } from 'lodash'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { getClient, TestData, CommonData, handleError, interceptRequest, checkCommon, checkCommonData, checkCommonParamsList, checkCommonParams, currentAccessToken, randomValue } from '../../test/common'



let cl: CommerceLayerClient


beforeAll(async () => { cl = await getClient() })


describe('Links resource', () => {

const resourceType = 'links'


/* spec.create.start */
it(resourceType + '.create', async () => {

const createAttributes = {
name: randomValue('string', 'name'),
client_id: randomValue('string', 'client_id'),
scope: randomValue('string', 'scope'),
starts_at: randomValue('string', 'starts_at'),
expires_at: randomValue('string', 'expires_at'),
item: cl.orders.relationship(TestData.id),
}

const attributes = { ...createAttributes, reference: TestData.reference }
const params = { fields: { [resourceType]: CommonData.paramsFields } }
const resData = attributes

const intId = cl.addRequestInterceptor((config) => {
expect(config.method).toBe('post')
checkCommon(config, resourceType)
checkCommonData(config, resourceType, attributes)
expect(cl[resourceType].isLink(config.data.data)).toBeTruthy()
return interceptRequest()
})

await cl[resourceType].create(resData, params, CommonData.options)
.catch(handleError)
.finally(() => cl.removeInterceptor('request', intId))

})
/* spec.create.stop */


/* spec.retrieve.start */
it(resourceType + '.retrieve', async () => {

const id = TestData.id
const params = { fields: {[resourceType]: CommonData.paramsFields } }

const intId = cl.addRequestInterceptor((config) => {
expect(config.method).toBe('get')
checkCommon(config, resourceType, id, currentAccessToken)
checkCommonParams(config, params)
return interceptRequest()
})

await cl[resourceType].retrieve(id, params, CommonData.options)
.catch(handleError)
.finally(() => cl.removeInterceptor('request', intId))

})
/* spec.retrieve.stop */


/* spec.update.start */
it(resourceType + '.update', async () => {

const attributes = { reference_origin: TestData.reference_origin, metadata: TestData.metadata }
const params = { fields: { [resourceType]: CommonData.paramsFields } }
const resData = { id: TestData.id, ...attributes}

const intId = cl.addRequestInterceptor((config) => {
expect(config.method).toBe('patch')
checkCommon(config, resourceType, resData.id, currentAccessToken)
checkCommonData(config, resourceType, attributes, resData.id)
return interceptRequest()
})

await cl[resourceType].update(resData, params, CommonData.options)
.catch(handleError)
.finally(() => cl.removeInterceptor('request', intId))

})
/* spec.update.stop */


/* spec.delete.start */
it(resourceType + '.delete', async () => {

const id = TestData.id

const intId = cl.addRequestInterceptor((config) => {
expect(config.method).toBe('delete')
checkCommon(config, resourceType, id, currentAccessToken)
return interceptRequest()
})

await cl[resourceType].delete(id, CommonData.options)
.catch(handleError)
.finally(() => cl.removeInterceptor('request', intId))

})
/* spec.delete.stop */


/* spec.list.start */
it(resourceType + '.list', async () => {

const params = CommonData.paramsList

const intId = cl.addRequestInterceptor((config) => {
expect(config.method).toBe('get')
checkCommon(config, resourceType)
checkCommonParamsList(config, params)
return interceptRequest()
})

await cl[resourceType].list(params, CommonData.options)
.catch(handleError)
.finally(() => cl.removeInterceptor('request', intId))

})
/* spec.list.stop */


/* spec.type.start */
it(resourceType + '.type', async () => {

const resource = { id: TestData.id, type: resourceType }
expect(cl[resourceType].isLink(resource)).toBeTruthy()

const type = cl[resourceType].type()
expect(type).toBe(resourceType)

})
/* spec.type.stop */


/* spec.relationship.start */
it(resourceType + '.relationship', async () => {

const relId = cl[resourceType].relationship(TestData.id)
expect(isEqual(relId, { id: TestData.id, type: resourceType}))

const relResId = cl[resourceType].relationship({ id: TestData.id, type: resourceType })
expect(isEqual(relResId, { id: TestData.id, type: resourceType}))

})
/* spec.relationship.stop */


/* spec.parse.start */
it(resourceType + '.parse', async () => {

const reference = 'myReferenceId'

const payload = `
{
"data": {
"id": "AbcdEfgHiL",
"meta": {
"mode": "test",
"organization_id": "myOrgId"
},
"type": "${resourceType}",
"links": {
"self": "https://sdk-test-org.commercelayer.io/api/${resourceType}/AbcdEfgHiL"
},
"attributes": {
"metadata": {},
"reference": "${reference}",
"created_at": "2023-10-01T05:53:29.296Z",
"updated_at": "2023-10-10T08:52:13.251Z"
}
}
}
`

const res = cl[resourceType].parse(payload) as Link

expect(res.type).toBe(resourceType)
expect(res.reference).toBe(reference)

})
/* spec.parse.stop */



/* relationship.events start */
it(resourceType + '.events', async () => {

const id = TestData.id
const params = { fields: { events: CommonData.paramsFields } }

const intId = cl.addRequestInterceptor((config) => {
expect(config.method).toBe('get')
checkCommon(config, resourceType, id, currentAccessToken, 'events')
checkCommonParams(config, params)
return interceptRequest()
})

await cl[resourceType].events(id, params, CommonData.options)
.catch(handleError)
.finally(() => cl.removeInterceptor('request', intId))

})
/* relationship.events stop */



/* trigger._disable start */
it(resourceType + '._disable', async () => {

let triggerAttr = '_disable'
if (!triggerAttr.startsWith('_')) triggerAttr = `_${triggerAttr}`

const triggerValue = true
const attributes = { [triggerAttr]: triggerValue }
const id = TestData.id

const intId = cl.addRequestInterceptor((config) => {
expect(config.method).toBe('patch')
checkCommon(config, resourceType, id, currentAccessToken)
checkCommonData(config, resourceType, attributes, id)
return interceptRequest()
})

await cl[resourceType]._disable(id, {}, CommonData.options)
.catch(handleError)
.finally(() => cl.removeInterceptor('request', intId))

})
/* trigger._disable stop */


/* trigger._enable start */
it(resourceType + '._enable', async () => {

let triggerAttr = '_enable'
if (!triggerAttr.startsWith('_')) triggerAttr = `_${triggerAttr}`

const triggerValue = true
const attributes = { [triggerAttr]: triggerValue }
const id = TestData.id

const intId = cl.addRequestInterceptor((config) => {
expect(config.method).toBe('patch')
checkCommon(config, resourceType, id, currentAccessToken)
checkCommonData(config, resourceType, attributes, id)
return interceptRequest()
})

await cl[resourceType]._enable(id, {}, CommonData.options)
.catch(handleError)
.finally(() => cl.removeInterceptor('request', intId))

})
/* trigger._enable stop */

})
21 changes: 21 additions & 0 deletions specs/resources/stock_transfers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,27 @@ describe('StockTransfers resource', () => {
/* relationship.line_item stop */


/* relationship.attachments start */
it(resourceType + '.attachments', async () => {

const id = TestData.id
const params = { fields: { attachments: CommonData.paramsFields } }

const intId = cl.addRequestInterceptor((config) => {
expect(config.method).toBe('get')
checkCommon(config, resourceType, id, currentAccessToken, 'attachments')
checkCommonParams(config, params)
return interceptRequest()
})

await cl[resourceType].attachments(id, params, CommonData.options)
.catch(handleError)
.finally(() => cl.removeInterceptor('request', intId))

})
/* relationship.attachments stop */


/* relationship.events start */
it(resourceType + '.events', async () => {

Expand Down
6 changes: 6 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export { default as KlarnaGateways } from './resources/klarna_gateways'
export { default as KlarnaPayments } from './resources/klarna_payments'
export { default as LineItemOptions } from './resources/line_item_options'
export { default as LineItems } from './resources/line_items'
export { default as Links } from './resources/links'
export { default as ManualGateways } from './resources/manual_gateways'
export { default as ManualTaxCalculators } from './resources/manual_tax_calculators'
export { default as Markets } from './resources/markets'
Expand Down Expand Up @@ -190,6 +191,7 @@ export type ResourceTypeLock =
| 'klarna_payments'
| 'line_item_options'
| 'line_items'
| 'links'
| 'manual_gateways'
| 'manual_tax_calculators'
| 'markets'
Expand Down Expand Up @@ -317,6 +319,7 @@ export const resourceList = [
'klarna_payments',
'line_item_options',
'line_items',
'links',
'manual_gateways',
'manual_tax_calculators',
'markets',
Expand Down Expand Up @@ -483,6 +486,7 @@ export type CreatableResourceType =
| 'klarna_payments'
| 'line_item_options'
| 'line_items'
| 'links'
| 'manual_gateways'
| 'manual_tax_calculators'
| 'markets'
Expand Down Expand Up @@ -592,6 +596,7 @@ export type UpdatableResourceType =
| 'klarna_payments'
| 'line_item_options'
| 'line_items'
| 'links'
| 'manual_gateways'
| 'manual_tax_calculators'
| 'markets'
Expand Down Expand Up @@ -702,6 +707,7 @@ export type DeletableResourceType =
| 'klarna_payments'
| 'line_item_options'
| 'line_items'
| 'links'
| 'manual_gateways'
| 'manual_tax_calculators'
| 'markets'
Expand Down
4 changes: 3 additions & 1 deletion src/commercelayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const debug = Debug('commercelayer')


// Autogenerated schema version number, do not remove this line
const OPEN_API_SCHEMA_VERSION = '5.3.3'
const OPEN_API_SCHEMA_VERSION = '5.4.0'
export { OPEN_API_SCHEMA_VERSION }


Expand Down Expand Up @@ -91,6 +91,7 @@ class CommerceLayerClient {
klarna_payments: api.KlarnaPayments
line_item_options: api.LineItemOptions
line_items: api.LineItems
links: api.Links
manual_gateways: api.ManualGateways
manual_tax_calculators: api.ManualTaxCalculators
markets: api.Markets
Expand Down Expand Up @@ -226,6 +227,7 @@ class CommerceLayerClient {
this.klarna_payments = new api.KlarnaPayments(this.#adapter)
this.line_item_options = new api.LineItemOptions(this.#adapter)
this.line_items = new api.LineItems(this.#adapter)
this.links = new api.Links(this.#adapter)
this.manual_gateways = new api.ManualGateways(this.#adapter)
this.manual_tax_calculators = new api.ManualTaxCalculators(this.#adapter)
this.markets = new api.Markets(this.#adapter)
Expand Down
Loading

0 comments on commit 83c628e

Please sign in to comment.