Skip to content

v2.0.0

Compare
Choose a tag to compare
@gustavoguichard gustavoguichard released this 08 Aug 18:19
· 41 commits to main since this release
e11f6a6

What's Changed

BREAKING Changes:

Dropped string transformations

String transformations such as kebabToCamel and etc were removed from this library. We recommend replacing it by string-ts which is much more powerful and fully featured.

// BEFORE v2
import { makeService, kebabToCamel } from 'make-service'

const service = makeService("https://example.com/api")
const response = await service.get("/users")
const users = await response.json(
  z
    .array(z.object({ "first-name": z.string(), contact: z.object({ "home-address": z.string() }) }))
    .transform(kebabToCamel)
)

// AFTER v2
import { makeService } from 'make-service'
import { deepCamelKeys } from 'string-ts'

const service = makeService("https://example.com/api")
const response = await service.get("/users")
const users = await response.json(
  z
    .array(z.object({ "first-name": z.string(), contact: z.object({ "home-address": z.string() }) }))
    .transform(deepCamelKeys)
)

With string-ts you don't need to specify the input casing of the string, you only need to specify the target casing. 🔥

Changes to the second argument of makeService

Now the second argument to makeService and makeFetcher functions is baseOptions which is an object with headers, requestTransformer, and responseTransformer. You can use the new transformers to pre-process your Request before sending it or post-process your Response just after fetching.
This allows further customization of this library such as creating adapters for APIs that will transform the payloads back and forth.
Turning the second parameter into an object will also allow future new APIs to come to this library.

How to migrate:

You just need to send your former baseHeaders in the baseOptions.headers now as so:

// Versions < 2.0.0
const service = makeService('https://google.com', new Headers({ authorization: "Bearer 123" }))

// From versions >= 2.0.0
const service = makeService('https://google.com', {
  headers: new Headers({ authorization: "Bearer 123" }),
})

Acknowledgements

I appreciate all the effort by @danielweinmann, @diogob , and the team at SeasonedSoftware that made it to this release.

Full Changelog: v1.1.0...v2.0.0