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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 67 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"axios": "^1.0.0",
"axios-case-converter": "^1.0.0",
"axios-retry": "^3.1.9",
"camelcase": "6.3.0",
"emoji-regex": "10.4.0",
"ts-custom-error": "^3.2.0",
"uuid": "^9.0.0",
"zod": "^3.24.1"
Expand Down
7 changes: 6 additions & 1 deletion src/restClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { HttpMethod } from './types/http'
import { v4 as uuidv4 } from 'uuid'
import axiosRetry from 'axios-retry'
import { API_BASE_URI } from './consts/endpoints'
import { customCamelCase } from './utils/processing-helpers'

export function paramsSerializer(params: Record<string, unknown>) {
const qs = new URLSearchParams()
Expand Down Expand Up @@ -70,7 +71,11 @@ function getRequestConfiguration(baseURL: string, apiToken?: string, requestId?:

function getAxiosClient(baseURL: string, apiToken?: string, requestId?: string) {
const configuration = getRequestConfiguration(baseURL, apiToken, requestId)
const client = applyCaseMiddleware(Axios.create(configuration))
const client = applyCaseMiddleware(Axios.create(configuration), {
caseFunctions: {
camel: customCamelCase,
},
})

axiosRetry(client, {
retries: 3,
Expand Down
19 changes: 19 additions & 0 deletions src/utils/processing-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { customCamelCase } from './processing-helpers'

describe('Processing helpers', () => {
describe('customCamelCase', () => {
test('returns the converted input if it is not an emoji', () => {
const input = 'hello_there'
const result = customCamelCase(input)

expect(result).toBe('helloThere')
})

test('returns the input if it is an emoji', () => {
const input = '👍'
const result = customCamelCase(input)

expect(result).toBe(input)
})
})
})
13 changes: 13 additions & 0 deletions src/utils/processing-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import camelcase from 'camelcase'
import emojiRegex from 'emoji-regex'

function isEmojiKey(key: string) {
const regex = emojiRegex()
return regex.test(key)
}

export function customCamelCase(input: string) {
// If the value is a solitary emoji string, return the key as-is
if (isEmojiKey(input)) return input
return camelcase(input)
}