Releases: gustavoguichard/make-service
v3.1.0
What's Changed
Main change: the trace function now gets a third parameter which is a clone of the TypedResponse
so you can debug not only the requests but also the response ;)
PRs:
- docs: add iamandrewluca as a contributor for code, promotion, and 3 more by @allcontributors in #49
- fix(makeFetcher): include requestTransformer headers by @iamandrewluca in #48
- Add third parameter with response to trace and allow it to be asynchronous by @diogob in #53
- Updating packages, vite, and lint config by @gustavoguichard in #54
New Contributors
Full Changelog: v3.0.0...v3.1.0
v3.0.0 - small changes in a major version
Why is it a major change?
This version are introducing little changes but it has 1 breaking change.
In the past we adopted a convention to add "content-type": "application/json"
headers as default to makeService, but as lots of early conventions it has proven to be a bad decision as depending on the format of the body
the content-type needs to be different and we are now using make-service
to deal with every type of request instead of just JSON APIs.
We are dropping that default so you might want to add that if you rely on that behavior.
If that's your case, you'll need to change your code like so:
# From
const service = makeService(BASE_URL)
# To
const service = makeService(BASE_URL, { headers: { "content-type": "application/json" } })
An important bugfix:
We had our first solid contribution from @iamandrewluca . To change the behavior of the response so it gets typed on the fly we are using JS Proxys. It works like a charm but for the methods we are not hijacking (.json()
and .text()
) we are now using Reflect
so we don't mess with the Response's prototype.
This bugfix should fix an issue where response.blob()
or response.arrayBuffer()
would never resolve.
This is a "small major" release, let us know if you had any trouble upgrading. We appreciate any sort of collaboration ;)
What's Changed
- docs: add iamandrewluca as a contributor for doc by @allcontributors in #43
- fix(typedResponse): bind remaining Proxy methods to Response by @iamandrewluca in #47
- BREAKING CHANGE: Drop the behavior of adding a default
content-type: application/json
by @gustavoguichard in #45
Full Changelog: v2.1.2...v3.0.0
v2.1.2
What's Changed
- Fix repository GitHub username by @iamandrewluca in #42
New Contributors
- @iamandrewluca made their first contribution in #42
Full Changelog: v2.1.1...v2.1.2
v2.1.1
What's Changed
- chore: Add contributors and other shields to README by @gustavoguichard in #37
- fix: add more strict function definitions too
addQueryToURL
by @garusis in #35
New Contributors
Full Changelog: v2.1.0...v2.1.1
v2.1.0
🆕 What's Changed
- fix: Add 'Date', 'undefined', and 'null' as possible JSON values to improve DX by @gustavoguichard in #34
🐞 Bug fixes
- Fixes a bug where addQueryToURL would not work with URLs with empty searchParams by @gustavoguichard in #32
Other PRs
- Add CI to this repo by @gustavoguichard in #30
- Expose
typeOf
function by @gustavoguichard in #33
Full Changelog: v2.0.0...v2.1.0
v2.0.0
What's Changed
- Add transformers to
makeService
andmakeFetcher
by @danielweinmann in #21 - Document baseOptions and add disclaimer by @danielweinmann in #26
- Expose getJson and getText as typedResponse options by @danielweinmann in #25
- Drop string transformations from this library, use
string-ts
instead by @gustavoguichard in #27
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
v2.0.0-next.0
What's Changed
- Add transformers to
makeService
andmakeFetcher
by @danielweinmann in #21 - Document baseOptions and add disclaimer by @danielweinmann in #26
- Expose getJson and getText as typedResponse options by @danielweinmann in #25
BREAKING Changes:
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-next.0
v1.1.0
What's Changed
- Strongly-typed params by @gustavoguichard in #18
- Payload transforms by @gustavoguichard in #17
- Make transforms apply deeply into objects within arrays by @gustavoguichard in #19
Full Changelog: v1.0.0...v1.1.0
v1.0.0
What's Changed
- BREAKING CHANGE: Remove deprecated addQueryToInput method. It was rep… by @gustavoguichard in #9
- Stop throwing depending on status by @gustavoguichard in #8
- Accept a function for baseHeaders by @danielweinmann in #6
- Accept more
BodyInit
types such as FormData, URLSearchParams, Blob, ArrayBuffer, ReadableStream, etc by @gustavoguichard in #10 - Update HTTP methods and improve type of method in RequestInit by @gustavoguichard in #11
- BREAKING CHANGE: Rename some methods for a standard where URL is always in caps by @gustavoguichard in #12
- Add makeFetcher as a primitive of makeService by @gustavoguichard in #13
- feat: Expose replaceURLParams as a public API by @gustavoguichard in #14
- Reorganize and expose primitives by @gustavoguichard in #15
Updated README
You can see all the new features an APIs in the updated and reorganized README.
New Contributors
- @danielweinmann made their first contribution in #6
Full Changelog: v0.2.0...v1.0.0
v1.0.0-next.2
What's Changed
- Update HTTP methods and improve type of method in RequestInit by @gustavoguichard in #11
- BREAKING CHANGE: Rename some methods for a standard where URL is always in caps by @gustavoguichard in #12
- Add makeFetcher as a primitive of makeService by @gustavoguichard in #13
- feat: Expose replaceURLParams as a public API by @gustavoguichard in #14
- Reorganize and expose primitives by @gustavoguichard in #15
Full Changelog: v1.0.0-next.0...v1.0.0-next.2