Skip to content

Commit

Permalink
feat: add support for jcont filter as object
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Jan 19, 2024
1 parent 56a7f99 commit f1f83d6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: Publish
on:
release:
types: [ published ]
Expand Down
4 changes: 0 additions & 4 deletions gen/schema.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable no-console */
import { readFileSync, writeFileSync } from 'fs'
import { snakeCase } from 'lodash'
import axios from 'axios'
import { resolve } from 'path'
import { sortObjectFields } from '../src/util'
import { inspect } from 'util'


// eslint-disable-next-line @typescript-eslint/no-var-requires
const Inflector = require('inflector-js')


Expand Down
4 changes: 2 additions & 2 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Debug from './debug'
const debug = Debug('query')


type QueryFilter = Record<string, string | number | boolean>
type QueryFilter = Record<string, string | number | boolean | object>


interface QueryParamsRetrieve {
Expand Down Expand Up @@ -61,7 +61,7 @@ const generateQueryStringParams = (params: QueryParamsRetrieve | QueryParamsList
// Filters
if (params.filters) {
Object.entries(params.filters).forEach(([p, v]) => {
qp[`filter[q][${p}]`] = String(v)
qp[`filter[q][${p}]`] = (typeof v === 'object')? JSON.stringify(v) : String(v)
})
}
}
Expand Down
33 changes: 18 additions & 15 deletions test/spot.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@

import commercelayer, { CommerceLayerStatic, SdkError } from '../src/index'
import { inspect } from 'util'
import commercelayer from '../src/index'
import getToken from './token'


(async () => {

enum ErrorType {
CLIENT = 'client', // Error instantiating the client
REQUEST = 'request', // Error preparing API request
RESPONSE = 'response', // Error response from API
CANCEL = 'cancel', // Forced request abort using interceptor
PARSE = 'parse', // Error parsing API resource
GENERIC = 'generic', // Other not specified errors
}
const auth = await getToken('integration')
const accessToken = auth ? auth.accessToken : ''
const organization = process.env.CL_SDK_ORGANIZATION || 'sdk-test-org'

const values = Object.values(ErrorType)
const cl = commercelayer({
organization,
accessToken
})

const err = {
name: 'SdkError',
type: 'cancel'
}
try {

console.log(CommerceLayerStatic.isSdkError(err))
const customers = await cl.customers.list({ filters: { email_eq: 'userx2@server.com' }})
console.log(inspect(customers, false, null, true))

} catch (error: any) {
console.log(inspect(error, false, null, true))
console.log(error.message)
}

})()

0 comments on commit f1f83d6

Please sign in to comment.