diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a8417245..0d914b98 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: Release +name: Publish on: release: types: [ published ] diff --git a/gen/schema.ts b/gen/schema.ts index 44845294..cec95326 100644 --- a/gen/schema.ts +++ b/gen/schema.ts @@ -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') diff --git a/src/query.ts b/src/query.ts index 483ee36a..9259f361 100644 --- a/src/query.ts +++ b/src/query.ts @@ -5,7 +5,7 @@ import Debug from './debug' const debug = Debug('query') -type QueryFilter = Record +type QueryFilter = Record interface QueryParamsRetrieve { @@ -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) }) } } diff --git a/test/spot.ts b/test/spot.ts index ed8343fa..1796bcf3 100644 --- a/test/spot.ts +++ b/test/spot.ts @@ -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) + } })()