@mittwald/api-models 0.0.0-development-04b7288-20240610 → 0.0.0-development-74e1fd1-20240611
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/dist/esm/app/AppInstallation/AppInstallation.js +43 -0
- package/dist/esm/app/AppInstallation/behaviors/api.js +21 -0
- package/dist/esm/app/AppInstallation/behaviors/index.js +2 -0
- package/dist/esm/app/AppInstallation/behaviors/types.js +1 -0
- package/dist/esm/app/AppInstallation/index.js +2 -0
- package/dist/esm/app/AppInstallation/types.js +1 -0
- package/dist/esm/app/index.js +1 -0
- package/dist/esm/base/DataModel.js +7 -0
- package/dist/esm/base/ReferenceModel.js +9 -0
- package/dist/esm/base/assertObjectFound.js +9 -0
- package/dist/esm/base/index.js +1 -0
- package/dist/esm/base/types.js +1 -0
- package/dist/esm/config/behaviors/api.js +40 -0
- package/dist/esm/config/behaviors/index.js +1 -0
- package/dist/esm/config/config.js +9 -0
- package/dist/esm/config/index.js +1 -0
- package/dist/esm/customer/Customer/Customer.js +43 -0
- package/dist/esm/customer/Customer/behaviors/api.js +20 -0
- package/dist/esm/customer/Customer/behaviors/index.js +2 -0
- package/dist/esm/customer/Customer/behaviors/types.js +1 -0
- package/dist/esm/customer/Customer/index.js +2 -0
- package/dist/esm/customer/Customer/types.js +1 -0
- package/dist/esm/customer/index.js +1 -0
- package/dist/esm/domain/Ingress/Ingress.js +56 -0
- package/dist/esm/domain/Ingress/behaviors/api.js +23 -0
- package/dist/esm/domain/Ingress/behaviors/index.js +2 -0
- package/dist/esm/domain/Ingress/behaviors/types.js +1 -0
- package/dist/esm/domain/Ingress/index.js +2 -0
- package/dist/esm/domain/Ingress/types.js +1 -0
- package/dist/esm/domain/IngressPath/IngressPath.js +15 -0
- package/dist/esm/domain/IngressPath/IngressPath.test.js +16 -0
- package/dist/esm/domain/IngressPath/index.js +2 -0
- package/dist/esm/domain/IngressPath/types.js +1 -0
- package/dist/esm/domain/IngressTarget/IngressTarget.js +51 -0
- package/dist/esm/domain/IngressTarget/IngressTarget.test-types.js +13 -0
- package/dist/esm/domain/IngressTarget/index.js +2 -0
- package/dist/esm/domain/IngressTarget/types.js +1 -0
- package/dist/esm/domain/index.js +1 -0
- package/dist/esm/errors/ObjectNotFoundError.js +7 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/lib/deepFreeze.js +4 -0
- package/dist/esm/lib/provideReact.js +5 -0
- package/dist/esm/lib/types.js +1 -0
- package/dist/esm/project/Project/Project.js +69 -0
- package/dist/esm/project/Project/behaviors/api.js +51 -0
- package/dist/esm/project/Project/behaviors/inMem.js +23 -0
- package/dist/esm/project/Project/behaviors/index.js +3 -0
- package/dist/esm/project/Project/behaviors/types.js +1 -0
- package/dist/esm/project/Project/index.js +2 -0
- package/dist/esm/project/Project/types.js +1 -0
- package/dist/esm/project/index.js +1 -0
- package/dist/esm/react/MittwaldApiModelProvider.js +12 -0
- package/dist/esm/react/index.js +3 -0
- package/dist/esm/react/reactUsePromise.js +17 -0
- package/dist/esm/react.js +1 -0
- package/dist/esm/server/Server/Server.js +47 -0
- package/dist/esm/server/Server/behaviors/api.js +19 -0
- package/dist/esm/server/Server/behaviors/index.js +2 -0
- package/dist/esm/server/Server/behaviors/types.js +1 -0
- package/dist/esm/server/Server/index.js +1 -0
- package/dist/esm/server/Server/types.js +1 -0
- package/dist/esm/server/index.js +1 -0
- package/dist/types/app/AppInstallation/AppInstallation.d.ts +109 -0
- package/dist/types/app/AppInstallation/behaviors/api.d.ts +3 -0
- package/dist/types/app/AppInstallation/behaviors/index.d.ts +2 -0
- package/dist/types/app/AppInstallation/behaviors/types.d.ts +5 -0
- package/dist/types/app/AppInstallation/index.d.ts +2 -0
- package/dist/types/app/AppInstallation/types.d.ts +4 -0
- package/dist/types/app/index.d.ts +1 -0
- package/dist/types/base/DataModel.d.ts +5 -0
- package/dist/types/base/ReferenceModel.d.ts +5 -0
- package/dist/types/base/assertObjectFound.d.ts +3 -0
- package/dist/types/base/index.d.ts +1 -0
- package/dist/types/base/types.d.ts +2 -0
- package/dist/types/config/behaviors/api.d.ts +12 -0
- package/dist/types/config/behaviors/index.d.ts +1 -0
- package/dist/types/config/config.d.ts +16 -0
- package/dist/types/config/index.d.ts +1 -0
- package/dist/types/customer/Customer/Customer.d.ts +113 -0
- package/dist/types/customer/Customer/behaviors/api.d.ts +3 -0
- package/dist/types/customer/Customer/behaviors/index.d.ts +2 -0
- package/dist/types/customer/Customer/behaviors/types.d.ts +5 -0
- package/dist/types/customer/Customer/index.d.ts +2 -0
- package/dist/types/customer/Customer/types.d.ts +4 -0
- package/dist/types/customer/index.d.ts +1 -0
- package/dist/types/domain/Ingress/Ingress.d.ts +102 -0
- package/dist/types/domain/Ingress/behaviors/api.d.ts +3 -0
- package/dist/types/domain/Ingress/behaviors/index.d.ts +2 -0
- package/dist/types/domain/Ingress/behaviors/types.d.ts +5 -0
- package/dist/types/domain/Ingress/index.d.ts +2 -0
- package/dist/types/domain/Ingress/types.d.ts +6 -0
- package/dist/types/domain/IngressPath/IngressPath.d.ts +11 -0
- package/dist/types/domain/IngressPath/IngressPath.test.d.ts +1 -0
- package/dist/types/domain/IngressPath/index.d.ts +2 -0
- package/dist/types/domain/IngressPath/types.d.ts +2 -0
- package/dist/types/domain/IngressTarget/IngressTarget.d.ts +29 -0
- package/dist/types/domain/IngressTarget/IngressTarget.test-types.d.ts +1 -0
- package/dist/types/domain/IngressTarget/index.d.ts +2 -0
- package/dist/types/domain/IngressTarget/types.d.ts +7 -0
- package/dist/types/domain/index.d.ts +1 -0
- package/dist/types/errors/ObjectNotFoundError.d.ts +3 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/lib/deepFreeze.d.ts +5 -0
- package/dist/types/lib/provideReact.d.ts +11 -0
- package/dist/types/lib/types.d.ts +2 -0
- package/dist/types/project/Project/Project.d.ts +246 -0
- package/dist/types/project/Project/behaviors/api.d.ts +3 -0
- package/dist/types/project/Project/behaviors/inMem.d.ts +3 -0
- package/dist/types/project/Project/behaviors/index.d.ts +3 -0
- package/dist/types/project/Project/behaviors/types.d.ts +11 -0
- package/dist/types/project/Project/index.d.ts +2 -0
- package/dist/types/project/Project/types.d.ts +4 -0
- package/dist/types/project/index.d.ts +1 -0
- package/dist/types/react/MittwaldApiModelProvider.d.ts +2 -0
- package/dist/types/react/index.d.ts +4 -0
- package/dist/types/react/reactUsePromise.d.ts +1 -0
- package/dist/types/react.d.ts +1 -0
- package/dist/types/server/Server/Server.d.ts +72 -0
- package/dist/types/server/Server/behaviors/api.d.ts +3 -0
- package/dist/types/server/Server/behaviors/index.d.ts +2 -0
- package/dist/types/server/Server/behaviors/types.d.ts +5 -0
- package/dist/types/server/Server/index.d.ts +1 -0
- package/dist/types/server/Server/types.d.ts +4 -0
- package/dist/types/server/index.d.ts +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { config } from "../../config/config.js";
|
|
2
|
+
import { classes } from "polytype";
|
|
3
|
+
import { DataModel } from "../../base/DataModel.js";
|
|
4
|
+
import assertObjectFound from "../../base/assertObjectFound.js";
|
|
5
|
+
import { ReferenceModel } from "../../base/ReferenceModel.js";
|
|
6
|
+
import { provideReact } from "../../lib/provideReact.js";
|
|
7
|
+
export class AppInstallation extends ReferenceModel {
|
|
8
|
+
static find = provideReact(async (id) => {
|
|
9
|
+
const data = await config.behaviors.appInstallation.find(id);
|
|
10
|
+
if (data !== undefined) {
|
|
11
|
+
return new AppInstallationDetailed(data);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
static get = provideReact(async (id) => {
|
|
15
|
+
const appInstallation = await this.find(id);
|
|
16
|
+
assertObjectFound(appInstallation, this, id);
|
|
17
|
+
return appInstallation;
|
|
18
|
+
});
|
|
19
|
+
static ofId(id) {
|
|
20
|
+
return new AppInstallation(id);
|
|
21
|
+
}
|
|
22
|
+
static list = provideReact(async (projectId, query = {}) => {
|
|
23
|
+
const data = await config.behaviors.appInstallation.list(projectId, query);
|
|
24
|
+
return data.map((d) => new AppInstallationListItem(d));
|
|
25
|
+
});
|
|
26
|
+
getDetailed = provideReact(() => AppInstallation.get(this.id));
|
|
27
|
+
}
|
|
28
|
+
// Common class for future extension
|
|
29
|
+
class AppInstallationCommon extends classes((DataModel), AppInstallation) {
|
|
30
|
+
constructor(data) {
|
|
31
|
+
super([data], [data.id]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class AppInstallationDetailed extends classes(AppInstallationCommon, (DataModel)) {
|
|
35
|
+
constructor(data) {
|
|
36
|
+
super([data], [data]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export class AppInstallationListItem extends classes(AppInstallationCommon, (DataModel)) {
|
|
40
|
+
constructor(data) {
|
|
41
|
+
super([data], [data]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { assertStatus } from "@mittwald/api-client";
|
|
2
|
+
import { assertOneOfStatus } from "@mittwald/api-client";
|
|
3
|
+
export const apiAppInstallationBehaviors = (client) => ({
|
|
4
|
+
find: async (id) => {
|
|
5
|
+
const response = await client.app.getAppinstallation({
|
|
6
|
+
appInstallationId: id,
|
|
7
|
+
});
|
|
8
|
+
if (response.status === 200) {
|
|
9
|
+
return response.data;
|
|
10
|
+
}
|
|
11
|
+
assertOneOfStatus(response, [404]);
|
|
12
|
+
},
|
|
13
|
+
list: async (projectId, query) => {
|
|
14
|
+
const response = await client.app.listAppinstallations({
|
|
15
|
+
queryParameters: query,
|
|
16
|
+
projectId,
|
|
17
|
+
});
|
|
18
|
+
assertStatus(response, 200);
|
|
19
|
+
return response.data;
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./AppInstallation/index.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ObjectNotFoundError from "../errors/ObjectNotFoundError.js";
|
|
2
|
+
export default function assertObjectFound(obj, theClass, refIdOrObject) {
|
|
3
|
+
if (obj === undefined) {
|
|
4
|
+
const refName = typeof refIdOrObject === "string"
|
|
5
|
+
? refIdOrObject
|
|
6
|
+
: refIdOrObject.toString();
|
|
7
|
+
throw new ObjectNotFoundError(theClass.name, refName);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MittwaldAPIV2Client } from "@mittwald/api-client";
|
|
2
|
+
import { config } from "../config.js";
|
|
3
|
+
import { apiProjectBehaviors } from "../../project/Project/behaviors/index.js";
|
|
4
|
+
import { apiServerBehaviors } from "../../server/Server/behaviors/index.js";
|
|
5
|
+
import { apiCustomerBehaviors } from "../../customer/Customer/behaviors/index.js";
|
|
6
|
+
import { apiIngressBehaviors } from "../../domain/Ingress/behaviors/index.js";
|
|
7
|
+
import { apiAppInstallationBehaviors } from "../../app/AppInstallation/behaviors/index.js";
|
|
8
|
+
class ApiSetupState {
|
|
9
|
+
_client;
|
|
10
|
+
setupWithClient(client) {
|
|
11
|
+
if (this._client !== undefined) {
|
|
12
|
+
throw new Error("API already setup. If you want to operate on the API client use api.client.");
|
|
13
|
+
}
|
|
14
|
+
this._client = client;
|
|
15
|
+
config.behaviors.project = apiProjectBehaviors(client);
|
|
16
|
+
config.behaviors.server = apiServerBehaviors(client);
|
|
17
|
+
config.behaviors.customer = apiCustomerBehaviors(client);
|
|
18
|
+
config.behaviors.ingress = apiIngressBehaviors(client);
|
|
19
|
+
config.behaviors.appInstallation = apiAppInstallationBehaviors(client);
|
|
20
|
+
}
|
|
21
|
+
setupWithApiToken(apiToken) {
|
|
22
|
+
return this.setupWithClient(MittwaldAPIV2Client.newWithToken(apiToken));
|
|
23
|
+
}
|
|
24
|
+
setupUnauthenticated() {
|
|
25
|
+
return this.setupWithClient(MittwaldAPIV2Client.newUnauthenticated());
|
|
26
|
+
}
|
|
27
|
+
get client() {
|
|
28
|
+
if (!this._client) {
|
|
29
|
+
throw new Error("Could not get client. Behavior not initialized.");
|
|
30
|
+
}
|
|
31
|
+
return this._client;
|
|
32
|
+
}
|
|
33
|
+
get defaults() {
|
|
34
|
+
return this.client.axios.defaults;
|
|
35
|
+
}
|
|
36
|
+
get interceptors() {
|
|
37
|
+
return this.client.axios.interceptors;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export const api = new ApiSetupState();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./api.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./behaviors/index.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { config } from "../../config/config.js";
|
|
2
|
+
import { classes } from "polytype";
|
|
3
|
+
import { DataModel } from "../../base/DataModel.js";
|
|
4
|
+
import assertObjectFound from "../../base/assertObjectFound.js";
|
|
5
|
+
import { ReferenceModel } from "../../base/ReferenceModel.js";
|
|
6
|
+
import { provideReact } from "../../lib/provideReact.js";
|
|
7
|
+
export class Customer extends ReferenceModel {
|
|
8
|
+
static ofId(id) {
|
|
9
|
+
return new Customer(id);
|
|
10
|
+
}
|
|
11
|
+
static find = provideReact(async (id) => {
|
|
12
|
+
const data = await config.behaviors.customer.find(id);
|
|
13
|
+
if (data !== undefined) {
|
|
14
|
+
return new CustomerDetailed(data);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
static list = provideReact(async (query = {}) => {
|
|
18
|
+
const data = await config.behaviors.customer.list(query);
|
|
19
|
+
return Object.freeze(data.map((d) => new CustomerListItem(d)));
|
|
20
|
+
});
|
|
21
|
+
static get = provideReact(async (id) => {
|
|
22
|
+
const customer = await this.find(id);
|
|
23
|
+
assertObjectFound(customer, this, id);
|
|
24
|
+
return customer;
|
|
25
|
+
});
|
|
26
|
+
getDetailed = provideReact(() => Customer.get(this.id));
|
|
27
|
+
}
|
|
28
|
+
// Common class for future extension
|
|
29
|
+
class CustomerCommon extends classes((DataModel), Customer) {
|
|
30
|
+
constructor(data) {
|
|
31
|
+
super([data], [data.customerId]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class CustomerDetailed extends classes(CustomerCommon, (DataModel)) {
|
|
35
|
+
constructor(data) {
|
|
36
|
+
super([data], [data]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export class CustomerListItem extends classes(CustomerCommon, (DataModel)) {
|
|
40
|
+
constructor(data) {
|
|
41
|
+
super([data], [data]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { assertStatus } from "@mittwald/api-client";
|
|
2
|
+
import { assertOneOfStatus } from "@mittwald/api-client";
|
|
3
|
+
export const apiCustomerBehaviors = (client) => ({
|
|
4
|
+
find: async (id) => {
|
|
5
|
+
const response = await client.customer.getCustomer({
|
|
6
|
+
customerId: id,
|
|
7
|
+
});
|
|
8
|
+
if (response.status === 200) {
|
|
9
|
+
return response.data;
|
|
10
|
+
}
|
|
11
|
+
assertOneOfStatus(response, [404]);
|
|
12
|
+
},
|
|
13
|
+
list: async (query) => {
|
|
14
|
+
const response = await client.customer.listCustomers({
|
|
15
|
+
queryParameters: query,
|
|
16
|
+
});
|
|
17
|
+
assertStatus(response, 200);
|
|
18
|
+
return response.data;
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Customer/index.js";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { config } from "../../config/config.js";
|
|
2
|
+
import { classes } from "polytype";
|
|
3
|
+
import { DataModel } from "../../base/DataModel.js";
|
|
4
|
+
import assertObjectFound from "../../base/assertObjectFound.js";
|
|
5
|
+
import { ReferenceModel } from "../../base/ReferenceModel.js";
|
|
6
|
+
import { provideReact } from "../../lib/provideReact.js";
|
|
7
|
+
import { IngressPath } from "../IngressPath/IngressPath.js";
|
|
8
|
+
export class Ingress extends ReferenceModel {
|
|
9
|
+
static ofId(id) {
|
|
10
|
+
return new Ingress(id);
|
|
11
|
+
}
|
|
12
|
+
static ofHostname(hostname) {
|
|
13
|
+
return Ingress.ofId(hostname);
|
|
14
|
+
}
|
|
15
|
+
static list = provideReact(async (query = {}) => {
|
|
16
|
+
const data = await config.behaviors.ingress.list(query);
|
|
17
|
+
return data.map((d) => new IngressListItem(d));
|
|
18
|
+
});
|
|
19
|
+
static find = provideReact(async (id) => {
|
|
20
|
+
const data = await config.behaviors.ingress.find(id);
|
|
21
|
+
if (data !== undefined) {
|
|
22
|
+
return new IngressDetailed(data);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
static get = provideReact(async (id) => {
|
|
26
|
+
const ingress = await this.find(id);
|
|
27
|
+
assertObjectFound(ingress, this, id);
|
|
28
|
+
return ingress;
|
|
29
|
+
});
|
|
30
|
+
getDetailed = provideReact(() => Ingress.get(this.id));
|
|
31
|
+
}
|
|
32
|
+
export class IngressCommon extends classes((DataModel), Ingress) {
|
|
33
|
+
baseUrl;
|
|
34
|
+
paths;
|
|
35
|
+
defaultPath;
|
|
36
|
+
constructor(data) {
|
|
37
|
+
super([data], [data.id]);
|
|
38
|
+
this.baseUrl = `https://${data.hostname}`;
|
|
39
|
+
this.paths = Object.freeze(data.paths.map((p) => new IngressPath(this, p)));
|
|
40
|
+
const defaultPath = this.paths.find((p) => p.path === "/");
|
|
41
|
+
if (defaultPath === undefined) {
|
|
42
|
+
throw new Error(`Ingress ${this.describe()} has no default path.`);
|
|
43
|
+
}
|
|
44
|
+
this.defaultPath = defaultPath;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export class IngressDetailed extends classes(IngressCommon, (DataModel)) {
|
|
48
|
+
constructor(data) {
|
|
49
|
+
super([data], [data]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class IngressListItem extends classes(IngressCommon, (DataModel)) {
|
|
53
|
+
constructor(data) {
|
|
54
|
+
super([data], [data]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { assertStatus } from "@mittwald/api-client";
|
|
2
|
+
import { assertOneOfStatus } from "@mittwald/api-client";
|
|
3
|
+
export const apiIngressBehaviors = (client) => ({
|
|
4
|
+
find: async (id) => {
|
|
5
|
+
const response = await client.domain.ingressGetIngress({
|
|
6
|
+
ingressId: id,
|
|
7
|
+
});
|
|
8
|
+
if (response.status === 200) {
|
|
9
|
+
return response.data;
|
|
10
|
+
}
|
|
11
|
+
assertOneOfStatus(response, [404]);
|
|
12
|
+
},
|
|
13
|
+
list: async (query = {}) => {
|
|
14
|
+
const { projectId } = query;
|
|
15
|
+
const response = await client.domain.ingressListIngresses({
|
|
16
|
+
queryParameters: {
|
|
17
|
+
projectId,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
assertStatus(response, 200);
|
|
21
|
+
return response.data;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DataModel } from "../../base/DataModel.js";
|
|
2
|
+
import { ingressTargetFactory, } from "../IngressTarget/IngressTarget.js";
|
|
3
|
+
export class IngressPath extends DataModel {
|
|
4
|
+
ingress;
|
|
5
|
+
path;
|
|
6
|
+
url;
|
|
7
|
+
target;
|
|
8
|
+
constructor(ingress, data) {
|
|
9
|
+
super(data);
|
|
10
|
+
this.ingress = ingress;
|
|
11
|
+
this.path = data.path;
|
|
12
|
+
this.url = new URL(data.path, ingress.baseUrl);
|
|
13
|
+
this.target = ingressTargetFactory(this, data.target);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IngressPath } from "./IngressPath.js";
|
|
2
|
+
import { IngressDetailed } from "../Ingress/index.js";
|
|
3
|
+
const ingressData = {
|
|
4
|
+
id: "abc",
|
|
5
|
+
paths: [],
|
|
6
|
+
};
|
|
7
|
+
const corruptIngressTargetData = {};
|
|
8
|
+
const ingressPathData = {
|
|
9
|
+
path: "/",
|
|
10
|
+
target: corruptIngressTargetData,
|
|
11
|
+
};
|
|
12
|
+
test("Creating IngressPath with corrupt IngressTarget throws error", () => {
|
|
13
|
+
expect(() => {
|
|
14
|
+
new IngressPath(new IngressDetailed(ingressData), ingressPathData);
|
|
15
|
+
}).toThrowError("Ingress IngressDetailed@abc has no default path.");
|
|
16
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { DataModel } from "../../base/DataModel.js";
|
|
2
|
+
import { AppInstallation } from "../../app/AppInstallation/index.js";
|
|
3
|
+
class IngressTargetBase extends DataModel {
|
|
4
|
+
path;
|
|
5
|
+
constructor(path, data) {
|
|
6
|
+
super(data);
|
|
7
|
+
this.path = path;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class IngressRedirectTarget extends IngressTargetBase {
|
|
11
|
+
type = "redirect";
|
|
12
|
+
url;
|
|
13
|
+
constructor(path, data) {
|
|
14
|
+
super(path, data);
|
|
15
|
+
this.url = new URL(data.url);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class IngressDirectoryTarget extends IngressTargetBase {
|
|
19
|
+
type = "directory";
|
|
20
|
+
directory;
|
|
21
|
+
constructor(path, data) {
|
|
22
|
+
super(path, data);
|
|
23
|
+
this.directory = data.directory;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class IngressAppInstallationTarget extends IngressTargetBase {
|
|
27
|
+
type = "appInstallation";
|
|
28
|
+
appInstallation;
|
|
29
|
+
constructor(path, data) {
|
|
30
|
+
super(path, data);
|
|
31
|
+
this.appInstallation = AppInstallation.ofId(data.installationId);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class IngressUndefinedTarget extends IngressTargetBase {
|
|
35
|
+
type = "undefined";
|
|
36
|
+
}
|
|
37
|
+
export const ingressTargetFactory = (path, data) => {
|
|
38
|
+
if ("directory" in data) {
|
|
39
|
+
return new IngressDirectoryTarget(path, data);
|
|
40
|
+
}
|
|
41
|
+
if ("url" in data) {
|
|
42
|
+
return new IngressRedirectTarget(path, data);
|
|
43
|
+
}
|
|
44
|
+
if ("installationId" in data) {
|
|
45
|
+
return new IngressAppInstallationTarget(path, data);
|
|
46
|
+
}
|
|
47
|
+
if ("useDefaultPage" in data) {
|
|
48
|
+
return new IngressUndefinedTarget(path, data);
|
|
49
|
+
}
|
|
50
|
+
throw new Error("Ingress target type is not supported.");
|
|
51
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const target = {};
|
|
2
|
+
// @ts-expect-error use type-guard first
|
|
3
|
+
void target.url;
|
|
4
|
+
if (target.type === "redirect") {
|
|
5
|
+
void target.url;
|
|
6
|
+
}
|
|
7
|
+
if (target.type === "directory") {
|
|
8
|
+
void target.directory;
|
|
9
|
+
}
|
|
10
|
+
if (target.type === "appInstallation") {
|
|
11
|
+
void target.appInstallation.id;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Ingress/index.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { MittwaldAPIV2Client } from "@mittwald/api-client";
|
|
2
|
+
export * from "./config/index.js";
|
|
3
|
+
export * from "./project/index.js";
|
|
4
|
+
export * from "./server/index.js";
|
|
5
|
+
export * from "./domain/index.js";
|
|
6
|
+
export * from "./customer/index.js";
|
|
7
|
+
export * from "./base/index.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { reactUsePromise } from "../react/reactUsePromise.js";
|
|
2
|
+
export const provideReact = (loader) => Object.assign(loader, {
|
|
3
|
+
asResource: (...params) => reactUsePromise.getAsyncResource(loader, params),
|
|
4
|
+
use: (...params) => reactUsePromise.getAsyncResource(loader, params).use(),
|
|
5
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { config } from "../../config/config.js";
|
|
2
|
+
import { classes } from "polytype";
|
|
3
|
+
import { DataModel } from "../../base/DataModel.js";
|
|
4
|
+
import assertObjectFound from "../../base/assertObjectFound.js";
|
|
5
|
+
import { Server } from "../../server/index.js";
|
|
6
|
+
import { provideReact, } from "../../lib/provideReact.js";
|
|
7
|
+
import { Customer } from "../../customer/Customer/Customer.js";
|
|
8
|
+
import { ReferenceModel } from "../../base/ReferenceModel.js";
|
|
9
|
+
import { Ingress, IngressListItem } from "../../domain/index.js";
|
|
10
|
+
export class Project extends ReferenceModel {
|
|
11
|
+
static ofId(id) {
|
|
12
|
+
return new Project(id);
|
|
13
|
+
}
|
|
14
|
+
static find = provideReact(async (id) => {
|
|
15
|
+
const data = await config.behaviors.project.find(id);
|
|
16
|
+
if (data !== undefined) {
|
|
17
|
+
return new ProjectDetailed(data);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
static get = provideReact(async (id) => {
|
|
21
|
+
const project = await this.find(id);
|
|
22
|
+
assertObjectFound(project, this, id);
|
|
23
|
+
return project;
|
|
24
|
+
});
|
|
25
|
+
static list = provideReact(async (query = {}) => {
|
|
26
|
+
const data = await config.behaviors.project.list(query);
|
|
27
|
+
return Object.freeze(data.map((d) => new ProjectListItem(d)));
|
|
28
|
+
});
|
|
29
|
+
static async create(serverId, description) {
|
|
30
|
+
const { id } = await config.behaviors.project.create(serverId, description);
|
|
31
|
+
return new Project(id);
|
|
32
|
+
}
|
|
33
|
+
getDetailed = provideReact(() => Project.get(this.id));
|
|
34
|
+
listIngresses = provideReact(() => Ingress.list({ projectId: this.id }));
|
|
35
|
+
getDefaultIngress = provideReact(async () => {
|
|
36
|
+
const ingresses = await Project.ofId(this.id).listIngresses();
|
|
37
|
+
const defaultIngress = ingresses.find((i) => i.data.isDefault);
|
|
38
|
+
assertObjectFound(defaultIngress, IngressListItem, this);
|
|
39
|
+
return defaultIngress;
|
|
40
|
+
});
|
|
41
|
+
async updateDescription(description) {
|
|
42
|
+
await config.behaviors.project.updateDescription(this.id, description);
|
|
43
|
+
}
|
|
44
|
+
async leave() {
|
|
45
|
+
await config.behaviors.project.leave(this.id);
|
|
46
|
+
}
|
|
47
|
+
async delete() {
|
|
48
|
+
await config.behaviors.project.delete(this.id);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
class ProjectCommon extends classes((DataModel), Project) {
|
|
52
|
+
server;
|
|
53
|
+
customer;
|
|
54
|
+
constructor(data) {
|
|
55
|
+
super([data], [data.id]);
|
|
56
|
+
this.server = data.serverId ? Server.ofId(data.serverId) : undefined;
|
|
57
|
+
this.customer = Customer.ofId(data.customerId);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export class ProjectDetailed extends classes(ProjectCommon, (DataModel)) {
|
|
61
|
+
constructor(data) {
|
|
62
|
+
super([data], [data]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export class ProjectListItem extends classes(ProjectCommon, (DataModel)) {
|
|
66
|
+
constructor(data) {
|
|
67
|
+
super([data], [data]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { assertStatus } from "@mittwald/api-client";
|
|
2
|
+
import { assertOneOfStatus } from "@mittwald/api-client";
|
|
3
|
+
export const apiProjectBehaviors = (client) => ({
|
|
4
|
+
find: async (id) => {
|
|
5
|
+
const response = await client.project.getProject({
|
|
6
|
+
projectId: id,
|
|
7
|
+
});
|
|
8
|
+
if (response.status === 200) {
|
|
9
|
+
return response.data;
|
|
10
|
+
}
|
|
11
|
+
assertOneOfStatus(response, [403]);
|
|
12
|
+
},
|
|
13
|
+
list: async (query) => {
|
|
14
|
+
const response = await client.project.listProjects({
|
|
15
|
+
queryParameters: query,
|
|
16
|
+
});
|
|
17
|
+
assertStatus(response, 200);
|
|
18
|
+
return response.data;
|
|
19
|
+
},
|
|
20
|
+
create: async (serverId, description) => {
|
|
21
|
+
const response = await client.project.createProject({
|
|
22
|
+
serverId,
|
|
23
|
+
data: {
|
|
24
|
+
description,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
assertStatus(response, 201);
|
|
28
|
+
return response.data;
|
|
29
|
+
},
|
|
30
|
+
leave: async (id) => {
|
|
31
|
+
const response = await client.project.leaveProject({
|
|
32
|
+
projectId: id,
|
|
33
|
+
});
|
|
34
|
+
assertStatus(response, 204);
|
|
35
|
+
},
|
|
36
|
+
delete: async (id) => {
|
|
37
|
+
const response = await client.project.deleteProject({
|
|
38
|
+
projectId: id,
|
|
39
|
+
});
|
|
40
|
+
assertStatus(response, 204);
|
|
41
|
+
},
|
|
42
|
+
updateDescription: async (id, description) => {
|
|
43
|
+
const response = await client.project.updateProjectDescription({
|
|
44
|
+
projectId: id,
|
|
45
|
+
data: {
|
|
46
|
+
description,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
assertStatus(response, 204);
|
|
50
|
+
},
|
|
51
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const inMemProjectBehaviors = (store) => ({
|
|
2
|
+
find: async (id) => store.get(id),
|
|
3
|
+
list: async () => {
|
|
4
|
+
return Array.from(store.values()).map((detailedProject) => ({
|
|
5
|
+
...detailedProject,
|
|
6
|
+
customerMeta: {
|
|
7
|
+
id: detailedProject.customerId,
|
|
8
|
+
},
|
|
9
|
+
}));
|
|
10
|
+
},
|
|
11
|
+
create: async () => {
|
|
12
|
+
throw new Error("Not implemented");
|
|
13
|
+
},
|
|
14
|
+
leave: async () => {
|
|
15
|
+
throw new Error("Not implemented");
|
|
16
|
+
},
|
|
17
|
+
delete: async () => {
|
|
18
|
+
throw new Error("Not implemented");
|
|
19
|
+
},
|
|
20
|
+
updateDescription: async () => {
|
|
21
|
+
throw new Error("Not implemented");
|
|
22
|
+
},
|
|
23
|
+
});
|