@deliverart/sdk-js-core 0.0.5 → 0.0.7
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/CHANGELOG.md +12 -0
- package/dist/index.cjs +13 -12
- package/dist/index.d.cts +11 -10
- package/dist/index.d.ts +11 -10
- package/dist/index.js +12 -11
- package/package.json +1 -1
- package/src/ApiClient.ts +20 -8
- package/src/types.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @deliverart/sdk-js-core
|
|
2
2
|
|
|
3
|
+
## 0.0.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c36723b: Extends ApiExtension with void type
|
|
8
|
+
|
|
9
|
+
## 0.0.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 14cc1fd: restructure ApiClient to use factory function and improve type definitions
|
|
14
|
+
|
|
3
15
|
## 0.0.5
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -30,23 +30,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
|
|
33
|
+
createApiClient: () => createApiClient
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
|
|
37
37
|
// src/ApiClient.ts
|
|
38
38
|
var import_axios = __toESM(require("axios"), 1);
|
|
39
|
-
|
|
40
|
-
http;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
39
|
+
function createApiClient(config) {
|
|
40
|
+
const http = import_axios.default.create({ baseURL: config.baseUrl });
|
|
41
|
+
const base = {
|
|
42
|
+
http,
|
|
43
|
+
addPlugin(plugin) {
|
|
44
|
+
const extension = plugin.setup(this);
|
|
45
|
+
return { ...this, ...extension };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return base;
|
|
49
|
+
}
|
|
49
50
|
// Annotate the CommonJS export names for ESM import in node:
|
|
50
51
|
0 && (module.exports = {
|
|
51
|
-
|
|
52
|
+
createApiClient
|
|
52
53
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
2
|
|
|
3
|
-
type ApiExtension = Record<string,
|
|
4
|
-
interface ApiClientPlugin<T extends ApiExtension =
|
|
5
|
-
setup(client: ApiClient<
|
|
3
|
+
type ApiExtension = Record<string, unknown>;
|
|
4
|
+
interface ApiClientPlugin<T extends ApiExtension = Record<string, unknown>> {
|
|
5
|
+
setup: (client: ApiClient<Record<string, unknown>>) => T;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
declare
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
declare function createApiClient<Extensions extends ApiExtension = NonNullable<unknown>>(config: {
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
}): ApiClient<Extensions>;
|
|
11
|
+
interface ApiClientBase {
|
|
12
|
+
http: AxiosInstance;
|
|
13
|
+
addPlugin: <T extends ApiExtension>(plugin: ApiClientPlugin<T>) => ApiClient<T>;
|
|
14
14
|
}
|
|
15
|
+
type ApiClient<Extensions extends ApiExtension = NonNullable<unknown>> = ApiClientBase & Extensions;
|
|
15
16
|
|
|
16
|
-
export { ApiClient, type ApiClientPlugin, type ApiExtension };
|
|
17
|
+
export { type ApiClient, type ApiClientPlugin, type ApiExtension, createApiClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios';
|
|
2
2
|
|
|
3
|
-
type ApiExtension = Record<string,
|
|
4
|
-
interface ApiClientPlugin<T extends ApiExtension =
|
|
5
|
-
setup(client: ApiClient<
|
|
3
|
+
type ApiExtension = Record<string, unknown>;
|
|
4
|
+
interface ApiClientPlugin<T extends ApiExtension = Record<string, unknown>> {
|
|
5
|
+
setup: (client: ApiClient<Record<string, unknown>>) => T;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
declare
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
declare function createApiClient<Extensions extends ApiExtension = NonNullable<unknown>>(config: {
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
}): ApiClient<Extensions>;
|
|
11
|
+
interface ApiClientBase {
|
|
12
|
+
http: AxiosInstance;
|
|
13
|
+
addPlugin: <T extends ApiExtension>(plugin: ApiClientPlugin<T>) => ApiClient<T>;
|
|
14
14
|
}
|
|
15
|
+
type ApiClient<Extensions extends ApiExtension = NonNullable<unknown>> = ApiClientBase & Extensions;
|
|
15
16
|
|
|
16
|
-
export { ApiClient, type ApiClientPlugin, type ApiExtension };
|
|
17
|
+
export { type ApiClient, type ApiClientPlugin, type ApiExtension, createApiClient };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
// src/ApiClient.ts
|
|
2
2
|
import axios from "axios";
|
|
3
|
-
|
|
4
|
-
http;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
3
|
+
function createApiClient(config) {
|
|
4
|
+
const http = axios.create({ baseURL: config.baseUrl });
|
|
5
|
+
const base = {
|
|
6
|
+
http,
|
|
7
|
+
addPlugin(plugin) {
|
|
8
|
+
const extension = plugin.setup(this);
|
|
9
|
+
return { ...this, ...extension };
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
return base;
|
|
13
|
+
}
|
|
13
14
|
export {
|
|
14
|
-
|
|
15
|
+
createApiClient
|
|
15
16
|
};
|
package/package.json
CHANGED
package/src/ApiClient.ts
CHANGED
|
@@ -2,15 +2,27 @@ import axios, { AxiosInstance } from 'axios'
|
|
|
2
2
|
|
|
3
3
|
import type { ApiClientPlugin, ApiExtension } from './types'
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
5
|
+
export function createApiClient<Extensions extends ApiExtension = NonNullable<unknown>>(config: {
|
|
6
|
+
baseUrl: string
|
|
7
|
+
}): ApiClient<Extensions> {
|
|
8
|
+
const http = axios.create({ baseURL: config.baseUrl })
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
const base: ApiClientBase = {
|
|
11
|
+
http,
|
|
12
|
+
addPlugin<T extends ApiExtension>(plugin: ApiClientPlugin<T>) {
|
|
13
|
+
const extension = plugin.setup(this as ApiClient<Extensions & T>)
|
|
14
|
+
return { ...this, ...extension } as ApiClient<Extensions & T>
|
|
15
|
+
},
|
|
10
16
|
}
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
return base as ApiClient<Extensions>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface ApiClientBase {
|
|
22
|
+
http: AxiosInstance
|
|
23
|
+
// eslint-disable-next-line no-unused-vars
|
|
24
|
+
addPlugin: <T extends ApiExtension>(plugin: ApiClientPlugin<T>) => ApiClient<T>
|
|
16
25
|
}
|
|
26
|
+
|
|
27
|
+
export type ApiClient<Extensions extends ApiExtension = NonNullable<unknown>> = ApiClientBase &
|
|
28
|
+
Extensions
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ApiClient } from './ApiClient'
|
|
2
2
|
|
|
3
|
-
export type ApiExtension = Record<string,
|
|
3
|
+
export type ApiExtension = Record<string, unknown>
|
|
4
4
|
|
|
5
|
-
export interface ApiClientPlugin<T extends ApiExtension =
|
|
5
|
+
export interface ApiClientPlugin<T extends ApiExtension = Record<string, unknown>> {
|
|
6
6
|
// eslint-disable-next-line no-unused-vars
|
|
7
|
-
setup(client: ApiClient<
|
|
7
|
+
setup: (client: ApiClient<Record<string, unknown>>) => T
|
|
8
8
|
}
|