@mittwald/api-client-commons 2.0.1 → 2.0.3

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 CHANGED
@@ -1 +1,33 @@
1
1
  Common code base used by `@mittwald/api-client-*` package.
2
+
3
+ ## API
4
+
5
+ ### assertStatus
6
+
7
+ The API client does not validate any response status by design, to give you the
8
+ most flexibility while handling also erroneous responses. If you want to assert
9
+ some desired response status, you can use the `assertStatus` function.
10
+
11
+ #### assertStatus(response, expectedStatus)
12
+
13
+ Returns: void
14
+
15
+ This method throws an `ApiClientError` if the given `response` does not match
16
+ the `expectedStatus`.
17
+
18
+ When you are using TypeScript this function also asserts the correct response
19
+ type.
20
+
21
+ ```ts
22
+ const response = await client.project.getProject({
23
+ pathParameters: {
24
+ projectId: "...",
25
+ },
26
+ });
27
+
28
+ assertStatus(response, 200);
29
+
30
+ const project = response.data;
31
+ // Project properties can now be accessed safely
32
+ const name = project.name;
33
+ ```
@@ -0,0 +1,5 @@
1
+ import { Response } from "./Response.js";
2
+ export declare function assertStatus<T extends Response, S extends T["status"]>(response: T, expectedStatus: S): asserts response is T & {
3
+ status: S;
4
+ };
5
+ export default assertStatus;
@@ -0,0 +1,7 @@
1
+ import ApiClientError from "../core/ApiClientError.js";
2
+ export function assertStatus(response, expectedStatus) {
3
+ if (response.status !== expectedStatus) {
4
+ throw ApiClientError.fromResponse(`Unexpected response status (expected ${expectedStatus}, got: ${response.status})`, response);
5
+ }
6
+ }
7
+ export default assertStatus;
@@ -3,4 +3,4 @@ export * from "./RequestFunction.js";
3
3
  export * from "./Response.js";
4
4
  export * from "./OpenAPIOperation.js";
5
5
  export * from "./http.js";
6
- export { Simplify } from "type-fest";
6
+ export * from "./simplify.js";
@@ -3,3 +3,4 @@ export * from "./RequestFunction.js";
3
3
  export * from "./Response.js";
4
4
  export * from "./OpenAPIOperation.js";
5
5
  export * from "./http.js";
6
+ export * from "./simplify.js";
@@ -0,0 +1,3 @@
1
+ export type Simplify<T> = {
2
+ [KeyType in keyof T]: T[KeyType];
3
+ } & {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,34 +1,8 @@
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
2
  Object.defineProperty(exports, "__esModule", { value: true });
29
3
  exports.ApiClientBase = void 0;
30
- const axios_1 = __importStar(require("axios"));
31
- const Request_js_1 = __importDefault(require("./Request.js"));
4
+ const axios_1 = require("axios");
5
+ const Request_js_1 = require("./Request.js");
32
6
  class ApiClientBase {
33
7
  constructor(axiosConfig = axios_1.default) {
34
8
  this.axios =
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Request = void 0;
7
- const OpenAPIPath_js_1 = __importDefault(require("./OpenAPIPath.js"));
4
+ const OpenAPIPath_js_1 = require("./OpenAPIPath.js");
8
5
  class Request {
9
6
  constructor(axiosInstance, operationDescriptor, config) {
10
7
  this.axios = axiosInstance;
@@ -0,0 +1,5 @@
1
+ import { Response } from "./Response.js";
2
+ export declare function assertStatus<T extends Response, S extends T["status"]>(response: T, expectedStatus: S): asserts response is T & {
3
+ status: S;
4
+ };
5
+ export default assertStatus;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertStatus = void 0;
4
+ const ApiClientError_js_1 = require("../core/ApiClientError.js");
5
+ function assertStatus(response, expectedStatus) {
6
+ if (response.status !== expectedStatus) {
7
+ throw ApiClientError_js_1.default.fromResponse(`Unexpected response status (expected ${expectedStatus}, got: ${response.status})`, response);
8
+ }
9
+ }
10
+ exports.assertStatus = assertStatus;
11
+ exports.default = assertStatus;
@@ -3,4 +3,4 @@ export * from "./RequestFunction.js";
3
3
  export * from "./Response.js";
4
4
  export * from "./OpenAPIOperation.js";
5
5
  export * from "./http.js";
6
- export { Simplify } from "type-fest";
6
+ export * from "./simplify.js";
@@ -19,3 +19,4 @@ __exportStar(require("./RequestFunction.js"), exports);
19
19
  __exportStar(require("./Response.js"), exports);
20
20
  __exportStar(require("./OpenAPIOperation.js"), exports);
21
21
  __exportStar(require("./http.js"), exports);
22
+ __exportStar(require("./simplify.js"), exports);
@@ -0,0 +1,3 @@
1
+ export type Simplify<T> = {
2
+ [KeyType in keyof T]: T[KeyType];
3
+ } & {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/api-client-commons",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Common types and utilities for mittwald API clients",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/mittwald/api-client-js.git",
@@ -13,16 +13,34 @@
13
13
  "type": "module",
14
14
  "exports": {
15
15
  ".": {
16
- "import": "./dist/core/index.js",
17
- "default": "./dist-cjs/core/index.js"
16
+ "types": {
17
+ "require": "./dist-cjs/core/index.d.ts",
18
+ "default": "./dist/core/index.d.ts"
19
+ },
20
+ "default": {
21
+ "require": "./dist-cjs/core/index.js",
22
+ "default": "./dist/core/index.js"
23
+ }
18
24
  },
19
25
  "./axios": {
20
- "import": "./dist/axios.js",
21
- "default": "./dist-cjs/axios.js"
26
+ "types": {
27
+ "require": "./dist-cjs/axios.d.ts",
28
+ "default": "./dist/axios.d.ts"
29
+ },
30
+ "default": {
31
+ "require": "./dist-cjs/axios.js",
32
+ "default": "./dist/axios.js"
33
+ }
22
34
  },
23
35
  "./types": {
24
- "import": "./dist/types/index.js",
25
- "default": "./dist-cjs/types/index.js"
36
+ "types": {
37
+ "require": "./dist-cjs/types/index.d.ts",
38
+ "default": "./dist/types/index.d.ts"
39
+ },
40
+ "default": {
41
+ "require": "./dist-cjs/types/index.js",
42
+ "default": "./dist/types/index.js"
43
+ }
26
44
  }
27
45
  },
28
46
  "scripts": {
@@ -44,10 +62,10 @@
44
62
  "axios": "^1.4.0",
45
63
  "parse-path": "^7.0.0",
46
64
  "path-to-regexp": "^6.2.1",
47
- "type-fest": "^3.10.0"
65
+ "type-fest": "^3.12.0"
48
66
  },
49
67
  "devDependencies": {
50
- "@yarnpkg/pnpify": "^4.0.0-rc.43",
68
+ "@yarnpkg/pnpify": "^4.0.0-rc.48",
51
69
  "tsd": "^0.28.1"
52
70
  },
53
71
  "types": "./dist/index.d.ts"