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 e169ed1 commit 1cb423c
Show file tree
Hide file tree
Showing 9 changed files with 1,402 additions and 244 deletions.
1,319 changes: 1,077 additions & 242 deletions gen/openapi.json

Large diffs are not rendered by default.

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

import { CommerceLayerClient } 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: { links: 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: { links: 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: { links: 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 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}))

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

})
/* spec.type.stop */



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))

})

})
19 changes: 19 additions & 0 deletions specs/resources/stock_transfers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,25 @@ describe('StockTransfers resource', () => {
})


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))

})


it(resourceType + '.events', async () => {

const id = TestData.id
Expand Down
3 changes: 3 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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 @@ -187,6 +188,7 @@ export type ResourceTypeLock =
| 'klarna_payments'
| 'line_item_options'
| 'line_items'
| 'links'
| 'manual_gateways'
| 'manual_tax_calculators'
| 'markets'
Expand Down Expand Up @@ -314,6 +316,7 @@ export const resourceList = [
'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 @@ -9,7 +9,7 @@ import Debug from './debug'
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 @@ -86,6 +86,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 @@ -220,6 +221,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
1 change: 1 addition & 0 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export type { KlarnaGateway, KlarnaGatewayCreate, KlarnaGatewayUpdate } from './
export type { KlarnaPayment, KlarnaPaymentCreate, KlarnaPaymentUpdate } from './resources/klarna_payments'
export type { LineItemOption, LineItemOptionCreate, LineItemOptionUpdate } from './resources/line_item_options'
export type { LineItem, LineItemCreate, LineItemUpdate } from './resources/line_items'
export type { Link, LinkCreate, LinkUpdate } from './resources/links'
export type { ManualGateway, ManualGatewayCreate, ManualGatewayUpdate } from './resources/manual_gateways'
export type { ManualTaxCalculator, ManualTaxCalculatorCreate, ManualTaxCalculatorUpdate } from './resources/manual_tax_calculators'
export type { Market, MarketCreate, MarketUpdate } from './resources/markets'
Expand Down
116 changes: 116 additions & 0 deletions src/resources/links.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { ApiResource, Resource, ResourceCreate, ResourceUpdate, ResourcesConfig, ResourceId, ResourceRel, ListResponse } from '../resource'
import type { QueryParamsList, QueryParamsRetrieve } from '../query'

import type { Order } from './orders'
import type { SkuList } from './sku_lists'
import type { Event } from './events'


type LinkRel = ResourceRel & { type: typeof Links.TYPE }
type OrderRel = ResourceRel & { type: 'orders' }
type SkuListRel = ResourceRel & { type: 'sku_lists' }


interface Link extends Resource {

name?: string
client_id?: string
scope?: string
starts_at?: string
expires_at?: string
active?: boolean
status?: string
domain?: string
url?: string
disabled_at?: string

item?: Order | SkuList
events?: Event[]

}


interface LinkCreate extends ResourceCreate {

name: string
client_id: string
scope: string
starts_at: string
expires_at: string
domain?: string
_disable?: boolean
_enable?: boolean

item: OrderRel | SkuListRel

}


interface LinkUpdate extends ResourceUpdate {

name?: string
client_id?: string
scope?: string
starts_at?: string
expires_at?: string
domain?: string
_disable?: boolean
_enable?: boolean

item?: OrderRel | SkuListRel

}


class Links extends ApiResource {

static readonly TYPE: 'links' = 'links' as const
// static readonly PATH = 'links'

async list(params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Link>> {
return this.resources.list<Link>({ type: Links.TYPE }, params, options)
}

async create(resource: LinkCreate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Link> {
return this.resources.create<LinkCreate, Link>({ ...resource, type: Links.TYPE }, params, options)
}

async retrieve(id: string, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Link> {
return this.resources.retrieve<Link>({ type: Links.TYPE, id }, params, options)
}

async update(resource: LinkUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Link> {
return this.resources.update<LinkUpdate, Link>({ ...resource, type: Links.TYPE }, params, options)
}

async delete(id: string, options?: ResourcesConfig): Promise<void> {
await this.resources.delete({ type: Links.TYPE, id }, options)
}

async events(linkId: string | Link, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Event>> {
const _linkId = (linkId as Link).id || linkId as string
return this.resources.fetch<Event>({ type: 'events' }, `links/${_linkId}/events`, params, options) as unknown as ListResponse<Event>
}


// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
isLink(resource: any): resource is Link {
return resource.type && (resource.type === Links.TYPE)
}


relationship(id: string | ResourceId | null): LinkRel {
return ((id === null) || (typeof id === 'string')) ? { id, type: Links.TYPE } : { id: id.id, type: Links.TYPE }
}


type(): string {
return Links.TYPE
}

}


export default Links

export { Link, LinkCreate, LinkUpdate }
1 change: 0 additions & 1 deletion src/resources/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ interface Order extends Resource {
fulfillment_updated_at?: string
refreshed_at?: string
archived_at?: string
expires_at?: string
subscription_created_at?: string
circuit_state?: string
circuit_failure_count?: number
Expand Down
Loading

0 comments on commit 1cb423c

Please sign in to comment.