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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: npm run build
- name: check type
run: npm run type-check
- name: check Axios header compatibility
- name: check authentication
run: npm test
- name: check npm diff
id: diff
Expand Down
21 changes: 0 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,6 @@ api.getChannels().then(res => {
});
```

### Custom Axios header defaults

When making requests through this SDK, custom class instances in Axios header
defaults (`headers.common`, `headers.get`, `headers.post`, and other supported
methods) retain their behavior from Axios 1.20. Their own enumerable properties
are copied to plain header maps before Axios 1.21 prepares the request. Common
defaults apply to all methods; method defaults apply only to that method.

This applies to both a supplied Axios instance and headers in
`Configuration.baseOptions` or per-request options. The original instance and
default objects are preserved, including request and response interceptors.
Plain maps, null-prototype maps, `AxiosHeaders`, and literal headers such as
`Link` remain supported.
Class instances under these reserved names are treated as defaults; serialize
a custom object first when it is intended as a literal method-named header.

Direct requests made outside this SDK follow
[Axios 1.21's header-default rules](https://github.com/axios/axios/releases/tag/v1.21.0).
For those requests, convert custom class defaults explicitly, for example
`axios.create({ headers: { get: { ...customDefaults } } })`.

## Versioning

`x.y.z-n`
Expand Down
9 changes: 0 additions & 9 deletions build/addApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,11 @@ export default async function(generatedFolder: string) {

// Use Promise<AxiosResponse<T>> to avoid Axios' non-exported types in declarations.
const commonFile = project.getSourceFileOrThrow("common.ts")
commonFile.addImportDeclaration({
namedImports: ["normalizeAxiosRequestHeaders"],
moduleSpecifier: "../../src/axiosHeaders",
})
const request = commonFile.getVariableDeclarationOrThrow("createRequestFunction")
.getInitializerIfKindOrThrow(SyntaxKind.FunctionExpression)
.getFirstDescendantByKindOrThrow(SyntaxKind.ArrowFunction)
request.getTypeParameterOrThrow("R").remove()
request.setReturnType("Promise<AxiosResponse<T>>")
request.getVariableDeclarationOrThrow("axiosRequestArgs").setInitializer(`{
...axiosArgs.options,
url: (configuration?.basePath || basePath) + axiosArgs.url,
headers: normalizeAxiosRequestHeaders(axios, axiosArgs.options.headers),
}`)
const response = request.getFirstDescendantByKindOrThrow(SyntaxKind.ReturnStatement)
.getExpressionOrThrow()
.asKindOrThrow(SyntaxKind.CallExpression)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"build": "tsx build/index.ts && tsdown",
"test": "node --test tests/axios-headers.test.mjs",
"test": "node --test tests/auth.test.mjs",
"clean": "rimraf bin dist",
"type-check": "tsc --noEmit --allowJS --project tsconfig.json"
},
Expand Down
60 changes: 0 additions & 60 deletions src/axiosHeaders.ts

This file was deleted.

24 changes: 24 additions & 0 deletions tests/auth.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import assert from "node:assert/strict";
import { createRequire } from "node:module";
import { test } from "node:test";
import axios from "axios";
import * as esm from "../dist/index.js";

const require = createRequire(import.meta.url);

for (const [format, sdk] of [["ESM", esm], ["CommonJS", require("../dist/index.cjs")]]) {
test(`${format}: sends the configured access token`, async () => {
const client = axios.create({
adapter: async config => ({
data: config.headers.get("Authorization"),
status: 200,
statusText: "OK",
headers: {},
config,
}),
});
const api = new sdk.Apis(new sdk.Configuration({ accessToken: "test-token" }), undefined, client);
const response = await api.getChannels();
assert.equal(response.data, "Bearer test-token");
});
}
184 changes: 0 additions & 184 deletions tests/axios-headers.test.mjs

This file was deleted.

Loading