@mittwald/api-models 4.242.2 → 4.243.0

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/dist/esm/app/AppInstallation/AppInstallation.js +89 -0
  2. package/dist/esm/app/AppInstallation/behaviors/api.js +24 -0
  3. package/dist/esm/app/AppInstallation/behaviors/index.js +2 -0
  4. package/dist/esm/app/AppInstallation/behaviors/types.js +1 -0
  5. package/dist/esm/app/AppInstallation/index.js +2 -0
  6. package/dist/esm/app/AppInstallation/types.js +1 -0
  7. package/dist/esm/app/index.js +1 -0
  8. package/dist/esm/article/Article/Article.js +79 -0
  9. package/dist/esm/article/Article/behaviors/api.js +22 -0
  10. package/dist/esm/article/Article/behaviors/index.js +2 -0
  11. package/dist/esm/article/Article/behaviors/types.js +1 -0
  12. package/dist/esm/article/Article/index.js +2 -0
  13. package/dist/esm/article/Article/types.js +1 -0
  14. package/dist/esm/article/index.js +1 -0
  15. package/dist/esm/base/DataModel.js +7 -0
  16. package/dist/esm/base/ListDataModel.js +8 -0
  17. package/dist/esm/base/ListQueryModel.js +11 -0
  18. package/dist/esm/base/Money.js +5 -0
  19. package/dist/esm/base/ReferenceModel.js +9 -0
  20. package/dist/esm/base/assertObjectFound.js +9 -0
  21. package/dist/esm/base/index.js +6 -0
  22. package/dist/esm/base/types.js +1 -0
  23. package/dist/esm/config/behaviors/api.js +49 -0
  24. package/dist/esm/config/behaviors/index.js +1 -0
  25. package/dist/esm/config/config.js +13 -0
  26. package/dist/esm/config/index.js +1 -0
  27. package/dist/esm/contract/Contract/Contract.js +78 -0
  28. package/dist/esm/contract/Contract/behaviors/api.js +20 -0
  29. package/dist/esm/contract/Contract/behaviors/index.js +2 -0
  30. package/dist/esm/contract/Contract/behaviors/types.js +1 -0
  31. package/dist/esm/contract/Contract/index.js +2 -0
  32. package/dist/esm/contract/Contract/types.js +1 -0
  33. package/dist/esm/contract/ContractItem/ContractItem.js +31 -0
  34. package/dist/esm/contract/ContractItem/behaviors/api.js +13 -0
  35. package/dist/esm/contract/ContractItem/behaviors/index.js +2 -0
  36. package/dist/esm/contract/ContractItem/behaviors/types.js +1 -0
  37. package/dist/esm/contract/ContractItem/index.js +2 -0
  38. package/dist/esm/contract/ContractItem/types.js +1 -0
  39. package/dist/esm/contract/index.js +2 -0
  40. package/dist/esm/customer/Customer/Customer.js +96 -0
  41. package/dist/esm/customer/Customer/behaviors/api.js +30 -0
  42. package/dist/esm/customer/Customer/behaviors/index.js +2 -0
  43. package/dist/esm/customer/Customer/behaviors/types.js +1 -0
  44. package/dist/esm/customer/Customer/index.js +2 -0
  45. package/dist/esm/customer/Customer/types.js +1 -0
  46. package/dist/esm/customer/index.js +1 -0
  47. package/dist/esm/domain/Ingress/Ingress.js +106 -0
  48. package/dist/esm/domain/Ingress/behaviors/api.js +25 -0
  49. package/dist/esm/domain/Ingress/behaviors/index.js +2 -0
  50. package/dist/esm/domain/Ingress/behaviors/types.js +1 -0
  51. package/dist/esm/domain/Ingress/index.js +2 -0
  52. package/dist/esm/domain/Ingress/types.js +1 -0
  53. package/dist/esm/domain/IngressPath/IngressPath.js +15 -0
  54. package/dist/esm/domain/IngressPath/IngressPath.test.js +16 -0
  55. package/dist/esm/domain/IngressPath/index.js +2 -0
  56. package/dist/esm/domain/IngressPath/types.js +1 -0
  57. package/dist/esm/domain/IngressTarget/IngressTarget.js +40 -0
  58. package/dist/esm/domain/IngressTarget/IngressTarget.test-types.js +10 -0
  59. package/dist/esm/domain/IngressTarget/index.js +2 -0
  60. package/dist/esm/domain/IngressTarget/types.js +1 -0
  61. package/dist/esm/domain/index.js +1 -0
  62. package/dist/esm/errors/ObjectNotFoundError.js +7 -0
  63. package/dist/esm/index.js +7 -0
  64. package/dist/esm/lib/deepFreeze.js +4 -0
  65. package/dist/esm/lib/joinedId.js +1 -0
  66. package/dist/esm/lib/types.js +1 -0
  67. package/dist/esm/project/Project/Project.js +121 -0
  68. package/dist/esm/project/Project/behaviors/api.js +58 -0
  69. package/dist/esm/project/Project/behaviors/inMem.js +27 -0
  70. package/dist/esm/project/Project/behaviors/index.js +3 -0
  71. package/dist/esm/project/Project/behaviors/types.js +1 -0
  72. package/dist/esm/project/Project/index.js +2 -0
  73. package/dist/esm/project/Project/types.js +1 -0
  74. package/dist/esm/project/index.js +1 -0
  75. package/dist/esm/react/MittwaldApiModelProvider.js +12 -0
  76. package/dist/esm/react/asyncResourceInvalidation.js +29 -0
  77. package/dist/esm/react/index.js +4 -0
  78. package/dist/esm/react/provideReact.js +27 -0
  79. package/dist/esm/react/provideReact.test-types.js +21 -0
  80. package/dist/esm/react/reactProvisionContext.js +2 -0
  81. package/dist/esm/react/reactUsePromise.js +17 -0
  82. package/dist/esm/react.js +1 -0
  83. package/dist/esm/server/Server/Server.js +102 -0
  84. package/dist/esm/server/Server/behaviors/api.js +22 -0
  85. package/dist/esm/server/Server/behaviors/index.js +2 -0
  86. package/dist/esm/server/Server/behaviors/types.js +1 -0
  87. package/dist/esm/server/Server/index.js +1 -0
  88. package/dist/esm/server/Server/types.js +1 -0
  89. package/dist/esm/server/index.js +1 -0
  90. package/dist/types/app/AppInstallation/AppInstallation.d.ts +138 -0
  91. package/dist/types/app/AppInstallation/behaviors/api.d.ts +3 -0
  92. package/dist/types/app/AppInstallation/behaviors/index.d.ts +2 -0
  93. package/dist/types/app/AppInstallation/behaviors/types.d.ts +6 -0
  94. package/dist/types/app/AppInstallation/index.d.ts +2 -0
  95. package/dist/types/app/AppInstallation/types.d.ts +4 -0
  96. package/dist/types/app/index.d.ts +1 -0
  97. package/dist/types/article/Article/Article.d.ts +133 -0
  98. package/dist/types/article/Article/behaviors/api.d.ts +3 -0
  99. package/dist/types/article/Article/behaviors/index.d.ts +2 -0
  100. package/dist/types/article/Article/behaviors/types.d.ts +6 -0
  101. package/dist/types/article/Article/index.d.ts +2 -0
  102. package/dist/types/article/Article/types.d.ts +5 -0
  103. package/dist/types/article/index.d.ts +1 -0
  104. package/dist/types/base/DataModel.d.ts +5 -0
  105. package/dist/types/base/ListDataModel.d.ts +5 -0
  106. package/dist/types/base/ListQueryModel.d.ts +9 -0
  107. package/dist/types/base/Money.d.ts +3 -0
  108. package/dist/types/base/ReferenceModel.d.ts +5 -0
  109. package/dist/types/base/assertObjectFound.d.ts +3 -0
  110. package/dist/types/base/index.d.ts +6 -0
  111. package/dist/types/base/types.d.ts +6 -0
  112. package/dist/types/config/behaviors/api.d.ts +12 -0
  113. package/dist/types/config/behaviors/index.d.ts +1 -0
  114. package/dist/types/config/config.d.ts +23 -0
  115. package/dist/types/config/index.d.ts +1 -0
  116. package/dist/types/contract/Contract/Contract.d.ts +68 -0
  117. package/dist/types/contract/Contract/behaviors/api.d.ts +3 -0
  118. package/dist/types/contract/Contract/behaviors/index.d.ts +2 -0
  119. package/dist/types/contract/Contract/behaviors/types.d.ts +9 -0
  120. package/dist/types/contract/Contract/index.d.ts +2 -0
  121. package/dist/types/contract/Contract/types.d.ts +8 -0
  122. package/dist/types/contract/ContractItem/ContractItem.d.ts +64 -0
  123. package/dist/types/contract/ContractItem/behaviors/api.d.ts +3 -0
  124. package/dist/types/contract/ContractItem/behaviors/index.d.ts +2 -0
  125. package/dist/types/contract/ContractItem/behaviors/types.d.ts +4 -0
  126. package/dist/types/contract/ContractItem/index.d.ts +2 -0
  127. package/dist/types/contract/ContractItem/types.d.ts +2 -0
  128. package/dist/types/contract/index.d.ts +2 -0
  129. package/dist/types/customer/Customer/Customer.d.ts +138 -0
  130. package/dist/types/customer/Customer/behaviors/api.d.ts +3 -0
  131. package/dist/types/customer/Customer/behaviors/index.d.ts +2 -0
  132. package/dist/types/customer/Customer/behaviors/types.d.ts +7 -0
  133. package/dist/types/customer/Customer/index.d.ts +2 -0
  134. package/dist/types/customer/Customer/types.d.ts +5 -0
  135. package/dist/types/customer/index.d.ts +1 -0
  136. package/dist/types/domain/Ingress/Ingress.d.ts +109 -0
  137. package/dist/types/domain/Ingress/behaviors/api.d.ts +3 -0
  138. package/dist/types/domain/Ingress/behaviors/index.d.ts +2 -0
  139. package/dist/types/domain/Ingress/behaviors/types.d.ts +6 -0
  140. package/dist/types/domain/Ingress/index.d.ts +2 -0
  141. package/dist/types/domain/Ingress/types.d.ts +8 -0
  142. package/dist/types/domain/IngressPath/IngressPath.d.ts +11 -0
  143. package/dist/types/domain/IngressPath/IngressPath.test.d.ts +1 -0
  144. package/dist/types/domain/IngressPath/index.d.ts +2 -0
  145. package/dist/types/domain/IngressPath/types.d.ts +2 -0
  146. package/dist/types/domain/IngressTarget/IngressTarget.d.ts +24 -0
  147. package/dist/types/domain/IngressTarget/IngressTarget.test-types.d.ts +1 -0
  148. package/dist/types/domain/IngressTarget/index.d.ts +2 -0
  149. package/dist/types/domain/IngressTarget/types.d.ts +6 -0
  150. package/dist/types/domain/index.d.ts +1 -0
  151. package/dist/types/errors/ObjectNotFoundError.d.ts +3 -0
  152. package/dist/types/index.d.ts +7 -0
  153. package/dist/types/lib/deepFreeze.d.ts +5 -0
  154. package/dist/types/lib/joinedId.d.ts +1 -0
  155. package/dist/types/lib/types.d.ts +2 -0
  156. package/dist/types/project/Project/Project.d.ts +292 -0
  157. package/dist/types/project/Project/behaviors/api.d.ts +3 -0
  158. package/dist/types/project/Project/behaviors/inMem.d.ts +3 -0
  159. package/dist/types/project/Project/behaviors/index.d.ts +3 -0
  160. package/dist/types/project/Project/behaviors/types.d.ts +12 -0
  161. package/dist/types/project/Project/index.d.ts +2 -0
  162. package/dist/types/project/Project/types.d.ts +10 -0
  163. package/dist/types/project/index.d.ts +1 -0
  164. package/dist/types/react/MittwaldApiModelProvider.d.ts +6 -0
  165. package/dist/types/react/asyncResourceInvalidation.d.ts +4 -0
  166. package/dist/types/react/index.d.ts +5 -0
  167. package/dist/types/react/provideReact.d.ts +12 -0
  168. package/dist/types/react/provideReact.test-types.d.ts +1 -0
  169. package/dist/types/react/reactProvisionContext.d.ts +3 -0
  170. package/dist/types/react/reactUsePromise.d.ts +2 -0
  171. package/dist/types/react.d.ts +1 -0
  172. package/dist/types/server/Server/Server.d.ts +115 -0
  173. package/dist/types/server/Server/behaviors/api.d.ts +3 -0
  174. package/dist/types/server/Server/behaviors/index.d.ts +2 -0
  175. package/dist/types/server/Server/behaviors/types.d.ts +6 -0
  176. package/dist/types/server/Server/index.d.ts +1 -0
  177. package/dist/types/server/Server/types.d.ts +8 -0
  178. package/dist/types/server/index.d.ts +1 -0
  179. package/package.json +3 -3
@@ -0,0 +1,89 @@
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 { Project } from "../../project/index.js";
10
+ export class AppInstallation extends ReferenceModel {
11
+ static find = provideReact(async (id) => {
12
+ const data = await config.behaviors.appInstallation.find(id);
13
+ if (data !== undefined) {
14
+ return new AppInstallationDetailed(data);
15
+ }
16
+ });
17
+ static get = provideReact(async (id) => {
18
+ const appInstallation = await this.find(id);
19
+ assertObjectFound(appInstallation, this, id);
20
+ return appInstallation;
21
+ });
22
+ static ofId(id) {
23
+ return new AppInstallation(id);
24
+ }
25
+ query(project, query = {}) {
26
+ return new AppInstallationListQuery(project, query);
27
+ }
28
+ /** @deprecated: use query() or project.appInstallations */
29
+ static list = provideReact(async (projectId, query = {}) => {
30
+ return new AppInstallationListQuery(Project.ofId(projectId), query)
31
+ .execute()
32
+ .then((r) => r.items);
33
+ });
34
+ getDetailed = provideReact(() => AppInstallation.get(this.id), [this.id]);
35
+ findDetailed = provideReact(() => AppInstallation.find(this.id), [this.id]);
36
+ }
37
+ // Common class for future extension
38
+ class AppInstallationCommon extends classes((DataModel), AppInstallation) {
39
+ constructor(data) {
40
+ super([data], [data.id]);
41
+ }
42
+ }
43
+ export class AppInstallationDetailed extends classes(AppInstallationCommon, (DataModel)) {
44
+ constructor(data) {
45
+ super([data], [data]);
46
+ }
47
+ }
48
+ export class AppInstallationListItem extends classes(AppInstallationCommon, (DataModel)) {
49
+ constructor(data) {
50
+ super([data], [data]);
51
+ }
52
+ }
53
+ export class AppInstallationListQuery extends ListQueryModel {
54
+ project;
55
+ constructor(project, query = {}) {
56
+ super(query, {
57
+ dependencies: [project.id],
58
+ });
59
+ this.project = project;
60
+ }
61
+ refine(query) {
62
+ return new AppInstallationListQuery(this.project, {
63
+ ...this.query,
64
+ ...query,
65
+ });
66
+ }
67
+ execute = provideReact(async () => {
68
+ const { items, totalCount } = await config.behaviors.appInstallation.list(this.project.id, {
69
+ limit: config.defaultPaginationLimit,
70
+ ...this.query,
71
+ });
72
+ return new AppInstallationList(this.project, this.query, items.map((d) => new AppInstallationListItem(d)), totalCount);
73
+ }, [this.queryId]);
74
+ getTotalCount = provideReact(async () => {
75
+ const { totalCount } = await this.refine({ limit: 1 }).execute();
76
+ return totalCount;
77
+ }, [this.queryId]);
78
+ findOneAndOnly = provideReact(async () => {
79
+ const { items, totalCount } = await this.refine({ limit: 2 }).execute();
80
+ if (totalCount === 1) {
81
+ return items[0];
82
+ }
83
+ }, [this.queryId]);
84
+ }
85
+ export class AppInstallationList extends classes(AppInstallationListQuery, (ListDataModel)) {
86
+ constructor(project, query, appInstallations, totalCount) {
87
+ super([project, query], [appInstallations, totalCount]);
88
+ }
89
+ }
@@ -0,0 +1,24 @@
1
+ import { assertStatus, extractTotalCountHeader, } 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 {
20
+ items: response.data,
21
+ totalCount: extractTotalCountHeader(response),
22
+ };
23
+ },
24
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./api.js";
2
+ export * from "./types.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./AppInstallation.js";
2
+ export * from "./types.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./AppInstallation/index.js";
@@ -0,0 +1,79 @@
1
+ import { ReferenceModel } from "../../base/ReferenceModel.js";
2
+ import { config } from "../../config/config.js";
3
+ import { classes } from "polytype";
4
+ import { DataModel } from "../../base/DataModel.js";
5
+ import assertObjectFound from "../../base/assertObjectFound.js";
6
+ import { provideReact } from "../../react/provideReact.js";
7
+ import { ListQueryModel } from "../../base/ListQueryModel.js";
8
+ import { ListDataModel } from "../../base/ListDataModel.js";
9
+ import { Money } from "../../base/Money.js";
10
+ export class Article extends ReferenceModel {
11
+ static ofId(id) {
12
+ return new Article(id);
13
+ }
14
+ static find = provideReact(async (id) => {
15
+ const data = await config.behaviors.article.find(id);
16
+ if (data !== undefined) {
17
+ return new ArticleDetailed(data);
18
+ }
19
+ });
20
+ static get = provideReact(async (id) => {
21
+ const article = await this.find(id);
22
+ assertObjectFound(article, this, id);
23
+ return article;
24
+ });
25
+ static query(query = {}) {
26
+ return new ArticleListQuery(query);
27
+ }
28
+ }
29
+ class ArticleCommon extends classes((DataModel), Article) {
30
+ price;
31
+ constructor(data) {
32
+ super([data]);
33
+ this.price = Money({ amount: data.price, currency: "EUR" });
34
+ }
35
+ }
36
+ export class ArticleDetailed extends classes(ArticleCommon, (DataModel)) {
37
+ constructor(data) {
38
+ super([data], [data]);
39
+ }
40
+ }
41
+ export class ArticleListItem extends classes(ArticleCommon, (DataModel)) {
42
+ constructor(data) {
43
+ super([data]);
44
+ }
45
+ }
46
+ export class ArticleListQuery extends ListQueryModel {
47
+ constructor(query = {}) {
48
+ super(query);
49
+ }
50
+ refine(query) {
51
+ return new ArticleListQuery({
52
+ ...this.query,
53
+ ...query,
54
+ });
55
+ }
56
+ execute = provideReact(async () => {
57
+ const { ...query } = this.query;
58
+ const { items, totalCount } = await config.behaviors.article.list({
59
+ limit: config.defaultPaginationLimit,
60
+ ...query,
61
+ });
62
+ return new ArticleList(this.query, items.map((d) => new ArticleListItem(d)), totalCount);
63
+ }, [this.queryId]);
64
+ getTotalCount = provideReact(async () => {
65
+ const { totalCount } = await this.refine({ limit: 1 }).execute();
66
+ return totalCount;
67
+ }, [this.queryId]);
68
+ findOneAndOnly = provideReact(async () => {
69
+ const { items, totalCount } = await this.refine({ limit: 1 }).execute();
70
+ if (totalCount === 1) {
71
+ return items[0];
72
+ }
73
+ }, [this.queryId]);
74
+ }
75
+ export class ArticleList extends classes(ArticleListQuery, (ListDataModel)) {
76
+ constructor(query, articles, totalCount) {
77
+ super([query], [articles, totalCount]);
78
+ }
79
+ }
@@ -0,0 +1,22 @@
1
+ import { assertStatus, extractTotalCountHeader, } from "@mittwald/api-client";
2
+ export const apiArticleBehaviors = (client) => ({
3
+ find: async (id) => {
4
+ const response = await client.article.getArticle({
5
+ articleId: id,
6
+ });
7
+ if (response.status === 200) {
8
+ return response.data;
9
+ }
10
+ assertStatus(response, 404);
11
+ },
12
+ list: async (query) => {
13
+ const response = await client.article.listArticles({
14
+ queryParameters: query,
15
+ });
16
+ assertStatus(response, 200);
17
+ return {
18
+ items: response.data,
19
+ totalCount: extractTotalCountHeader(response),
20
+ };
21
+ },
22
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./api.js";
2
+ export * from "./types.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./Article.js";
2
+ export * from "./types.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./Article/index.js";
@@ -0,0 +1,7 @@
1
+ import deepFreeze from "../lib/deepFreeze.js";
2
+ export class DataModel {
3
+ data;
4
+ constructor(data) {
5
+ this.data = deepFreeze(data);
6
+ }
7
+ }
@@ -0,0 +1,8 @@
1
+ export class ListDataModel {
2
+ items;
3
+ totalCount;
4
+ constructor(items, totalCount) {
5
+ this.items = Object.freeze(items);
6
+ this.totalCount = totalCount;
7
+ }
8
+ }
@@ -0,0 +1,11 @@
1
+ import { hash } from "object-code";
2
+ import { joinedId } from "../lib/joinedId.js";
3
+ export class ListQueryModel {
4
+ query;
5
+ queryId;
6
+ constructor(query, opts = {}) {
7
+ const { dependencies = [] } = opts;
8
+ this.query = query;
9
+ this.queryId = joinedId(hash(query), ...dependencies);
10
+ }
11
+ }
@@ -0,0 +1,5 @@
1
+ import Dinero from "dinero.js";
2
+ export const Money = Dinero;
3
+ Money.defaultCurrency = "EUR";
4
+ Money.defaultPrecision = 2;
5
+ Money.globalLocale = "de-DE";
@@ -0,0 +1,9 @@
1
+ export class ReferenceModel {
2
+ id;
3
+ constructor(id) {
4
+ this.id = id;
5
+ }
6
+ describe() {
7
+ return `${this.constructor.name}@${this.id}`;
8
+ }
9
+ }
@@ -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,6 @@
1
+ export * from "./assertObjectFound.js";
2
+ export * from "./DataModel.js";
3
+ export * from "./ReferenceModel.js";
4
+ export * from "./ListDataModel.js";
5
+ export * from "./ListQueryModel.js";
6
+ export * from "./types.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
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
+ import { addUrlTagToProvideReactCache } from "../../react/asyncResourceInvalidation.js";
9
+ import { apiArticleBehaviors } from "../../article/Article/behaviors/index.js";
10
+ import { apiContractBehaviors } from "../../contract/Contract/behaviors/index.js";
11
+ import { apiContractItemBehaviors } from "../../contract/ContractItem/behaviors/index.js";
12
+ class ApiSetupState {
13
+ _client;
14
+ setupWithClient(client) {
15
+ if (this._client !== undefined) {
16
+ throw new Error("API already setup. If you want to operate on the API client use api.client.");
17
+ }
18
+ this._client = client;
19
+ this._client.defaultRequestOptions.onBeforeRequest =
20
+ addUrlTagToProvideReactCache;
21
+ config.behaviors.article = apiArticleBehaviors(client);
22
+ config.behaviors.project = apiProjectBehaviors(client);
23
+ config.behaviors.server = apiServerBehaviors(client);
24
+ config.behaviors.customer = apiCustomerBehaviors(client);
25
+ config.behaviors.ingress = apiIngressBehaviors(client);
26
+ config.behaviors.appInstallation = apiAppInstallationBehaviors(client);
27
+ config.behaviors.contract = apiContractBehaviors(client);
28
+ config.behaviors.contractItem = apiContractItemBehaviors(client);
29
+ }
30
+ setupWithApiToken(apiToken) {
31
+ return this.setupWithClient(MittwaldAPIV2Client.newWithToken(apiToken));
32
+ }
33
+ setupUnauthenticated() {
34
+ return this.setupWithClient(MittwaldAPIV2Client.newUnauthenticated());
35
+ }
36
+ get client() {
37
+ if (!this._client) {
38
+ throw new Error("Could not get client. Behavior not initialized.");
39
+ }
40
+ return this._client;
41
+ }
42
+ get defaults() {
43
+ return this.client.axios.defaults;
44
+ }
45
+ get interceptors() {
46
+ return this.client.axios.interceptors;
47
+ }
48
+ }
49
+ export const api = new ApiSetupState();
@@ -0,0 +1 @@
1
+ export * from "./api.js";
@@ -0,0 +1,13 @@
1
+ export const config = {
2
+ defaultPaginationLimit: 50,
3
+ behaviors: {
4
+ contract: undefined,
5
+ contractItem: undefined,
6
+ article: undefined,
7
+ project: undefined,
8
+ server: undefined,
9
+ customer: undefined,
10
+ ingress: undefined,
11
+ appInstallation: undefined,
12
+ },
13
+ };
@@ -0,0 +1 @@
1
+ export * from "./behaviors/index.js";
@@ -0,0 +1,78 @@
1
+ import { DataModel, ListDataModel, ListQueryModel, ReferenceModel, } from "../../base/index.js";
2
+ import { provideReact } from "../../react/index.js";
3
+ import { config } from "../../config/config.js";
4
+ import { classes } from "polytype";
5
+ import assertObjectFound from "../../base/assertObjectFound.js";
6
+ export class Contract extends ReferenceModel {
7
+ static ofId(id) {
8
+ return new Contract(id);
9
+ }
10
+ static find = provideReact(async (id) => {
11
+ const data = await config.behaviors.contract.find(id);
12
+ if (data !== undefined) {
13
+ return new ContractDetailed(data);
14
+ }
15
+ });
16
+ static query(query) {
17
+ return new ContractListQuery(query);
18
+ }
19
+ static get = provideReact(async (id) => {
20
+ const customer = await this.find(id);
21
+ assertObjectFound(customer, this, id);
22
+ return customer;
23
+ });
24
+ }
25
+ class ContractCommon extends classes((DataModel), Contract) {
26
+ constructor(data) {
27
+ super([data], [data.customerId]);
28
+ }
29
+ }
30
+ export class ContractDetailed extends classes(ContractCommon, (DataModel)) {
31
+ constructor(data) {
32
+ super([data], [data]);
33
+ }
34
+ }
35
+ export class ContractListItem extends classes(ContractCommon, (DataModel)) {
36
+ constructor(data) {
37
+ super([data], [data]);
38
+ }
39
+ }
40
+ export class ContractListQuery extends ListQueryModel {
41
+ constructor(query) {
42
+ super(query);
43
+ }
44
+ refine(query) {
45
+ return new ContractListQuery({
46
+ ...this.query,
47
+ ...query,
48
+ });
49
+ }
50
+ execute = provideReact(async () => {
51
+ const { customer, ...query } = this.query;
52
+ const customerId = customer.id;
53
+ const request = {
54
+ customerId: customerId,
55
+ queryParameters: {
56
+ limit: config.defaultPaginationLimit,
57
+ ...query,
58
+ },
59
+ };
60
+ const { items, totalCount } = await config.behaviors.contract.list(request);
61
+ return new ContractList(this.query, items.map((d) => new ContractListItem(d)), totalCount);
62
+ }, [this.queryId]);
63
+ getTotalCount = provideReact(async () => {
64
+ const { totalCount } = await this.refine({ limit: 1 }).execute();
65
+ return totalCount;
66
+ }, [this.queryId]);
67
+ findOneAndOnly = provideReact(async () => {
68
+ const { items, totalCount } = await this.refine({ limit: 1 }).execute();
69
+ if (totalCount === 1) {
70
+ return items[0];
71
+ }
72
+ }, [this.queryId]);
73
+ }
74
+ export class ContractList extends classes(ContractListQuery, (ListDataModel)) {
75
+ constructor(query, contracts, totalCount) {
76
+ super([query], [contracts, totalCount]);
77
+ }
78
+ }
@@ -0,0 +1,20 @@
1
+ import { assertStatus, extractTotalCountHeader, } from "@mittwald/api-client";
2
+ export const apiContractBehaviors = (client) => ({
3
+ find: async (id) => {
4
+ const response = await client.contract.getDetailOfContract({
5
+ contractId: id,
6
+ });
7
+ if (response.status === 200) {
8
+ return response.data;
9
+ }
10
+ assertStatus(response, 404);
11
+ },
12
+ list: async (request) => {
13
+ const response = await client.contract.listContracts(request);
14
+ assertStatus(response, 200);
15
+ return {
16
+ items: response.data,
17
+ totalCount: extractTotalCountHeader(response),
18
+ };
19
+ },
20
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./api.js";
2
+ export * from "./types.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./Contract.js";
2
+ export * from "./types.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ import { classes } from "polytype";
2
+ import { DataModel, ReferenceModel } from "../../base/index.js";
3
+ import { provideReact } from "../../react/index.js";
4
+ import { config } from "../../config/config.js";
5
+ import assertObjectFound from "../../base/assertObjectFound.js";
6
+ export class ContractItem extends ReferenceModel {
7
+ static ofId(contractId, id) {
8
+ return new ContractItem(contractId, id);
9
+ }
10
+ static find = provideReact(async (contractId, contractItemId) => {
11
+ const data = await config.behaviors.contractItem.find(contractId, contractItemId);
12
+ if (data !== undefined) {
13
+ return new ContractItemDetailed(contractId, data);
14
+ }
15
+ });
16
+ static get = provideReact(async (contractId, contractItemId) => {
17
+ const item = await this.find(contractId, contractItemId);
18
+ assertObjectFound(item, this, contractItemId);
19
+ return item;
20
+ });
21
+ contractId;
22
+ constructor(contractId, id) {
23
+ super(id);
24
+ this.contractId = contractId;
25
+ }
26
+ }
27
+ export class ContractItemDetailed extends classes((DataModel), ContractItem) {
28
+ constructor(contractId, data) {
29
+ super([data], [contractId, data.itemId]);
30
+ }
31
+ }
@@ -0,0 +1,13 @@
1
+ import { assertStatus } from "@mittwald/api-client";
2
+ export const apiContractItemBehaviors = (client) => ({
3
+ find: async (contractId, contractItemId) => {
4
+ const response = await client.contract.getDetailOfContractItem({
5
+ contractId,
6
+ contractItemId,
7
+ });
8
+ if (response.status === 200) {
9
+ return response.data;
10
+ }
11
+ assertStatus(response, 404);
12
+ },
13
+ });
@@ -0,0 +1,2 @@
1
+ export * from "./api.js";
2
+ export * from "./types.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./ContractItem.js";
2
+ export * from "./types.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./Contract/index.js";
2
+ export * from "./ContractItem/index.js";