@mittwald/api-client-commons 4.1.2-alpha.4 → 4.1.3-alpha.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.
Files changed (114) hide show
  1. package/dist/index.d.mts +45 -0
  2. package/dist/index.d.ts +45 -0
  3. package/dist/index.mjs +22 -0
  4. package/dist/react/index.d.mts +19 -0
  5. package/dist/react/index.d.ts +19 -0
  6. package/dist/react/index.mjs +49 -0
  7. package/dist/shared/api-client-commons.2a6e3962.mjs +128 -0
  8. package/dist/shared/api-client-commons.5e434015.d.mts +71 -0
  9. package/dist/shared/api-client-commons.5e434015.d.ts +71 -0
  10. package/package.json +51 -57
  11. package/dist/cjs/axios.d.ts +0 -1
  12. package/dist/cjs/axios.js +0 -17
  13. package/dist/cjs/core/ApiClientBase.d.ts +0 -9
  14. package/dist/cjs/core/ApiClientBase.js +0 -42
  15. package/dist/cjs/core/ApiClientError.d.ts +0 -7
  16. package/dist/cjs/core/ApiClientError.js +0 -16
  17. package/dist/cjs/core/OpenAPIPath.d.ts +0 -9
  18. package/dist/cjs/core/OpenAPIPath.js +0 -22
  19. package/dist/cjs/core/Request.d.ts +0 -13
  20. package/dist/cjs/core/Request.js +0 -80
  21. package/dist/cjs/core/Request.test.d.ts +0 -1
  22. package/dist/cjs/core/Request.test.js +0 -58
  23. package/dist/cjs/core/index.d.ts +0 -4
  24. package/dist/cjs/core/index.js +0 -20
  25. package/dist/cjs/index.d.ts +0 -3
  26. package/dist/cjs/index.js +0 -19
  27. package/dist/cjs/react/ApiCallAsyncResourceFactory.d.ts +0 -12
  28. package/dist/cjs/react/ApiCallAsyncResourceFactory.js +0 -52
  29. package/dist/cjs/react/ApiCallAsyncResourceFactory.test-types.d.ts +0 -1
  30. package/dist/cjs/react/ApiCallAsyncResourceFactory.test-types.js +0 -38
  31. package/dist/cjs/react/ApiCallAsyncResourceFactory.test.d.ts +0 -1
  32. package/dist/cjs/react/ApiCallAsyncResourceFactory.test.js +0 -57
  33. package/dist/cjs/react/index.d.ts +0 -1
  34. package/dist/cjs/react/index.js +0 -17
  35. package/dist/cjs/react/types.d.ts +0 -3
  36. package/dist/cjs/react/types.js +0 -2
  37. package/dist/cjs/types/NullableOnNoRequiredKeysDeep.d.ts +0 -6
  38. package/dist/cjs/types/NullableOnNoRequiredKeysDeep.js +0 -2
  39. package/dist/cjs/types/OpenAPIOperation.d.ts +0 -16
  40. package/dist/cjs/types/OpenAPIOperation.js +0 -2
  41. package/dist/cjs/types/RequestFunction.d.ts +0 -11
  42. package/dist/cjs/types/RequestFunction.js +0 -2
  43. package/dist/cjs/types/RequestFunction.test-types.d.ts +0 -1
  44. package/dist/cjs/types/RequestFunction.test-types.js +0 -30
  45. package/dist/cjs/types/RequestType.d.ts +0 -21
  46. package/dist/cjs/types/RequestType.js +0 -2
  47. package/dist/cjs/types/RequestType.test-types.d.ts +0 -1
  48. package/dist/cjs/types/RequestType.test-types.js +0 -148
  49. package/dist/cjs/types/Response.d.ts +0 -7
  50. package/dist/cjs/types/Response.js +0 -2
  51. package/dist/cjs/types/Response.test-types.d.ts +0 -1
  52. package/dist/cjs/types/Response.test-types.js +0 -43
  53. package/dist/cjs/types/assertStatus.d.ts +0 -5
  54. package/dist/cjs/types/assertStatus.js +0 -14
  55. package/dist/cjs/types/assertStatus.test-types.d.ts +0 -1
  56. package/dist/cjs/types/assertStatus.test-types.js +0 -13
  57. package/dist/cjs/types/http.d.ts +0 -13
  58. package/dist/cjs/types/http.js +0 -2
  59. package/dist/cjs/types/index.d.ts +0 -8
  60. package/dist/cjs/types/index.js +0 -24
  61. package/dist/cjs/types/simplify.d.ts +0 -3
  62. package/dist/cjs/types/simplify.js +0 -2
  63. package/dist/esm/axios.d.ts +0 -1
  64. package/dist/esm/axios.js +0 -1
  65. package/dist/esm/core/ApiClientBase.d.ts +0 -9
  66. package/dist/esm/core/ApiClientBase.js +0 -13
  67. package/dist/esm/core/ApiClientError.d.ts +0 -7
  68. package/dist/esm/core/ApiClientError.js +0 -12
  69. package/dist/esm/core/OpenAPIPath.d.ts +0 -9
  70. package/dist/esm/core/OpenAPIPath.js +0 -20
  71. package/dist/esm/core/Request.d.ts +0 -13
  72. package/dist/esm/core/Request.js +0 -76
  73. package/dist/esm/core/Request.test.d.ts +0 -1
  74. package/dist/esm/core/Request.test.js +0 -53
  75. package/dist/esm/core/index.d.ts +0 -4
  76. package/dist/esm/core/index.js +0 -4
  77. package/dist/esm/index.d.ts +0 -3
  78. package/dist/esm/index.js +0 -3
  79. package/dist/esm/react/ApiCallAsyncResourceFactory.d.ts +0 -12
  80. package/dist/esm/react/ApiCallAsyncResourceFactory.js +0 -35
  81. package/dist/esm/react/ApiCallAsyncResourceFactory.test-types.d.ts +0 -1
  82. package/dist/esm/react/ApiCallAsyncResourceFactory.test-types.js +0 -36
  83. package/dist/esm/react/ApiCallAsyncResourceFactory.test.d.ts +0 -1
  84. package/dist/esm/react/ApiCallAsyncResourceFactory.test.js +0 -46
  85. package/dist/esm/react/index.d.ts +0 -1
  86. package/dist/esm/react/index.js +0 -1
  87. package/dist/esm/react/types.d.ts +0 -3
  88. package/dist/esm/react/types.js +0 -1
  89. package/dist/esm/types/NullableOnNoRequiredKeysDeep.d.ts +0 -6
  90. package/dist/esm/types/NullableOnNoRequiredKeysDeep.js +0 -1
  91. package/dist/esm/types/OpenAPIOperation.d.ts +0 -16
  92. package/dist/esm/types/OpenAPIOperation.js +0 -1
  93. package/dist/esm/types/RequestFunction.d.ts +0 -11
  94. package/dist/esm/types/RequestFunction.js +0 -1
  95. package/dist/esm/types/RequestFunction.test-types.d.ts +0 -1
  96. package/dist/esm/types/RequestFunction.test-types.js +0 -29
  97. package/dist/esm/types/RequestType.d.ts +0 -21
  98. package/dist/esm/types/RequestType.js +0 -1
  99. package/dist/esm/types/RequestType.test-types.d.ts +0 -1
  100. package/dist/esm/types/RequestType.test-types.js +0 -146
  101. package/dist/esm/types/Response.d.ts +0 -7
  102. package/dist/esm/types/Response.js +0 -1
  103. package/dist/esm/types/Response.test-types.d.ts +0 -1
  104. package/dist/esm/types/Response.test-types.js +0 -70
  105. package/dist/esm/types/assertStatus.d.ts +0 -5
  106. package/dist/esm/types/assertStatus.js +0 -7
  107. package/dist/esm/types/assertStatus.test-types.d.ts +0 -1
  108. package/dist/esm/types/assertStatus.test-types.js +0 -8
  109. package/dist/esm/types/http.d.ts +0 -13
  110. package/dist/esm/types/http.js +0 -1
  111. package/dist/esm/types/index.d.ts +0 -8
  112. package/dist/esm/types/index.js +0 -8
  113. package/dist/esm/types/simplify.d.ts +0 -3
  114. package/dist/esm/types/simplify.js +0 -1
@@ -0,0 +1,45 @@
1
+ import { AxiosInstance, CreateAxiosDefaults, AxiosError, InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig } from 'axios';
2
+ export * from 'axios';
3
+ import { R as Response, O as OpenAPIOperation, a as RequestFunction, A as AnyResponse, P as PathParameters, b as RequestObject, c as ResponsePromise } from './shared/api-client-commons.5e434015.mjs';
4
+ export { e as AnyRequest, l as HttpHeaders, j as HttpMediaType, k as HttpMethod, H as HttpPayload, i as HttpStatus, I as InferredRequestType, f as InferredResponseType, Q as QueryParameters, h as RequestData, d as RequestType, g as ResponseData } from './shared/api-client-commons.5e434015.mjs';
5
+ import 'type-fest';
6
+
7
+ declare function assertStatus<T extends Response, S extends T["status"]>(response: T, expectedStatus: S): asserts response is T & {
8
+ status: S;
9
+ };
10
+
11
+ type Simplify<T> = {
12
+ [KeyType in keyof T]: T[KeyType];
13
+ } & {};
14
+
15
+ declare abstract class ApiClientBase {
16
+ axios: AxiosInstance;
17
+ constructor(axiosConfig?: AxiosInstance | CreateAxiosDefaults);
18
+ protected requestFunctionFactory<TOp extends OpenAPIOperation>(operation: TOp): RequestFunction<TOp>;
19
+ }
20
+
21
+ declare class ApiClientError<T = unknown, D = unknown> extends AxiosError<T, D> {
22
+ constructor(message?: string, code?: string, config?: InternalAxiosRequestConfig<D>, request?: unknown, response?: AxiosResponse<T, D>);
23
+ static fromResponse(message: string, response: AnyResponse): ApiClientError;
24
+ }
25
+
26
+ declare class OpenAPIPath {
27
+ private readonly rawPath;
28
+ private readonly params?;
29
+ constructor(rawPath: string, params?: PathParameters);
30
+ buildUrl(): string;
31
+ private static setPathParams;
32
+ }
33
+
34
+ declare class Request<TOp extends OpenAPIOperation> {
35
+ private readonly operationDescriptor;
36
+ private readonly requestObject?;
37
+ readonly requestConfig: AxiosRequestConfig;
38
+ constructor(operationDescriptor: TOp, requestObject?: RequestObject<TOp>);
39
+ execute(axios: AxiosInstance): ResponsePromise<TOp>;
40
+ private buildAxiosConfig;
41
+ private makeAxiosHeaders;
42
+ private convertQueryToUrlSearchParams;
43
+ }
44
+
45
+ export { AnyResponse, ApiClientBase, ApiClientError, OpenAPIOperation, OpenAPIPath, PathParameters, Request, RequestFunction, RequestObject, Response, ResponsePromise, type Simplify, assertStatus };
@@ -0,0 +1,45 @@
1
+ import { AxiosInstance, CreateAxiosDefaults, AxiosError, InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig } from 'axios';
2
+ export * from 'axios';
3
+ import { R as Response, O as OpenAPIOperation, a as RequestFunction, A as AnyResponse, P as PathParameters, b as RequestObject, c as ResponsePromise } from './shared/api-client-commons.5e434015.js';
4
+ export { e as AnyRequest, l as HttpHeaders, j as HttpMediaType, k as HttpMethod, H as HttpPayload, i as HttpStatus, I as InferredRequestType, f as InferredResponseType, Q as QueryParameters, h as RequestData, d as RequestType, g as ResponseData } from './shared/api-client-commons.5e434015.js';
5
+ import 'type-fest';
6
+
7
+ declare function assertStatus<T extends Response, S extends T["status"]>(response: T, expectedStatus: S): asserts response is T & {
8
+ status: S;
9
+ };
10
+
11
+ type Simplify<T> = {
12
+ [KeyType in keyof T]: T[KeyType];
13
+ } & {};
14
+
15
+ declare abstract class ApiClientBase {
16
+ axios: AxiosInstance;
17
+ constructor(axiosConfig?: AxiosInstance | CreateAxiosDefaults);
18
+ protected requestFunctionFactory<TOp extends OpenAPIOperation>(operation: TOp): RequestFunction<TOp>;
19
+ }
20
+
21
+ declare class ApiClientError<T = unknown, D = unknown> extends AxiosError<T, D> {
22
+ constructor(message?: string, code?: string, config?: InternalAxiosRequestConfig<D>, request?: unknown, response?: AxiosResponse<T, D>);
23
+ static fromResponse(message: string, response: AnyResponse): ApiClientError;
24
+ }
25
+
26
+ declare class OpenAPIPath {
27
+ private readonly rawPath;
28
+ private readonly params?;
29
+ constructor(rawPath: string, params?: PathParameters);
30
+ buildUrl(): string;
31
+ private static setPathParams;
32
+ }
33
+
34
+ declare class Request<TOp extends OpenAPIOperation> {
35
+ private readonly operationDescriptor;
36
+ private readonly requestObject?;
37
+ readonly requestConfig: AxiosRequestConfig;
38
+ constructor(operationDescriptor: TOp, requestObject?: RequestObject<TOp>);
39
+ execute(axios: AxiosInstance): ResponsePromise<TOp>;
40
+ private buildAxiosConfig;
41
+ private makeAxiosHeaders;
42
+ private convertQueryToUrlSearchParams;
43
+ }
44
+
45
+ export { AnyResponse, ApiClientBase, ApiClientError, OpenAPIOperation, OpenAPIPath, PathParameters, Request, RequestFunction, RequestObject, Response, ResponsePromise, type Simplify, assertStatus };
package/dist/index.mjs ADDED
@@ -0,0 +1,22 @@
1
+ import axios__default, { Axios } from 'axios';
2
+ export * from 'axios';
3
+ import { R as Request } from './shared/api-client-commons.2a6e3962.mjs';
4
+ export { A as ApiClientError, O as OpenAPIPath, a as assertStatus } from './shared/api-client-commons.2a6e3962.mjs';
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __publicField = (obj, key, value) => {
9
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
+ return value;
11
+ };
12
+ class ApiClientBase {
13
+ constructor(axiosConfig = axios__default) {
14
+ __publicField(this, "axios");
15
+ this.axios = axiosConfig instanceof Axios ? axiosConfig : axios__default.create(axiosConfig);
16
+ }
17
+ requestFunctionFactory(operation) {
18
+ return (conf) => new Request(operation, conf).execute(this.axios);
19
+ }
20
+ }
21
+
22
+ export { ApiClientBase, Request };
@@ -0,0 +1,19 @@
1
+ import { O as OpenAPIOperation, b as RequestObject, g as ResponseData, a as RequestFunction } from '../shared/api-client-commons.5e434015.mjs';
2
+ import { AsyncResource } from '@mittwald/react-use-promise';
3
+ import 'axios';
4
+ import 'type-fest';
5
+
6
+ type GetApiResourceFn<TOp extends OpenAPIOperation> = null extends RequestObject<TOp> ? (conf?: RequestObject<TOp>) => AsyncResource<ResponseData<TOp>> : (conf: RequestObject<TOp>) => AsyncResource<ResponseData<TOp>>;
7
+
8
+ declare class ApiCallAsyncResourceFactory<TOp extends OpenAPIOperation> {
9
+ private static namespace;
10
+ private readonly operation;
11
+ private readonly requestFn;
12
+ constructor(operation: TOp, requestFn: RequestFunction<TOp>);
13
+ private getAsyncResourceId;
14
+ private getAsyncResourceTags;
15
+ private executeRequest;
16
+ getApiResource: GetApiResourceFn<TOp>;
17
+ }
18
+
19
+ export { ApiCallAsyncResourceFactory };
@@ -0,0 +1,19 @@
1
+ import { O as OpenAPIOperation, b as RequestObject, g as ResponseData, a as RequestFunction } from '../shared/api-client-commons.5e434015.js';
2
+ import { AsyncResource } from '@mittwald/react-use-promise';
3
+ import 'axios';
4
+ import 'type-fest';
5
+
6
+ type GetApiResourceFn<TOp extends OpenAPIOperation> = null extends RequestObject<TOp> ? (conf?: RequestObject<TOp>) => AsyncResource<ResponseData<TOp>> : (conf: RequestObject<TOp>) => AsyncResource<ResponseData<TOp>>;
7
+
8
+ declare class ApiCallAsyncResourceFactory<TOp extends OpenAPIOperation> {
9
+ private static namespace;
10
+ private readonly operation;
11
+ private readonly requestFn;
12
+ constructor(operation: TOp, requestFn: RequestFunction<TOp>);
13
+ private getAsyncResourceId;
14
+ private getAsyncResourceTags;
15
+ private executeRequest;
16
+ getApiResource: GetApiResourceFn<TOp>;
17
+ }
18
+
19
+ export { ApiCallAsyncResourceFactory };
@@ -0,0 +1,49 @@
1
+ import { getAsyncResource } from '@mittwald/react-use-promise';
2
+ import { R as Request, a as assertStatus } from '../shared/api-client-commons.2a6e3962.mjs';
3
+ import 'axios';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __publicField = (obj, key, value) => {
8
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
+ return value;
10
+ };
11
+ const _ApiCallAsyncResourceFactory = class _ApiCallAsyncResourceFactory {
12
+ constructor(operation, requestFn) {
13
+ __publicField(this, "operation");
14
+ __publicField(this, "requestFn");
15
+ __publicField(this, "getApiResource", (requestObj) => {
16
+ const request = new Request(this.operation, requestObj);
17
+ return getAsyncResource(
18
+ (requestObj2) => this.executeRequest(requestObj2),
19
+ [requestObj],
20
+ {
21
+ tags: this.getAsyncResourceTags(request),
22
+ loaderId: this.getAsyncResourceId()
23
+ }
24
+ );
25
+ });
26
+ this.operation = operation;
27
+ this.requestFn = requestFn;
28
+ }
29
+ getAsyncResourceId() {
30
+ return `${_ApiCallAsyncResourceFactory.namespace}/${this.operation.operationId}`;
31
+ }
32
+ getAsyncResourceTags(request) {
33
+ const url = request.requestConfig.url ?? "";
34
+ return [
35
+ this.getAsyncResourceId(),
36
+ `${_ApiCallAsyncResourceFactory.namespace}/${this.operation.method}`,
37
+ `${_ApiCallAsyncResourceFactory.namespace}/${url}`
38
+ ];
39
+ }
40
+ async executeRequest(requestObj) {
41
+ const response = await this.requestFn(requestObj);
42
+ assertStatus(response, 200);
43
+ return response.data;
44
+ }
45
+ };
46
+ __publicField(_ApiCallAsyncResourceFactory, "namespace", "@mittwald/api-client");
47
+ let ApiCallAsyncResourceFactory = _ApiCallAsyncResourceFactory;
48
+
49
+ export { ApiCallAsyncResourceFactory };
@@ -0,0 +1,128 @@
1
+ import { AxiosError } from 'axios';
2
+
3
+ var __defProp$1 = Object.defineProperty;
4
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField$1 = (obj, key, value) => {
6
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ return value;
8
+ };
9
+ class OpenAPIPath {
10
+ constructor(rawPath, params) {
11
+ __publicField$1(this, "rawPath");
12
+ __publicField$1(this, "params");
13
+ this.rawPath = rawPath;
14
+ this.params = params;
15
+ }
16
+ buildUrl() {
17
+ return OpenAPIPath.setPathParams(this.rawPath, this.params);
18
+ }
19
+ static setPathParams(path, params) {
20
+ const asEntries = Object.entries(params ?? {});
21
+ const finalPath = asEntries.reduce((path2, entry) => {
22
+ const [key, value] = entry;
23
+ return path2.replace(`{${key}}`, encodeURIComponent(value));
24
+ }, path);
25
+ return finalPath.startsWith("/") ? finalPath.substring(1) : finalPath;
26
+ }
27
+ }
28
+
29
+ var __defProp = Object.defineProperty;
30
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
31
+ var __publicField = (obj, key, value) => {
32
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
33
+ return value;
34
+ };
35
+ class Request {
36
+ constructor(operationDescriptor, requestObject) {
37
+ __publicField(this, "operationDescriptor");
38
+ __publicField(this, "requestObject");
39
+ __publicField(this, "requestConfig");
40
+ this.operationDescriptor = operationDescriptor;
41
+ this.requestObject = requestObject;
42
+ this.requestConfig = Object.freeze(this.buildAxiosConfig());
43
+ }
44
+ execute(axios) {
45
+ return axios.request(this.requestConfig);
46
+ }
47
+ buildAxiosConfig() {
48
+ const { method, path } = this.operationDescriptor;
49
+ const pathParameters = this.requestObject;
50
+ const openApiPath = new OpenAPIPath(path, pathParameters);
51
+ const url = openApiPath.buildUrl();
52
+ const data = this.requestObject && "data" in this.requestObject ? this.requestObject.data : void 0;
53
+ const headersConfig = this.requestObject && "headers" in this.requestObject ? this.requestObject.headers : void 0;
54
+ const headers = headersConfig ? this.makeAxiosHeaders(headersConfig) : void 0;
55
+ const queryParametersConfig = this.requestObject && "queryParameters" in this.requestObject ? this.requestObject.queryParameters : void 0;
56
+ const params = this.convertQueryToUrlSearchParams(queryParametersConfig);
57
+ return {
58
+ url,
59
+ method,
60
+ headers,
61
+ // Must be a plain object or an URLSearchParams object
62
+ params,
63
+ data,
64
+ validateStatus: () => true
65
+ };
66
+ }
67
+ makeAxiosHeaders(headers) {
68
+ return Object.fromEntries(
69
+ Object.entries(headers).map(([key, value]) => [key, value?.toString()])
70
+ );
71
+ }
72
+ convertQueryToUrlSearchParams(query) {
73
+ if (query === void 0 || query === null) {
74
+ return void 0;
75
+ }
76
+ if (query instanceof URLSearchParams) {
77
+ return query;
78
+ }
79
+ if (typeof query === "string") {
80
+ return new URLSearchParams(query);
81
+ }
82
+ if (typeof query === "object") {
83
+ const searchParams = new URLSearchParams();
84
+ for (const [key, value] of Object.entries(query)) {
85
+ if (Array.isArray(value)) {
86
+ for (const arrayItem of value) {
87
+ searchParams.append(key, arrayItem);
88
+ }
89
+ } else {
90
+ searchParams.append(
91
+ key,
92
+ typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? value.toString() : JSON.stringify(value)
93
+ );
94
+ }
95
+ }
96
+ return searchParams;
97
+ }
98
+ throw new Error(`Unexpected query parameter type (${typeof query})`);
99
+ }
100
+ }
101
+
102
+ class ApiClientError extends AxiosError {
103
+ constructor(message, code, config, request, response) {
104
+ super(message, code, config, request, response);
105
+ Object.setPrototypeOf(this, ApiClientError.prototype);
106
+ this.name = "ApiClientError";
107
+ }
108
+ static fromResponse(message, response) {
109
+ return new ApiClientError(
110
+ message,
111
+ void 0,
112
+ response.config,
113
+ response.request,
114
+ response
115
+ );
116
+ }
117
+ }
118
+
119
+ function assertStatus(response, expectedStatus) {
120
+ if (response.status !== expectedStatus) {
121
+ throw ApiClientError.fromResponse(
122
+ `Unexpected response status (expected ${expectedStatus}, got: ${response.status})`,
123
+ response
124
+ );
125
+ }
126
+ }
127
+
128
+ export { ApiClientError as A, OpenAPIPath as O, Request as R, assertStatus as a };
@@ -0,0 +1,71 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { HasRequiredKeys, PartialOnUndefinedDeep, OmitIndexSignature } from 'type-fest';
3
+
4
+ type HttpPayload = unknown;
5
+ type HttpStatus = number | "default";
6
+ type HttpMediaType = string;
7
+ type SafeHttpMethod = "GET" | "HEAD" | "OPTIONS";
8
+ type UnsafeHttpMethod = "PUT" | "DELETE" | "POST" | "PATCH";
9
+ type HttpMethod = SafeHttpMethod | UnsafeHttpMethod;
10
+ type HeaderValue = string | number | boolean;
11
+ type HttpHeaders = Partial<{
12
+ [TKey: string]: HeaderValue | HeaderValue[];
13
+ }>;
14
+ type PathParameters = Record<string, string | number>;
15
+ type QueryParameters = Record<string, unknown>;
16
+
17
+ type EmptyObject = Record<string, never>;
18
+ type EmptyRequestComponent = EmptyObject | null;
19
+ type RequestWithOptionalHeaders = {
20
+ headers?: HttpHeaders;
21
+ };
22
+ type RequestWithData<TData> = TData extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
23
+ data: TData;
24
+ };
25
+ type RequestWithPathParameters<TPathParameters> = TPathParameters extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
26
+ pathParameters: TPathParameters;
27
+ };
28
+ type RequestWithHeaders<THeaders> = THeaders extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
29
+ headers: THeaders & HttpHeaders;
30
+ };
31
+ type RequestWithQueryParameters<TQuery> = TQuery extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
32
+ queryParameters: TQuery & HttpHeaders;
33
+ };
34
+ type RequestType<TData extends HttpPayload = EmptyRequestComponent, TPathParameters extends PathParameters | EmptyRequestComponent = EmptyRequestComponent, TQueryParameters extends QueryParameters | EmptyRequestComponent = EmptyRequestComponent, THeader extends HttpHeaders | EmptyRequestComponent = EmptyRequestComponent> = TData | TPathParameters | THeader | TQueryParameters extends EmptyRequestComponent ? RequestWithOptionalHeaders : RequestWithData<TData> & RequestWithPathParameters<TPathParameters> & RequestWithQueryParameters<TQueryParameters> & RequestWithHeaders<THeader>;
35
+ type AnyRequest = RequestType<any, any, any, any>;
36
+
37
+ type Response<TContent extends HttpPayload = HttpPayload, TStatus extends HttpStatus = HttpStatus, TMediaType extends HttpMediaType | null = HttpMediaType> = AxiosResponse<TContent> & {
38
+ status: TStatus;
39
+ mediaType: TMediaType;
40
+ };
41
+ type AnyResponse = Response<any, any, any>;
42
+
43
+ interface OpenAPIOperation<TIgnoredRequest extends AnyRequest = RequestType, IgnoredResponse extends AnyResponse = Response> {
44
+ operationId: string;
45
+ path: string;
46
+ method: HttpMethod;
47
+ }
48
+ type InferredRequestType<TOp> = TOp extends OpenAPIOperation<infer TReq> ? TReq : never;
49
+ type InferredResponseType<TOp> = TOp extends OpenAPIOperation<RequestType, infer TRes> ? TRes : never;
50
+ type ResponseData<TOp, TStatus extends HttpStatus = 200> = Extract<InferredResponseType<TOp>, {
51
+ status: TStatus;
52
+ }>["data"];
53
+ type RequestData<TOp> = TOp extends OpenAPIOperation ? InferredRequestType<TOp> extends {
54
+ data: infer TData;
55
+ } ? TData : never : never;
56
+
57
+ type PartialOnNoRequiredKeysDeep<T> = PartialOnUndefinedDeep<OmitIndexSignature<{
58
+ [TKey in keyof T]: HasRequiredKeys<PartialOnNoRequiredKeysDeep<T[TKey]>> extends true ? T[TKey] : T[TKey] | undefined;
59
+ }>>;
60
+ type NullableOnNoRequiredKeysDeep<T> = HasRequiredKeys<PartialOnNoRequiredKeysDeep<T>> extends true ? PartialOnNoRequiredKeysDeep<T> : PartialOnNoRequiredKeysDeep<T> | null;
61
+
62
+ type UnboxPathParameters<T> = T extends {
63
+ pathParameters: infer TPath;
64
+ } ? Omit<T, "pathParameters"> & TPath : T;
65
+ type RequestObject<TOp extends OpenAPIOperation> = NullableOnNoRequiredKeysDeep<UnboxPathParameters<InferredRequestType<TOp>>>;
66
+ type ResponsePromise<TOp extends OpenAPIOperation> = Promise<InferredResponseType<TOp>>;
67
+ type RequestFunctionWithOptionalRequest<TOp extends OpenAPIOperation> = (request?: RequestObject<TOp>) => ResponsePromise<TOp>;
68
+ type RequestFunctionWithRequiredRequest<TOp extends OpenAPIOperation> = (request: RequestObject<TOp>) => ResponsePromise<TOp>;
69
+ type RequestFunction<TOp extends OpenAPIOperation> = null extends RequestObject<TOp> ? RequestFunctionWithOptionalRequest<TOp> : RequestFunctionWithRequiredRequest<TOp>;
70
+
71
+ export type { AnyResponse as A, HttpPayload as H, InferredRequestType as I, OpenAPIOperation as O, PathParameters as P, QueryParameters as Q, Response as R, RequestFunction as a, RequestObject as b, ResponsePromise as c, RequestType as d, AnyRequest as e, InferredResponseType as f, ResponseData as g, RequestData as h, HttpStatus as i, HttpMediaType as j, HttpMethod as k, HttpHeaders as l };
@@ -0,0 +1,71 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { HasRequiredKeys, PartialOnUndefinedDeep, OmitIndexSignature } from 'type-fest';
3
+
4
+ type HttpPayload = unknown;
5
+ type HttpStatus = number | "default";
6
+ type HttpMediaType = string;
7
+ type SafeHttpMethod = "GET" | "HEAD" | "OPTIONS";
8
+ type UnsafeHttpMethod = "PUT" | "DELETE" | "POST" | "PATCH";
9
+ type HttpMethod = SafeHttpMethod | UnsafeHttpMethod;
10
+ type HeaderValue = string | number | boolean;
11
+ type HttpHeaders = Partial<{
12
+ [TKey: string]: HeaderValue | HeaderValue[];
13
+ }>;
14
+ type PathParameters = Record<string, string | number>;
15
+ type QueryParameters = Record<string, unknown>;
16
+
17
+ type EmptyObject = Record<string, never>;
18
+ type EmptyRequestComponent = EmptyObject | null;
19
+ type RequestWithOptionalHeaders = {
20
+ headers?: HttpHeaders;
21
+ };
22
+ type RequestWithData<TData> = TData extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
23
+ data: TData;
24
+ };
25
+ type RequestWithPathParameters<TPathParameters> = TPathParameters extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
26
+ pathParameters: TPathParameters;
27
+ };
28
+ type RequestWithHeaders<THeaders> = THeaders extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
29
+ headers: THeaders & HttpHeaders;
30
+ };
31
+ type RequestWithQueryParameters<TQuery> = TQuery extends EmptyRequestComponent ? RequestWithOptionalHeaders : {
32
+ queryParameters: TQuery & HttpHeaders;
33
+ };
34
+ type RequestType<TData extends HttpPayload = EmptyRequestComponent, TPathParameters extends PathParameters | EmptyRequestComponent = EmptyRequestComponent, TQueryParameters extends QueryParameters | EmptyRequestComponent = EmptyRequestComponent, THeader extends HttpHeaders | EmptyRequestComponent = EmptyRequestComponent> = TData | TPathParameters | THeader | TQueryParameters extends EmptyRequestComponent ? RequestWithOptionalHeaders : RequestWithData<TData> & RequestWithPathParameters<TPathParameters> & RequestWithQueryParameters<TQueryParameters> & RequestWithHeaders<THeader>;
35
+ type AnyRequest = RequestType<any, any, any, any>;
36
+
37
+ type Response<TContent extends HttpPayload = HttpPayload, TStatus extends HttpStatus = HttpStatus, TMediaType extends HttpMediaType | null = HttpMediaType> = AxiosResponse<TContent> & {
38
+ status: TStatus;
39
+ mediaType: TMediaType;
40
+ };
41
+ type AnyResponse = Response<any, any, any>;
42
+
43
+ interface OpenAPIOperation<TIgnoredRequest extends AnyRequest = RequestType, IgnoredResponse extends AnyResponse = Response> {
44
+ operationId: string;
45
+ path: string;
46
+ method: HttpMethod;
47
+ }
48
+ type InferredRequestType<TOp> = TOp extends OpenAPIOperation<infer TReq> ? TReq : never;
49
+ type InferredResponseType<TOp> = TOp extends OpenAPIOperation<RequestType, infer TRes> ? TRes : never;
50
+ type ResponseData<TOp, TStatus extends HttpStatus = 200> = Extract<InferredResponseType<TOp>, {
51
+ status: TStatus;
52
+ }>["data"];
53
+ type RequestData<TOp> = TOp extends OpenAPIOperation ? InferredRequestType<TOp> extends {
54
+ data: infer TData;
55
+ } ? TData : never : never;
56
+
57
+ type PartialOnNoRequiredKeysDeep<T> = PartialOnUndefinedDeep<OmitIndexSignature<{
58
+ [TKey in keyof T]: HasRequiredKeys<PartialOnNoRequiredKeysDeep<T[TKey]>> extends true ? T[TKey] : T[TKey] | undefined;
59
+ }>>;
60
+ type NullableOnNoRequiredKeysDeep<T> = HasRequiredKeys<PartialOnNoRequiredKeysDeep<T>> extends true ? PartialOnNoRequiredKeysDeep<T> : PartialOnNoRequiredKeysDeep<T> | null;
61
+
62
+ type UnboxPathParameters<T> = T extends {
63
+ pathParameters: infer TPath;
64
+ } ? Omit<T, "pathParameters"> & TPath : T;
65
+ type RequestObject<TOp extends OpenAPIOperation> = NullableOnNoRequiredKeysDeep<UnboxPathParameters<InferredRequestType<TOp>>>;
66
+ type ResponsePromise<TOp extends OpenAPIOperation> = Promise<InferredResponseType<TOp>>;
67
+ type RequestFunctionWithOptionalRequest<TOp extends OpenAPIOperation> = (request?: RequestObject<TOp>) => ResponsePromise<TOp>;
68
+ type RequestFunctionWithRequiredRequest<TOp extends OpenAPIOperation> = (request: RequestObject<TOp>) => ResponsePromise<TOp>;
69
+ type RequestFunction<TOp extends OpenAPIOperation> = null extends RequestObject<TOp> ? RequestFunctionWithOptionalRequest<TOp> : RequestFunctionWithRequiredRequest<TOp>;
70
+
71
+ export type { AnyResponse as A, HttpPayload as H, InferredRequestType as I, OpenAPIOperation as O, PathParameters as P, QueryParameters as Q, Response as R, RequestFunction as a, RequestObject as b, ResponsePromise as c, RequestType as d, AnyRequest as e, InferredResponseType as f, ResponseData as g, RequestData as h, HttpStatus as i, HttpMediaType as j, HttpMethod as k, HttpHeaders as l };
package/package.json CHANGED
@@ -1,76 +1,70 @@
1
1
  {
2
2
  "name": "@mittwald/api-client-commons",
3
- "version": "4.1.2-alpha.4",
3
+ "version": "4.1.3-alpha.1",
4
+ "author": "Mittwald CM Service GmbH & Co. KG <opensource@mittwald.de>",
5
+ "type": "module",
4
6
  "description": "Common types and utilities for mittwald API clients",
5
- "license": "MIT",
6
- "repository": "https://github.com/mittwald/api-client-js.git",
7
- "author": {
8
- "name": "Mittwald CM Service GmbH & Co. KG",
9
- "email": "opensource@mittwald.de"
10
- },
7
+ "keywords": [
8
+ "api",
9
+ "client",
10
+ "mittwald",
11
+ "rest",
12
+ "sdk"
13
+ ],
11
14
  "homepage": "https://developer.mittwald.de",
15
+ "repository": "https://github.com/mittwald/api-client-js.git",
12
16
  "bugs": "https://github.com/mittwald/api-client-js/issues",
13
- "main": "dist/cjs/index.js",
14
- "type": "module",
17
+ "license": "MIT",
15
18
  "exports": {
16
- ".": {
17
- "types": {
18
- "require": "./dist/cjs/index.d.ts",
19
- "default": "./dist/esm/index.d.ts"
20
- },
21
- "default": {
22
- "require": "./dist/cjs/index.js",
23
- "default": "./dist/esm/index.js"
24
- }
25
- },
26
- "./react": {
27
- "types": {
28
- "require": "./dist/cjs/react/index.d.ts",
29
- "default": "./dist/esm/react/index.d.ts"
30
- },
31
- "default": {
32
- "require": "./dist/cjs/react/index.js",
33
- "default": "./dist/esm/react/index.js"
34
- }
35
- }
36
- },
37
- "scripts": {
38
- "test": "node --experimental-vm-modules $(yarn bin jest)"
19
+ ".": "./dist/index.mjs",
20
+ "./react": "./dist/react/index.mjs"
39
21
  },
40
22
  "files": [
41
- "dist/**/*.{js,d.ts}"
42
- ],
43
- "keywords": [
44
- "mittwald",
45
- "api",
46
- "client",
47
- "sdk",
48
- "rest"
23
+ "dist"
49
24
  ],
50
- "peerDependencies": {
51
- "@mittwald/react-use-promise": "^1.3.2"
52
- },
53
- "peerDependenciesMeta": {
54
- "@mittwald/react-use-promise": {
55
- "optional": true
56
- }
25
+ "scripts": {
26
+ "build": "yarn unbuild",
27
+ "format": "prettier --write '**/*.{ts,tsx,yaml,yml,json,md,mdx,js}'",
28
+ "lint": "eslint .",
29
+ "test": "node --experimental-vm-modules $(yarn bin jest)"
57
30
  },
58
31
  "dependencies": {
59
- "@types/parse-path": "^7.0.0",
60
- "axios": "^1.4.0",
32
+ "@types/parse-path": "^7.0.3",
33
+ "axios": "^1.6.2",
61
34
  "parse-path": "^7.0.0",
62
35
  "path-to-regexp": "^6.2.1",
63
- "type-fest": "^3.12.0"
36
+ "type-fest": "^4.8.2"
64
37
  },
65
38
  "devDependencies": {
66
- "@jest/globals": "^29.6.0",
67
- "@mittwald/react-use-promise": "^1.3.2",
68
- "@types/jest": "^29.5.2",
69
- "@yarnpkg/pnpify": "^4.0.0-rc.48",
70
- "jest": "^29.6.1",
39
+ "@jest/globals": "^29.7.0",
40
+ "@mittwald/react-use-promise": "^2.1.0",
41
+ "@types/jest": "^29.5.10",
42
+ "@typescript-eslint/eslint-plugin": "^6.12.0",
43
+ "@typescript-eslint/parser": "^6.12.0",
44
+ "eslint": "^8.54.0",
45
+ "eslint-config-prettier": "^9.0.0",
46
+ "eslint-plugin-json": "^3.1.0",
47
+ "eslint-plugin-prettier": "^5.0.1",
48
+ "jest": "^29.7.0",
49
+ "prettier": "^3.1.0",
50
+ "prettier-plugin-jsdoc": "^1.1.1",
51
+ "prettier-plugin-pkgsort": "^0.2.1",
52
+ "prettier-plugin-sort-json": "^3.1.0",
71
53
  "react": "^18.2.0",
72
54
  "ts-jest": "^29.1.1",
73
- "tsd": "^0.28.1"
55
+ "tsd": "^0.29.0",
56
+ "typescript": "^5.3.2",
57
+ "unbuild": "^2.0.0"
58
+ },
59
+ "peerDependencies": {
60
+ "@mittwald/react-use-promise": "^2.1.0"
61
+ },
62
+ "peerDependenciesMeta": {
63
+ "@mittwald/react-use-promise": {
64
+ "optional": true
65
+ }
74
66
  },
75
- "types": "dist/cjs/index.d.ts"
67
+ "unbuild": {
68
+ "declaration": true
69
+ }
76
70
  }
@@ -1 +0,0 @@
1
- export * from "axios";
package/dist/cjs/axios.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("axios"), exports);
@@ -1,9 +0,0 @@
1
- import { AxiosInstance, CreateAxiosDefaults } from "axios";
2
- import { RequestFunction } from "../types/index.js";
3
- import { OpenAPIOperation } from "../types/index.js";
4
- export declare abstract class ApiClientBase {
5
- axios: AxiosInstance;
6
- constructor(axiosConfig?: AxiosInstance | CreateAxiosDefaults);
7
- protected requestFunctionFactory<TOp extends OpenAPIOperation>(operation: TOp): RequestFunction<TOp>;
8
- }
9
- export default ApiClientBase;