@routar/axios 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +17 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -12
- package/dist/index.js.map +1 -1
- package/package.json +17 -4
package/README.md
CHANGED
|
@@ -8,4 +8,4 @@ Axios-based executor for [routar](https://github.com/kbmin1129/routar) — trans
|
|
|
8
8
|
npm install @routar/core @routar/axios axios
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
See the [main README](https://github.com/
|
|
11
|
+
See the [documentation](https://routar.vercel.app) or the [main README](https://github.com/minr2kb/routar) for full documentation.
|
package/dist/index.cjs
CHANGED
|
@@ -10,18 +10,23 @@ function resolveInstance(input) {
|
|
|
10
10
|
return input();
|
|
11
11
|
}
|
|
12
12
|
function createAxiosExecutor(instanceOrFactory, options) {
|
|
13
|
-
return core.createExecutor(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
return core.createExecutor(
|
|
14
|
+
async ({ method, url, params, body, headers, signal }) => {
|
|
15
|
+
const instance = await resolveInstance(instanceOrFactory);
|
|
16
|
+
const base = (instance.defaults.baseURL ?? "").replace(/\/$/, "");
|
|
17
|
+
const { data } = await instance.request({
|
|
18
|
+
method,
|
|
19
|
+
url: base + url,
|
|
20
|
+
baseURL: "",
|
|
21
|
+
params,
|
|
22
|
+
data: body,
|
|
23
|
+
headers,
|
|
24
|
+
signal
|
|
25
|
+
});
|
|
26
|
+
return data;
|
|
27
|
+
},
|
|
28
|
+
options?.middlewares
|
|
29
|
+
);
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
exports.createAxiosExecutor = createAxiosExecutor;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/create-axios-executor.ts"],"names":["createExecutor"],"mappings":";;;;;AAwBA,SAAS,
|
|
1
|
+
{"version":3,"sources":["../src/create-axios-executor.ts"],"names":["createExecutor"],"mappings":";;;;;AAwBA,SAAS,gBACP,KAAA,EACwC;AAExC,EAAA,IAAI,kBAAmB,KAAA,EAAkB;AACvC,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAQ,KAAA,EAA0B;AACpC;AA6BO,SAAS,mBAAA,CACd,mBACA,OAAA,EAGU;AACV,EAAA,OAAOA,mBAAA;AAAA,IACL,OAAO,EAAE,MAAA,EAAQ,GAAA,EAAK,QAAQ,IAAA,EAAM,OAAA,EAAS,QAAO,KAAM;AACxD,MAAA,MAAM,QAAA,GAAW,MAAM,eAAA,CAAgB,iBAAiB,CAAA;AACxD,MAAA,MAAM,QAAQ,QAAA,CAAS,QAAA,CAAS,WAAW,EAAA,EAAI,OAAA,CAAQ,OAAO,EAAE,CAAA;AAChE,MAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,SAAS,OAAA,CAAQ;AAAA,QACtC,MAAA;AAAA,QACA,KAAK,IAAA,GAAO,GAAA;AAAA,QACZ,OAAA,EAAS,EAAA;AAAA,QACT,MAAA;AAAA,QACA,IAAA,EAAM,IAAA;AAAA,QACN,OAAA;AAAA,QACA;AAAA,OACD,CAAA;AACD,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA,IACA,OAAA,EAAS;AAAA,GACX;AACF","file":"index.cjs","sourcesContent":["import type { Executor, ExecutorMiddleware } from \"@routar/core\";\nimport { createExecutor } from \"@routar/core\";\nimport type { AxiosInstance } from \"axios\";\n\n/** Zero-argument factory that returns an Axios instance (optionally async). */\ntype InstanceFactory = () => AxiosInstance | Promise<AxiosInstance>;\n\n/**\n * Accepted input for {@link createAxiosExecutor}.\n *\n * Pass a pre-configured `AxiosInstance` for CSR (the same instance is reused\n * across requests, which preserves interceptors and connection pooling).\n * Pass a factory function for SSR so a fresh instance — with per-request\n * headers or tokens — can be created on each call.\n */\nexport type InstanceOrFactory = AxiosInstance | InstanceFactory;\n\n/**\n * Discriminates between an `AxiosInstance` and a plain factory function.\n *\n * `AxiosInstance` is itself callable, so `typeof input === 'function'` cannot\n * distinguish the two. Duck-typing via `interceptors` works because Axios\n * always attaches it to instances, while user-supplied factories do not.\n */\nfunction resolveInstance(\n input: InstanceOrFactory,\n): AxiosInstance | Promise<AxiosInstance> {\n // AxiosInstance is callable but always has `interceptors`; plain factory functions do not.\n if (\"interceptors\" in (input as object)) {\n return input as AxiosInstance;\n }\n return (input as InstanceFactory)();\n}\n\n/**\n * Creates an {@link Executor} backed by Axios.\n *\n * Suited for CSR where a single shared `AxiosInstance` is preferred (fast,\n * interceptor-friendly). Also supports SSR via a factory that produces a\n * fresh instance per request, allowing dynamic per-request auth headers.\n *\n * Axios error objects (`AxiosError`) propagate unchanged through the executor\n * so you can inspect `err.response`, `err.code`, etc. in middleware or\n * callers — use `withRetry`'s `shouldRetry` option to skip retries on 4xx.\n *\n * @param instanceOrFactory - A pre-built `AxiosInstance` (CSR) or a factory\n * function that returns one (SSR / per-request config).\n * @param options.middlewares - Middleware chain applied before the Axios call.\n *\n * @example\n * ```ts\n * // CSR — shared instance\n * const executor = createAxiosExecutor(axios.create({ baseURL: 'https://api.example.com' }));\n *\n * // SSR — factory\n * const executor = createAxiosExecutor(async () => {\n * const token = await getServerToken();\n * return axios.create({ baseURL: 'https://api.example.com', headers: { Authorization: `Bearer ${token}` } });\n * });\n * ```\n */\nexport function createAxiosExecutor(\n instanceOrFactory: InstanceOrFactory,\n options?: {\n middlewares?: ExecutorMiddleware[];\n },\n): Executor {\n return createExecutor(\n async ({ method, url, params, body, headers, signal }) => {\n const instance = await resolveInstance(instanceOrFactory);\n const base = (instance.defaults.baseURL ?? '').replace(/\\/$/, '');\n const { data } = await instance.request({\n method,\n url: base + url,\n baseURL: '',\n params,\n data: body,\n headers,\n signal,\n });\n return data;\n },\n options?.middlewares,\n );\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -8,18 +8,23 @@ function resolveInstance(input) {
|
|
|
8
8
|
return input();
|
|
9
9
|
}
|
|
10
10
|
function createAxiosExecutor(instanceOrFactory, options) {
|
|
11
|
-
return createExecutor(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
return createExecutor(
|
|
12
|
+
async ({ method, url, params, body, headers, signal }) => {
|
|
13
|
+
const instance = await resolveInstance(instanceOrFactory);
|
|
14
|
+
const base = (instance.defaults.baseURL ?? "").replace(/\/$/, "");
|
|
15
|
+
const { data } = await instance.request({
|
|
16
|
+
method,
|
|
17
|
+
url: base + url,
|
|
18
|
+
baseURL: "",
|
|
19
|
+
params,
|
|
20
|
+
data: body,
|
|
21
|
+
headers,
|
|
22
|
+
signal
|
|
23
|
+
});
|
|
24
|
+
return data;
|
|
25
|
+
},
|
|
26
|
+
options?.middlewares
|
|
27
|
+
);
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
export { createAxiosExecutor };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/create-axios-executor.ts"],"names":[],"mappings":";;;AAwBA,SAAS,
|
|
1
|
+
{"version":3,"sources":["../src/create-axios-executor.ts"],"names":[],"mappings":";;;AAwBA,SAAS,gBACP,KAAA,EACwC;AAExC,EAAA,IAAI,kBAAmB,KAAA,EAAkB;AACvC,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAQ,KAAA,EAA0B;AACpC;AA6BO,SAAS,mBAAA,CACd,mBACA,OAAA,EAGU;AACV,EAAA,OAAO,cAAA;AAAA,IACL,OAAO,EAAE,MAAA,EAAQ,GAAA,EAAK,QAAQ,IAAA,EAAM,OAAA,EAAS,QAAO,KAAM;AACxD,MAAA,MAAM,QAAA,GAAW,MAAM,eAAA,CAAgB,iBAAiB,CAAA;AACxD,MAAA,MAAM,QAAQ,QAAA,CAAS,QAAA,CAAS,WAAW,EAAA,EAAI,OAAA,CAAQ,OAAO,EAAE,CAAA;AAChE,MAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,SAAS,OAAA,CAAQ;AAAA,QACtC,MAAA;AAAA,QACA,KAAK,IAAA,GAAO,GAAA;AAAA,QACZ,OAAA,EAAS,EAAA;AAAA,QACT,MAAA;AAAA,QACA,IAAA,EAAM,IAAA;AAAA,QACN,OAAA;AAAA,QACA;AAAA,OACD,CAAA;AACD,MAAA,OAAO,IAAA;AAAA,IACT,CAAA;AAAA,IACA,OAAA,EAAS;AAAA,GACX;AACF","file":"index.js","sourcesContent":["import type { Executor, ExecutorMiddleware } from \"@routar/core\";\nimport { createExecutor } from \"@routar/core\";\nimport type { AxiosInstance } from \"axios\";\n\n/** Zero-argument factory that returns an Axios instance (optionally async). */\ntype InstanceFactory = () => AxiosInstance | Promise<AxiosInstance>;\n\n/**\n * Accepted input for {@link createAxiosExecutor}.\n *\n * Pass a pre-configured `AxiosInstance` for CSR (the same instance is reused\n * across requests, which preserves interceptors and connection pooling).\n * Pass a factory function for SSR so a fresh instance — with per-request\n * headers or tokens — can be created on each call.\n */\nexport type InstanceOrFactory = AxiosInstance | InstanceFactory;\n\n/**\n * Discriminates between an `AxiosInstance` and a plain factory function.\n *\n * `AxiosInstance` is itself callable, so `typeof input === 'function'` cannot\n * distinguish the two. Duck-typing via `interceptors` works because Axios\n * always attaches it to instances, while user-supplied factories do not.\n */\nfunction resolveInstance(\n input: InstanceOrFactory,\n): AxiosInstance | Promise<AxiosInstance> {\n // AxiosInstance is callable but always has `interceptors`; plain factory functions do not.\n if (\"interceptors\" in (input as object)) {\n return input as AxiosInstance;\n }\n return (input as InstanceFactory)();\n}\n\n/**\n * Creates an {@link Executor} backed by Axios.\n *\n * Suited for CSR where a single shared `AxiosInstance` is preferred (fast,\n * interceptor-friendly). Also supports SSR via a factory that produces a\n * fresh instance per request, allowing dynamic per-request auth headers.\n *\n * Axios error objects (`AxiosError`) propagate unchanged through the executor\n * so you can inspect `err.response`, `err.code`, etc. in middleware or\n * callers — use `withRetry`'s `shouldRetry` option to skip retries on 4xx.\n *\n * @param instanceOrFactory - A pre-built `AxiosInstance` (CSR) or a factory\n * function that returns one (SSR / per-request config).\n * @param options.middlewares - Middleware chain applied before the Axios call.\n *\n * @example\n * ```ts\n * // CSR — shared instance\n * const executor = createAxiosExecutor(axios.create({ baseURL: 'https://api.example.com' }));\n *\n * // SSR — factory\n * const executor = createAxiosExecutor(async () => {\n * const token = await getServerToken();\n * return axios.create({ baseURL: 'https://api.example.com', headers: { Authorization: `Bearer ${token}` } });\n * });\n * ```\n */\nexport function createAxiosExecutor(\n instanceOrFactory: InstanceOrFactory,\n options?: {\n middlewares?: ExecutorMiddleware[];\n },\n): Executor {\n return createExecutor(\n async ({ method, url, params, body, headers, signal }) => {\n const instance = await resolveInstance(instanceOrFactory);\n const base = (instance.defaults.baseURL ?? '').replace(/\\/$/, '');\n const { data } = await instance.request({\n method,\n url: base + url,\n baseURL: '',\n params,\n data: body,\n headers,\n signal,\n });\n return data;\n },\n options?.middlewares,\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routar/axios",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Axios-based executor for routar — transport adapter using Axios",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"api",
|
|
7
|
+
"http",
|
|
8
|
+
"typescript",
|
|
9
|
+
"axios",
|
|
10
|
+
"routar",
|
|
11
|
+
"executor"
|
|
12
|
+
],
|
|
6
13
|
"author": "Kyungbae Min",
|
|
7
14
|
"license": "MIT",
|
|
8
15
|
"repository": {
|
|
@@ -22,7 +29,11 @@
|
|
|
22
29
|
"main": "./dist/index.cjs",
|
|
23
30
|
"module": "./dist/index.js",
|
|
24
31
|
"types": "./dist/index.d.ts",
|
|
25
|
-
"files": [
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
26
37
|
"scripts": {
|
|
27
38
|
"build": "tsup",
|
|
28
39
|
"dev": "tsup --watch"
|
|
@@ -37,5 +48,7 @@
|
|
|
37
48
|
"tsup": "^8.0.0",
|
|
38
49
|
"typescript": "^6.0.0"
|
|
39
50
|
},
|
|
40
|
-
"publishConfig": {
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
}
|
|
41
54
|
}
|