@mittwald/api-client 1.0.0-alpha.12

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.
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/v2.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import MittwaldApiV2Client from "./generated/v2/client.js";
2
+ export declare class MittwaldAPIClient extends MittwaldApiV2Client {
3
+ private readonly apiToken;
4
+ private constructor();
5
+ private setupInterceptors;
6
+ static newUnauthenticated(): MittwaldAPIClient;
7
+ static newWithToken(apiToken: string): MittwaldAPIClient;
8
+ static newWithCredentials(email: string, password: string): Promise<MittwaldAPIClient>;
9
+ }
10
+ export default MittwaldAPIClient;
package/dist/v2.js ADDED
@@ -0,0 +1,41 @@
1
+ import ApiClientError from "@mittwald/api-client-commons/dist/core/ApiClientError.js";
2
+ import MittwaldApiV2Client from "./generated/v2/client.js";
3
+ export class MittwaldAPIClient extends MittwaldApiV2Client {
4
+ apiToken;
5
+ constructor(apiToken) {
6
+ super({
7
+ baseURL: "https://api.mittwald.de/",
8
+ });
9
+ this.apiToken = apiToken;
10
+ this.setupInterceptors();
11
+ }
12
+ setupInterceptors() {
13
+ this.axios.interceptors.request.use((conf) => {
14
+ const token = this.apiToken;
15
+ if (token) {
16
+ conf.headers.set("x-access-token", token);
17
+ }
18
+ return conf;
19
+ });
20
+ }
21
+ static newUnauthenticated() {
22
+ return new MittwaldAPIClient();
23
+ }
24
+ static newWithToken(apiToken) {
25
+ return new MittwaldAPIClient(apiToken);
26
+ }
27
+ static async newWithCredentials(email, password) {
28
+ const client = MittwaldAPIClient.newUnauthenticated();
29
+ const authResult = await client.user.signupApiAuthenticate({
30
+ data: {
31
+ email,
32
+ password,
33
+ },
34
+ });
35
+ if (authResult.status === 200) {
36
+ return new MittwaldAPIClient(authResult.data.token);
37
+ }
38
+ throw ApiClientError.fromResponse("Login failed", authResult);
39
+ }
40
+ }
41
+ export default MittwaldAPIClient;
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@mittwald/api-client",
3
+ "description": "Auto-generated client for the mittwald API",
4
+ "version": "1.0.0-alpha.12",
5
+ "license": "MIT",
6
+ "repository": "https://github.com/mittwald/api-client-js.git",
7
+ "homepage": "https://developer.mittwald.de",
8
+ "bugs": "https://github.com/mittwald/api-client-js/issues",
9
+ "type": "module",
10
+ "author": {
11
+ "name": "Mittwald CM Service GmbH & Co. KG",
12
+ "email": "opensource@mittwald.de"
13
+ },
14
+ "keywords": [
15
+ "mittwald",
16
+ "api",
17
+ "client",
18
+ "sdk",
19
+ "rest"
20
+ ],
21
+ "scripts": {
22
+ "copy:dts": "yarn run -T copyfiles -u 1 src/**/*.d.ts dist",
23
+ "generate:client": "yarn generate:client:v2 && yarn post:generate",
24
+ "generate:client-dev": "yarn generate:client-dev:v2 && yarn post:generate",
25
+ "generate:client-dev:v2": "curl --silent https://api-public.dev.mittwald.systems/openapi | ./transform-openapi.sh | yarn acg generate --name MittwaldAPIV2 - src/generated/v2 --optionalHeader x-access-token",
26
+ "generate:client:v2": "curl --silent https://api.mittwald.de/openapi | ./transform-openapi.sh | yarn acg generate --name MittwaldAPIV2 - src/generated/v2 --optionalHeader x-access-token",
27
+ "post:generate": "yarn run -T compile && yarn copy:dts"
28
+ },
29
+ "files": [
30
+ "dist/**/*.{js,d.ts}"
31
+ ],
32
+ "dependencies": {
33
+ "@mittwald/api-client-commons": "^1.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@mittwald/api-code-generator": "^1.0.0"
37
+ },
38
+ "types": "./dist/index.d.ts"
39
+ }