@mittwald/api-models 4.242.1 → 4.242.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.
Files changed (179) hide show
  1. package/package.json +3 -3
  2. package/dist/esm/app/AppInstallation/AppInstallation.js +0 -89
  3. package/dist/esm/app/AppInstallation/behaviors/api.js +0 -24
  4. package/dist/esm/app/AppInstallation/behaviors/index.js +0 -2
  5. package/dist/esm/app/AppInstallation/behaviors/types.js +0 -1
  6. package/dist/esm/app/AppInstallation/index.js +0 -2
  7. package/dist/esm/app/AppInstallation/types.js +0 -1
  8. package/dist/esm/app/index.js +0 -1
  9. package/dist/esm/article/Article/Article.js +0 -79
  10. package/dist/esm/article/Article/behaviors/api.js +0 -22
  11. package/dist/esm/article/Article/behaviors/index.js +0 -2
  12. package/dist/esm/article/Article/behaviors/types.js +0 -1
  13. package/dist/esm/article/Article/index.js +0 -2
  14. package/dist/esm/article/Article/types.js +0 -1
  15. package/dist/esm/article/index.js +0 -1
  16. package/dist/esm/base/DataModel.js +0 -7
  17. package/dist/esm/base/ListDataModel.js +0 -8
  18. package/dist/esm/base/ListQueryModel.js +0 -11
  19. package/dist/esm/base/Money.js +0 -5
  20. package/dist/esm/base/ReferenceModel.js +0 -9
  21. package/dist/esm/base/assertObjectFound.js +0 -9
  22. package/dist/esm/base/index.js +0 -6
  23. package/dist/esm/base/types.js +0 -1
  24. package/dist/esm/config/behaviors/api.js +0 -49
  25. package/dist/esm/config/behaviors/index.js +0 -1
  26. package/dist/esm/config/config.js +0 -13
  27. package/dist/esm/config/index.js +0 -1
  28. package/dist/esm/contract/Contract/Contract.js +0 -78
  29. package/dist/esm/contract/Contract/behaviors/api.js +0 -20
  30. package/dist/esm/contract/Contract/behaviors/index.js +0 -2
  31. package/dist/esm/contract/Contract/behaviors/types.js +0 -1
  32. package/dist/esm/contract/Contract/index.js +0 -2
  33. package/dist/esm/contract/Contract/types.js +0 -1
  34. package/dist/esm/contract/ContractItem/ContractItem.js +0 -31
  35. package/dist/esm/contract/ContractItem/behaviors/api.js +0 -13
  36. package/dist/esm/contract/ContractItem/behaviors/index.js +0 -2
  37. package/dist/esm/contract/ContractItem/behaviors/types.js +0 -1
  38. package/dist/esm/contract/ContractItem/index.js +0 -2
  39. package/dist/esm/contract/ContractItem/types.js +0 -1
  40. package/dist/esm/contract/index.js +0 -2
  41. package/dist/esm/customer/Customer/Customer.js +0 -96
  42. package/dist/esm/customer/Customer/behaviors/api.js +0 -30
  43. package/dist/esm/customer/Customer/behaviors/index.js +0 -2
  44. package/dist/esm/customer/Customer/behaviors/types.js +0 -1
  45. package/dist/esm/customer/Customer/index.js +0 -2
  46. package/dist/esm/customer/Customer/types.js +0 -1
  47. package/dist/esm/customer/index.js +0 -1
  48. package/dist/esm/domain/Ingress/Ingress.js +0 -106
  49. package/dist/esm/domain/Ingress/behaviors/api.js +0 -25
  50. package/dist/esm/domain/Ingress/behaviors/index.js +0 -2
  51. package/dist/esm/domain/Ingress/behaviors/types.js +0 -1
  52. package/dist/esm/domain/Ingress/index.js +0 -2
  53. package/dist/esm/domain/Ingress/types.js +0 -1
  54. package/dist/esm/domain/IngressPath/IngressPath.js +0 -15
  55. package/dist/esm/domain/IngressPath/IngressPath.test.js +0 -16
  56. package/dist/esm/domain/IngressPath/index.js +0 -2
  57. package/dist/esm/domain/IngressPath/types.js +0 -1
  58. package/dist/esm/domain/IngressTarget/IngressTarget.js +0 -40
  59. package/dist/esm/domain/IngressTarget/IngressTarget.test-types.js +0 -10
  60. package/dist/esm/domain/IngressTarget/index.js +0 -2
  61. package/dist/esm/domain/IngressTarget/types.js +0 -1
  62. package/dist/esm/domain/index.js +0 -1
  63. package/dist/esm/errors/ObjectNotFoundError.js +0 -7
  64. package/dist/esm/index.js +0 -7
  65. package/dist/esm/lib/deepFreeze.js +0 -4
  66. package/dist/esm/lib/joinedId.js +0 -1
  67. package/dist/esm/lib/types.js +0 -1
  68. package/dist/esm/project/Project/Project.js +0 -121
  69. package/dist/esm/project/Project/behaviors/api.js +0 -58
  70. package/dist/esm/project/Project/behaviors/inMem.js +0 -27
  71. package/dist/esm/project/Project/behaviors/index.js +0 -3
  72. package/dist/esm/project/Project/behaviors/types.js +0 -1
  73. package/dist/esm/project/Project/index.js +0 -2
  74. package/dist/esm/project/Project/types.js +0 -1
  75. package/dist/esm/project/index.js +0 -1
  76. package/dist/esm/react/MittwaldApiModelProvider.js +0 -12
  77. package/dist/esm/react/asyncResourceInvalidation.js +0 -29
  78. package/dist/esm/react/index.js +0 -4
  79. package/dist/esm/react/provideReact.js +0 -27
  80. package/dist/esm/react/provideReact.test-types.js +0 -21
  81. package/dist/esm/react/reactProvisionContext.js +0 -2
  82. package/dist/esm/react/reactUsePromise.js +0 -17
  83. package/dist/esm/react.js +0 -1
  84. package/dist/esm/server/Server/Server.js +0 -102
  85. package/dist/esm/server/Server/behaviors/api.js +0 -22
  86. package/dist/esm/server/Server/behaviors/index.js +0 -2
  87. package/dist/esm/server/Server/behaviors/types.js +0 -1
  88. package/dist/esm/server/Server/index.js +0 -1
  89. package/dist/esm/server/Server/types.js +0 -1
  90. package/dist/esm/server/index.js +0 -1
  91. package/dist/types/app/AppInstallation/AppInstallation.d.ts +0 -138
  92. package/dist/types/app/AppInstallation/behaviors/api.d.ts +0 -3
  93. package/dist/types/app/AppInstallation/behaviors/index.d.ts +0 -2
  94. package/dist/types/app/AppInstallation/behaviors/types.d.ts +0 -6
  95. package/dist/types/app/AppInstallation/index.d.ts +0 -2
  96. package/dist/types/app/AppInstallation/types.d.ts +0 -4
  97. package/dist/types/app/index.d.ts +0 -1
  98. package/dist/types/article/Article/Article.d.ts +0 -133
  99. package/dist/types/article/Article/behaviors/api.d.ts +0 -3
  100. package/dist/types/article/Article/behaviors/index.d.ts +0 -2
  101. package/dist/types/article/Article/behaviors/types.d.ts +0 -6
  102. package/dist/types/article/Article/index.d.ts +0 -2
  103. package/dist/types/article/Article/types.d.ts +0 -5
  104. package/dist/types/article/index.d.ts +0 -1
  105. package/dist/types/base/DataModel.d.ts +0 -5
  106. package/dist/types/base/ListDataModel.d.ts +0 -5
  107. package/dist/types/base/ListQueryModel.d.ts +0 -9
  108. package/dist/types/base/Money.d.ts +0 -3
  109. package/dist/types/base/ReferenceModel.d.ts +0 -5
  110. package/dist/types/base/assertObjectFound.d.ts +0 -3
  111. package/dist/types/base/index.d.ts +0 -6
  112. package/dist/types/base/types.d.ts +0 -6
  113. package/dist/types/config/behaviors/api.d.ts +0 -12
  114. package/dist/types/config/behaviors/index.d.ts +0 -1
  115. package/dist/types/config/config.d.ts +0 -23
  116. package/dist/types/config/index.d.ts +0 -1
  117. package/dist/types/contract/Contract/Contract.d.ts +0 -68
  118. package/dist/types/contract/Contract/behaviors/api.d.ts +0 -3
  119. package/dist/types/contract/Contract/behaviors/index.d.ts +0 -2
  120. package/dist/types/contract/Contract/behaviors/types.d.ts +0 -9
  121. package/dist/types/contract/Contract/index.d.ts +0 -2
  122. package/dist/types/contract/Contract/types.d.ts +0 -8
  123. package/dist/types/contract/ContractItem/ContractItem.d.ts +0 -64
  124. package/dist/types/contract/ContractItem/behaviors/api.d.ts +0 -3
  125. package/dist/types/contract/ContractItem/behaviors/index.d.ts +0 -2
  126. package/dist/types/contract/ContractItem/behaviors/types.d.ts +0 -4
  127. package/dist/types/contract/ContractItem/index.d.ts +0 -2
  128. package/dist/types/contract/ContractItem/types.d.ts +0 -2
  129. package/dist/types/contract/index.d.ts +0 -2
  130. package/dist/types/customer/Customer/Customer.d.ts +0 -138
  131. package/dist/types/customer/Customer/behaviors/api.d.ts +0 -3
  132. package/dist/types/customer/Customer/behaviors/index.d.ts +0 -2
  133. package/dist/types/customer/Customer/behaviors/types.d.ts +0 -7
  134. package/dist/types/customer/Customer/index.d.ts +0 -2
  135. package/dist/types/customer/Customer/types.d.ts +0 -5
  136. package/dist/types/customer/index.d.ts +0 -1
  137. package/dist/types/domain/Ingress/Ingress.d.ts +0 -109
  138. package/dist/types/domain/Ingress/behaviors/api.d.ts +0 -3
  139. package/dist/types/domain/Ingress/behaviors/index.d.ts +0 -2
  140. package/dist/types/domain/Ingress/behaviors/types.d.ts +0 -6
  141. package/dist/types/domain/Ingress/index.d.ts +0 -2
  142. package/dist/types/domain/Ingress/types.d.ts +0 -8
  143. package/dist/types/domain/IngressPath/IngressPath.d.ts +0 -11
  144. package/dist/types/domain/IngressPath/IngressPath.test.d.ts +0 -1
  145. package/dist/types/domain/IngressPath/index.d.ts +0 -2
  146. package/dist/types/domain/IngressPath/types.d.ts +0 -2
  147. package/dist/types/domain/IngressTarget/IngressTarget.d.ts +0 -24
  148. package/dist/types/domain/IngressTarget/IngressTarget.test-types.d.ts +0 -1
  149. package/dist/types/domain/IngressTarget/index.d.ts +0 -2
  150. package/dist/types/domain/IngressTarget/types.d.ts +0 -6
  151. package/dist/types/domain/index.d.ts +0 -1
  152. package/dist/types/errors/ObjectNotFoundError.d.ts +0 -3
  153. package/dist/types/index.d.ts +0 -7
  154. package/dist/types/lib/deepFreeze.d.ts +0 -5
  155. package/dist/types/lib/joinedId.d.ts +0 -1
  156. package/dist/types/lib/types.d.ts +0 -2
  157. package/dist/types/project/Project/Project.d.ts +0 -292
  158. package/dist/types/project/Project/behaviors/api.d.ts +0 -3
  159. package/dist/types/project/Project/behaviors/inMem.d.ts +0 -3
  160. package/dist/types/project/Project/behaviors/index.d.ts +0 -3
  161. package/dist/types/project/Project/behaviors/types.d.ts +0 -12
  162. package/dist/types/project/Project/index.d.ts +0 -2
  163. package/dist/types/project/Project/types.d.ts +0 -10
  164. package/dist/types/project/index.d.ts +0 -1
  165. package/dist/types/react/MittwaldApiModelProvider.d.ts +0 -6
  166. package/dist/types/react/asyncResourceInvalidation.d.ts +0 -4
  167. package/dist/types/react/index.d.ts +0 -5
  168. package/dist/types/react/provideReact.d.ts +0 -12
  169. package/dist/types/react/provideReact.test-types.d.ts +0 -1
  170. package/dist/types/react/reactProvisionContext.d.ts +0 -3
  171. package/dist/types/react/reactUsePromise.d.ts +0 -2
  172. package/dist/types/react.d.ts +0 -1
  173. package/dist/types/server/Server/Server.d.ts +0 -115
  174. package/dist/types/server/Server/behaviors/api.d.ts +0 -3
  175. package/dist/types/server/Server/behaviors/index.d.ts +0 -2
  176. package/dist/types/server/Server/behaviors/types.d.ts +0 -6
  177. package/dist/types/server/Server/index.d.ts +0 -1
  178. package/dist/types/server/Server/types.d.ts +0 -8
  179. package/dist/types/server/index.d.ts +0 -1
@@ -1,96 +0,0 @@
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 "../../react/provideReact.js";
7
- import { ListQueryModel } from "../../base/ListQueryModel.js";
8
- import { ListDataModel } from "../../base/ListDataModel.js";
9
- import { ServerListQuery } from "../../server/index.js";
10
- import { ProjectListQuery } from "../../project/index.js";
11
- export class Customer extends ReferenceModel {
12
- servers;
13
- projects;
14
- constructor(id) {
15
- super(id);
16
- this.servers = new ServerListQuery({
17
- customer: this,
18
- });
19
- this.projects = new ProjectListQuery({
20
- customer: this,
21
- });
22
- }
23
- static ofId(id) {
24
- return new Customer(id);
25
- }
26
- static find = provideReact(async (id) => {
27
- const data = await config.behaviors.customer.find(id);
28
- if (data !== undefined) {
29
- return new CustomerDetailed(data);
30
- }
31
- });
32
- static query(query = {}) {
33
- return new CustomerListQuery(query);
34
- }
35
- /** @deprecated Use query() */
36
- static list = provideReact(async (query = {}) => new CustomerListQuery(query).execute().then((res) => res.items));
37
- static get = provideReact(async (id) => {
38
- const customer = await this.find(id);
39
- assertObjectFound(customer, this, id);
40
- return customer;
41
- });
42
- getDetailed = provideReact(() => Customer.get(this.id), [this.id]);
43
- findDetailed = provideReact(() => Customer.find(this.id), [this.id]);
44
- async update(data) {
45
- await config.behaviors.customer.update(this.id, data);
46
- }
47
- }
48
- // Common class for future extension
49
- class CustomerCommon extends classes((DataModel), Customer) {
50
- constructor(data) {
51
- super([data], [data.customerId]);
52
- }
53
- }
54
- export class CustomerDetailed extends classes(CustomerCommon, (DataModel)) {
55
- constructor(data) {
56
- super([data], [data]);
57
- }
58
- }
59
- export class CustomerListItem extends classes(CustomerCommon, (DataModel)) {
60
- constructor(data) {
61
- super([data], [data]);
62
- }
63
- }
64
- export class CustomerListQuery extends ListQueryModel {
65
- constructor(query = {}) {
66
- super(query);
67
- }
68
- refine(query) {
69
- return new CustomerListQuery({
70
- ...this.query,
71
- ...query,
72
- });
73
- }
74
- execute = provideReact(async () => {
75
- const { items, totalCount } = await config.behaviors.customer.list({
76
- limit: config.defaultPaginationLimit,
77
- ...this.query,
78
- });
79
- return new CustomerList(this.query, items.map((d) => new CustomerListItem(d)), totalCount);
80
- }, [this.queryId]);
81
- getTotalCount = provideReact(async () => {
82
- const { totalCount } = await this.refine({ limit: 1 }).execute();
83
- return totalCount;
84
- }, [this.queryId]);
85
- findOneAndOnly = provideReact(async () => {
86
- const { items, totalCount } = await this.refine({ limit: 2 }).execute();
87
- if (totalCount === 1) {
88
- return items[0];
89
- }
90
- }, [this.queryId]);
91
- }
92
- export class CustomerList extends classes(CustomerListQuery, (ListDataModel)) {
93
- constructor(query, customers, totalCount) {
94
- super([query], [customers, totalCount]);
95
- }
96
- }
@@ -1,30 +0,0 @@
1
- import { assertStatus, extractTotalCountHeader, } 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 {
19
- items: response.data,
20
- totalCount: extractTotalCountHeader(response),
21
- };
22
- },
23
- update: async (id, data) => {
24
- const response = await client.customer.updateCustomer({
25
- customerId: id,
26
- data,
27
- });
28
- assertStatus(response, 200);
29
- },
30
- });
@@ -1,2 +0,0 @@
1
- export * from "./api.js";
2
- export * from "./types.js";
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export * from "./Customer.js";
2
- export * from "./types.js";
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export * from "./Customer/index.js";
@@ -1,106 +0,0 @@
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 "../../react/provideReact.js";
7
- import { IngressPath } from "../IngressPath/IngressPath.js";
8
- import { ListQueryModel } from "../../base/ListQueryModel.js";
9
- import { ListDataModel } from "../../base/ListDataModel.js";
10
- export class Ingress extends ReferenceModel {
11
- static ofId(id) {
12
- return new Ingress(id);
13
- }
14
- static ofHostname(hostname) {
15
- return Ingress.ofId(hostname);
16
- }
17
- /** @deprecated: use query() or project.ingresses */
18
- static list = provideReact(async (query = {}) => new IngressListQuery(query).execute().then((r) => r.items));
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), [this.id]);
31
- findDetailed = provideReact(() => Ingress.find(this.id), [this.id]);
32
- }
33
- export class IngressCommon extends classes((DataModel), Ingress) {
34
- baseUrl;
35
- paths;
36
- defaultPath;
37
- constructor(data) {
38
- super([data], [data.id]);
39
- this.baseUrl = `https://${data.hostname}`;
40
- this.paths = Object.freeze(data.paths.map((p) => new IngressPath(this, p)));
41
- const defaultPath = this.paths.find((p) => p.path === "/");
42
- if (defaultPath === undefined) {
43
- throw new Error(`Ingress ${this.describe()} has no default path.`);
44
- }
45
- this.defaultPath = defaultPath;
46
- }
47
- }
48
- export class IngressDetailed extends classes(IngressCommon, (DataModel)) {
49
- constructor(data) {
50
- super([data], [data]);
51
- }
52
- }
53
- export class IngressListItem extends classes(IngressCommon, (DataModel)) {
54
- constructor(data) {
55
- super([data], [data]);
56
- }
57
- }
58
- export class IngressListQuery extends ListQueryModel {
59
- constructor(query = {}) {
60
- super(query);
61
- }
62
- refine(query = {}) {
63
- return new IngressListQuery({
64
- ...this.query,
65
- ...query,
66
- });
67
- }
68
- execute = provideReact(async () => {
69
- const { project, ...query } = this.query;
70
- const { items, totalCount } = await config.behaviors.ingress.list({
71
- /** @todo: use this code when pagination is supported by API */
72
- // limit: config.defaultPaginationLimit,
73
- ...query,
74
- projectId: project?.id,
75
- });
76
- return new IngressList(this.query, items.map((d) => new IngressListItem(d)), totalCount);
77
- }, [this.queryId]);
78
- getTotalCount = provideReact(async () => {
79
- /** @todo: use this code when pagination is supported by API */
80
- // const { totalCount } = await this.refine({ limit: 1 }).execute();
81
- // return totalCount;
82
- const { items } = await this.refine({}).execute();
83
- return items.length;
84
- }, [this.queryId]);
85
- findOneAndOnly = provideReact(async () => {
86
- /** @todo: use this code when pagination is supported by API */
87
- // const { items, totalCount } = await this.refine({ limit: 2 }).execute();
88
- // if (totalCount === 1) {
89
- // return items[0];
90
- // }
91
- const { items, totalCount } = await this.refine({}).execute();
92
- if (totalCount === 1) {
93
- return items[0];
94
- }
95
- }, [this.queryId]);
96
- }
97
- export class IngressList extends classes(IngressListQuery, (ListDataModel)) {
98
- constructor(query, ingresses, totalCount) {
99
- super([query], [ingresses, totalCount]);
100
- }
101
- getDefault() {
102
- const defaultIngress = this.items.find((i) => i.data.isDefault);
103
- assertObjectFound(defaultIngress, IngressListItem, "IngressList");
104
- return defaultIngress;
105
- }
106
- }
@@ -1,25 +0,0 @@
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 response = await client.domain.ingressListIngresses({
15
- queryParameters: query,
16
- });
17
- assertStatus(response, 200);
18
- return {
19
- items: response.data,
20
- totalCount: response.data.length,
21
- /** @todo: use this code when pagination is supported by API */
22
- // totalCount: extractTotalCountHeader(response),
23
- };
24
- },
25
- });
@@ -1,2 +0,0 @@
1
- export * from "./api.js";
2
- export * from "./types.js";
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export * from "./Ingress.js";
2
- export * from "./types.js";
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +0,0 @@
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
- }
@@ -1,16 +0,0 @@
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
- });
@@ -1,2 +0,0 @@
1
- export * from "./IngressPath.js";
2
- export * from "./types.js";
@@ -1 +0,0 @@
1
- export {};
@@ -1,40 +0,0 @@
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 IngressAppInstallationTarget extends IngressTargetBase {
19
- type = "appInstallation";
20
- appInstallation;
21
- constructor(path, data) {
22
- super(path, data);
23
- this.appInstallation = AppInstallation.ofId(data.installationId);
24
- }
25
- }
26
- export class IngressUndefinedTarget extends IngressTargetBase {
27
- type = "undefined";
28
- }
29
- export const ingressTargetFactory = (path, data) => {
30
- if ("url" in data) {
31
- return new IngressRedirectTarget(path, data);
32
- }
33
- if ("installationId" in data) {
34
- return new IngressAppInstallationTarget(path, data);
35
- }
36
- if ("useDefaultPage" in data) {
37
- return new IngressUndefinedTarget(path, data);
38
- }
39
- throw new Error("Ingress target type is not supported.");
40
- };
@@ -1,10 +0,0 @@
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 === "appInstallation") {
8
- void target.appInstallation.id;
9
- }
10
- export {};
@@ -1,2 +0,0 @@
1
- export * from "./IngressTarget.js";
2
- export * from "./types.js";
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export * from "./Ingress/index.js";
@@ -1,7 +0,0 @@
1
- export default class ObjectNotFoundError extends Error {
2
- constructor(type, refName) {
3
- super(`${type}@${refName} not found`);
4
- this.name = "ObjectNotFoundError";
5
- Object.setPrototypeOf(this, ObjectNotFoundError.prototype);
6
- }
7
- }
package/dist/esm/index.js DELETED
@@ -1,7 +0,0 @@
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";
@@ -1,4 +0,0 @@
1
- import deepFreezeLib from "another-deep-freeze";
2
- // eslint-disable-next-line
3
- const deepFreeze = deepFreezeLib.default;
4
- export default deepFreeze;
@@ -1 +0,0 @@
1
- export const joinedId = (...parts) => parts.join(" | ");
@@ -1 +0,0 @@
1
- export {};
@@ -1,121 +0,0 @@
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 "../../react/provideReact.js";
7
- import { Customer } from "../../customer/Customer/Customer.js";
8
- import { ReferenceModel } from "../../base/ReferenceModel.js";
9
- import { Ingress, IngressListItem, IngressListQuery, } from "../../domain/index.js";
10
- import { ListQueryModel } from "../../base/ListQueryModel.js";
11
- import { ListDataModel } from "../../base/ListDataModel.js";
12
- import { AppInstallationListQuery } from "../../app/index.js";
13
- export class Project extends ReferenceModel {
14
- ingresses;
15
- appInstallations;
16
- constructor(id) {
17
- super(id);
18
- this.ingresses = new IngressListQuery({
19
- project: this,
20
- });
21
- this.appInstallations = new AppInstallationListQuery(this);
22
- }
23
- static ofId(id) {
24
- return new Project(id);
25
- }
26
- static find = provideReact(async (id) => {
27
- const data = await config.behaviors.project.find(id);
28
- if (data !== undefined) {
29
- return new ProjectDetailed(data);
30
- }
31
- });
32
- static get = provideReact(async (id) => {
33
- const project = await this.find(id);
34
- assertObjectFound(project, this, id);
35
- return project;
36
- });
37
- static query(query = {}) {
38
- return new ProjectListQuery(query);
39
- }
40
- /** @deprecated: use query(), Customer.projects or Server.projects */
41
- static list = provideReact(async (query = {}) => {
42
- return new ProjectListQuery(query).execute().then((r) => r.items);
43
- });
44
- static async create(serverId, description) {
45
- const { id } = await config.behaviors.project.create(serverId, description);
46
- return new Project(id);
47
- }
48
- getDetailed = provideReact(() => Project.get(this.id), [this.id]);
49
- findDetailed = provideReact(() => Project.find(this.id), [this.id]);
50
- /** @deprecated: use ingresses property */
51
- listIngresses = provideReact(() => Ingress.list({ projectId: this.id }));
52
- getDefaultIngress = provideReact(async () => {
53
- const ingresses = await Project.ofId(this.id).listIngresses();
54
- const defaultIngress = ingresses.find((i) => i.data.isDefault);
55
- assertObjectFound(defaultIngress, IngressListItem, this);
56
- return defaultIngress;
57
- });
58
- async updateDescription(description) {
59
- await config.behaviors.project.updateDescription(this.id, description);
60
- }
61
- async leave() {
62
- await config.behaviors.project.leave(this.id);
63
- }
64
- async delete() {
65
- await config.behaviors.project.delete(this.id);
66
- }
67
- }
68
- class ProjectCommon extends classes((DataModel), Project) {
69
- server;
70
- customer;
71
- constructor(data) {
72
- super([data], [data.id]);
73
- this.server = data.serverId ? Server.ofId(data.serverId) : undefined;
74
- this.customer = Customer.ofId(data.customerId);
75
- }
76
- }
77
- export class ProjectDetailed extends classes(ProjectCommon, (DataModel)) {
78
- constructor(data) {
79
- super([data], [data]);
80
- }
81
- }
82
- export class ProjectListItem extends classes(ProjectCommon, (DataModel)) {
83
- constructor(data) {
84
- super([data], [data]);
85
- }
86
- }
87
- export class ProjectListQuery extends ListQueryModel {
88
- constructor(query = {}) {
89
- super(query);
90
- }
91
- refine(query) {
92
- return new ProjectListQuery({
93
- ...this.query,
94
- ...query,
95
- });
96
- }
97
- execute = provideReact(async () => {
98
- const { server, customer, ...query } = this.query;
99
- const { items, totalCount } = await config.behaviors.project.list({
100
- ...query,
101
- serverId: server?.id,
102
- customerId: customer?.id,
103
- });
104
- return new ProjectList(this.query, items.map((d) => new ProjectListItem(d)), totalCount);
105
- }, [this.queryId]);
106
- getTotalCount = provideReact(async () => {
107
- const { totalCount } = await this.refine({ limit: 1 }).execute();
108
- return totalCount;
109
- }, [this.queryId]);
110
- findOneAndOnly = provideReact(async () => {
111
- const { items, totalCount } = await this.refine({ limit: 2 }).execute();
112
- if (totalCount === 1) {
113
- return items[0];
114
- }
115
- }, [this.queryId]);
116
- }
117
- export class ProjectList extends classes(ProjectListQuery, (ListDataModel)) {
118
- constructor(query, projects, totalCount) {
119
- super([query], [projects, totalCount]);
120
- }
121
- }
@@ -1,58 +0,0 @@
1
- import { assertStatus, extractTotalCountHeader, } 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 {
19
- items: response.data,
20
- totalCount: extractTotalCountHeader(response),
21
- };
22
- },
23
- create: async (serverId, description) => {
24
- const response = await client.project.createProject({
25
- serverId,
26
- data: {
27
- description,
28
- },
29
- });
30
- assertStatus(response, 201);
31
- return response.data;
32
- },
33
- leave: async (id) => {
34
- const selfMembershipResponse = await client.project.getSelfMembershipForProject({
35
- projectId: id,
36
- });
37
- assertStatus(selfMembershipResponse, 200);
38
- const response = await client.project.deleteProjectMembership({
39
- projectMembershipId: selfMembershipResponse.data.id,
40
- });
41
- assertStatus(response, 204);
42
- },
43
- delete: async (id) => {
44
- const response = await client.project.deleteProject({
45
- projectId: id,
46
- });
47
- assertStatus(response, 204);
48
- },
49
- updateDescription: async (id, description) => {
50
- const response = await client.project.updateProjectDescription({
51
- projectId: id,
52
- data: {
53
- description,
54
- },
55
- });
56
- assertStatus(response, 204);
57
- },
58
- });
@@ -1,27 +0,0 @@
1
- export const inMemProjectBehaviors = (store) => ({
2
- find: async (id) => store.get(id),
3
- list: async () => {
4
- const items = Array.from(store.values()).map((detailedProject) => ({
5
- ...detailedProject,
6
- customerMeta: {
7
- id: detailedProject.customerId,
8
- },
9
- }));
10
- return {
11
- items,
12
- totalCount: items.length,
13
- };
14
- },
15
- create: async () => {
16
- throw new Error("Not implemented");
17
- },
18
- leave: async () => {
19
- throw new Error("Not implemented");
20
- },
21
- delete: async () => {
22
- throw new Error("Not implemented");
23
- },
24
- updateDescription: async () => {
25
- throw new Error("Not implemented");
26
- },
27
- });
@@ -1,3 +0,0 @@
1
- export * from "./api.js";
2
- export * from "./inMem.js";
3
- export * from "./types.js";
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export * from "./Project.js";
2
- export * from "./types.js";
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export * from "./Project/index.js";
@@ -1,12 +0,0 @@
1
- import { usePromise } from "@mittwald/react-use-promise";
2
- import { setModule } from "./reactUsePromise.js";
3
- export const MittwaldApiModelProvider = (props) => {
4
- const { fallback, children } = props;
5
- const module = usePromise(() => import("@mittwald/react-use-promise").then(setModule), [], {
6
- useSuspense: false,
7
- });
8
- if (!module.hasValue) {
9
- return fallback;
10
- }
11
- return children;
12
- };