@mittwald/api-models 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +300 -0
- package/dist/index.d.mts +16601 -0
- package/dist/index.d.ts +16601 -0
- package/dist/index.mjs +704 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react.d.mts +17 -0
- package/dist/react.d.ts +17 -0
- package/dist/react.mjs +17 -0
- package/dist/react.mjs.map +1 -0
- package/dist/shared/api-models.54184fa2.mjs +25 -0
- package/dist/shared/api-models.54184fa2.mjs.map +1 -0
- package/package.json +80 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
import { assertStatus } from '@mittwald/api-client';
|
|
2
|
+
import { assertOneOfStatus } from '@mittwald/api-client-commons';
|
|
3
|
+
import { classes } from 'polytype';
|
|
4
|
+
import deepFreezeLib from 'another-deep-freeze';
|
|
5
|
+
import { w as withAsyncResourceVariant } from './shared/api-models.54184fa2.mjs';
|
|
6
|
+
|
|
7
|
+
const config = {
|
|
8
|
+
behaviors: {
|
|
9
|
+
project: void 0,
|
|
10
|
+
server: void 0,
|
|
11
|
+
customer: void 0,
|
|
12
|
+
ingress: void 0,
|
|
13
|
+
appInstallation: void 0
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const apiProjectBehaviors = (client) => ({
|
|
18
|
+
find: async (id) => {
|
|
19
|
+
const response = await client.project.getProject({
|
|
20
|
+
projectId: id
|
|
21
|
+
});
|
|
22
|
+
if (response.status === 200) {
|
|
23
|
+
return response.data;
|
|
24
|
+
}
|
|
25
|
+
assertOneOfStatus(response, [403]);
|
|
26
|
+
},
|
|
27
|
+
list: async (query) => {
|
|
28
|
+
const response = await client.project.listProjects({
|
|
29
|
+
queryParameters: query
|
|
30
|
+
});
|
|
31
|
+
assertStatus(response, 200);
|
|
32
|
+
return response.data;
|
|
33
|
+
},
|
|
34
|
+
create: async (serverId, description) => {
|
|
35
|
+
const response = await client.project.createProject({
|
|
36
|
+
serverId,
|
|
37
|
+
data: {
|
|
38
|
+
description
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
assertStatus(response, 201);
|
|
42
|
+
return response.data;
|
|
43
|
+
},
|
|
44
|
+
leave: async (id) => {
|
|
45
|
+
const response = await client.project.leaveProject({
|
|
46
|
+
projectId: id
|
|
47
|
+
});
|
|
48
|
+
assertStatus(response, 204);
|
|
49
|
+
},
|
|
50
|
+
delete: async (id) => {
|
|
51
|
+
const response = await client.project.deleteProject({
|
|
52
|
+
projectId: id
|
|
53
|
+
});
|
|
54
|
+
assertStatus(response, 204);
|
|
55
|
+
},
|
|
56
|
+
updateDescription: async (id, description) => {
|
|
57
|
+
const response = await client.project.updateProjectDescription({
|
|
58
|
+
projectId: id,
|
|
59
|
+
data: {
|
|
60
|
+
description
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
assertStatus(response, 200);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const apiServerBehaviors = (client) => ({
|
|
68
|
+
find: async (id) => {
|
|
69
|
+
const response = await client.project.getServer({
|
|
70
|
+
serverId: id
|
|
71
|
+
});
|
|
72
|
+
if (response.status === 200) {
|
|
73
|
+
return response.data;
|
|
74
|
+
}
|
|
75
|
+
assertOneOfStatus(response, [403, 404]);
|
|
76
|
+
},
|
|
77
|
+
list: async (query) => {
|
|
78
|
+
const response = await client.project.listServers({
|
|
79
|
+
queryParameters: query
|
|
80
|
+
});
|
|
81
|
+
assertStatus(response, 200);
|
|
82
|
+
return response.data;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const apiCustomerBehaviors = (client) => ({
|
|
87
|
+
find: async (id) => {
|
|
88
|
+
const response = await client.customer.getCustomer({
|
|
89
|
+
customerId: id
|
|
90
|
+
});
|
|
91
|
+
if (response.status === 200) {
|
|
92
|
+
return response.data;
|
|
93
|
+
}
|
|
94
|
+
assertOneOfStatus(response, [403]);
|
|
95
|
+
},
|
|
96
|
+
list: async (query) => {
|
|
97
|
+
const response = await client.customer.listCustomers({
|
|
98
|
+
queryParameters: query
|
|
99
|
+
});
|
|
100
|
+
assertStatus(response, 200);
|
|
101
|
+
return response.data;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const apiIngressBehaviors = (client) => ({
|
|
106
|
+
find: async (id) => {
|
|
107
|
+
const response = await client.domain.ingressGetSpecific({
|
|
108
|
+
ingressId: id
|
|
109
|
+
});
|
|
110
|
+
if (response.status === 200) {
|
|
111
|
+
return response.data;
|
|
112
|
+
}
|
|
113
|
+
assertOneOfStatus(response, [403]);
|
|
114
|
+
},
|
|
115
|
+
list: async (query = {}) => {
|
|
116
|
+
const { projectId } = query;
|
|
117
|
+
if (projectId) {
|
|
118
|
+
const response = await client.domain.ingressListForProject({
|
|
119
|
+
projectId
|
|
120
|
+
});
|
|
121
|
+
assertStatus(response, 200);
|
|
122
|
+
return response.data;
|
|
123
|
+
} else {
|
|
124
|
+
const response = await client.domain.ingressListAccessible();
|
|
125
|
+
assertStatus(response, 200);
|
|
126
|
+
return response.data;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const apiAppInstallationBehaviors = (client) => ({
|
|
132
|
+
find: async (id) => {
|
|
133
|
+
const response = await client.appInstallation.getAppInstallation({
|
|
134
|
+
appInstallationId: id
|
|
135
|
+
});
|
|
136
|
+
if (response.status === 200) {
|
|
137
|
+
return response.data;
|
|
138
|
+
}
|
|
139
|
+
assertOneOfStatus(response, [403]);
|
|
140
|
+
},
|
|
141
|
+
list: async (query) => {
|
|
142
|
+
const response = await client.appInstallation.listAppInstallations({
|
|
143
|
+
queryParameters: query
|
|
144
|
+
});
|
|
145
|
+
assertStatus(response, 200);
|
|
146
|
+
return response.data;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const setupApiBehaviors = (client) => {
|
|
151
|
+
config.behaviors.project = apiProjectBehaviors(client);
|
|
152
|
+
config.behaviors.server = apiServerBehaviors(client);
|
|
153
|
+
config.behaviors.customer = apiCustomerBehaviors(client);
|
|
154
|
+
config.behaviors.ingress = apiIngressBehaviors(client);
|
|
155
|
+
config.behaviors.appInstallation = apiAppInstallationBehaviors(client);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const deepFreeze = deepFreezeLib.default;
|
|
159
|
+
|
|
160
|
+
var __defProp$8 = Object.defineProperty;
|
|
161
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
162
|
+
var __publicField$8 = (obj, key, value) => {
|
|
163
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
164
|
+
return value;
|
|
165
|
+
};
|
|
166
|
+
class DataModel {
|
|
167
|
+
constructor(data) {
|
|
168
|
+
__publicField$8(this, "data");
|
|
169
|
+
this.data = deepFreeze(data);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
class ObjectNotFoundError extends Error {
|
|
174
|
+
constructor(type, refName) {
|
|
175
|
+
super(`${type}@${refName} not found`);
|
|
176
|
+
this.name = "ObjectNotFoundError";
|
|
177
|
+
Object.setPrototypeOf(this, ObjectNotFoundError.prototype);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function assertObjectFound(obj, theClass, refIdOrObject) {
|
|
182
|
+
if (obj === void 0) {
|
|
183
|
+
const refName = typeof refIdOrObject === "string" ? refIdOrObject : refIdOrObject.toString();
|
|
184
|
+
throw new ObjectNotFoundError(theClass.name, refName);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
var __defProp$7 = Object.defineProperty;
|
|
189
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
190
|
+
var __publicField$7 = (obj, key, value) => {
|
|
191
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
192
|
+
return value;
|
|
193
|
+
};
|
|
194
|
+
class ReferenceModel {
|
|
195
|
+
constructor(id) {
|
|
196
|
+
__publicField$7(this, "id");
|
|
197
|
+
this.id = id;
|
|
198
|
+
}
|
|
199
|
+
describe() {
|
|
200
|
+
return `${this.constructor.name}@${this.id}`;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const uuidRegex = RegExp(
|
|
205
|
+
"^[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$"
|
|
206
|
+
);
|
|
207
|
+
const isUuid = (testString) => uuidRegex.test(testString);
|
|
208
|
+
|
|
209
|
+
var __defProp$6 = Object.defineProperty;
|
|
210
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
211
|
+
var __publicField$6 = (obj, key, value) => {
|
|
212
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
213
|
+
return value;
|
|
214
|
+
};
|
|
215
|
+
const _Server = class _Server extends ReferenceModel {
|
|
216
|
+
constructor() {
|
|
217
|
+
super(...arguments);
|
|
218
|
+
__publicField$6(this, "listProjects", withAsyncResourceVariant(
|
|
219
|
+
async (query = {}) => {
|
|
220
|
+
return Project.list({
|
|
221
|
+
...query,
|
|
222
|
+
serverId: await this.getUuid()
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
));
|
|
226
|
+
__publicField$6(this, "getDetailed", withAsyncResourceVariant(
|
|
227
|
+
() => ServerDetailed.get(this.id)
|
|
228
|
+
));
|
|
229
|
+
}
|
|
230
|
+
static ofId(id) {
|
|
231
|
+
return new _Server(id);
|
|
232
|
+
}
|
|
233
|
+
async getUuid() {
|
|
234
|
+
return _Server.getUuid(this.id);
|
|
235
|
+
}
|
|
236
|
+
static async getUuid(shortIdOrUuid) {
|
|
237
|
+
if (isUuid(shortIdOrUuid)) {
|
|
238
|
+
return shortIdOrUuid;
|
|
239
|
+
}
|
|
240
|
+
const allServers = await ServerListItem.list();
|
|
241
|
+
const uuid = allServers.find((p) => p.data.shortId === shortIdOrUuid)?.id;
|
|
242
|
+
assertObjectFound(uuid, _Server, shortIdOrUuid);
|
|
243
|
+
return uuid;
|
|
244
|
+
}
|
|
245
|
+
async createProject(...parameters) {
|
|
246
|
+
return Project.create(await this.getUuid(), ...parameters);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
__publicField$6(_Server, "find", withAsyncResourceVariant(
|
|
250
|
+
async (id) => {
|
|
251
|
+
const serverData = await config.behaviors.server.find(
|
|
252
|
+
await _Server.getUuid(id)
|
|
253
|
+
);
|
|
254
|
+
if (serverData !== void 0) {
|
|
255
|
+
return new ServerDetailed([serverData]);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
));
|
|
259
|
+
__publicField$6(_Server, "get", withAsyncResourceVariant(
|
|
260
|
+
async (id) => {
|
|
261
|
+
const server = await ServerDetailed.find(id);
|
|
262
|
+
assertObjectFound(server, _Server, id);
|
|
263
|
+
return server;
|
|
264
|
+
}
|
|
265
|
+
));
|
|
266
|
+
__publicField$6(_Server, "list", withAsyncResourceVariant(
|
|
267
|
+
async (query = {}) => {
|
|
268
|
+
const projectListData = await config.behaviors.server.list(query);
|
|
269
|
+
return projectListData.map((d) => new ServerListItem([d]));
|
|
270
|
+
}
|
|
271
|
+
));
|
|
272
|
+
let Server = _Server;
|
|
273
|
+
class ServerCommon extends classes(
|
|
274
|
+
DataModel,
|
|
275
|
+
Server
|
|
276
|
+
) {
|
|
277
|
+
constructor(data) {
|
|
278
|
+
super([data], [data.id]);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
class ServerListItem extends classes(ServerCommon, DataModel) {
|
|
282
|
+
}
|
|
283
|
+
class ServerDetailed extends classes(ServerCommon, DataModel) {
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
var __defProp$5 = Object.defineProperty;
|
|
287
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
288
|
+
var __publicField$5 = (obj, key, value) => {
|
|
289
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
290
|
+
return value;
|
|
291
|
+
};
|
|
292
|
+
const _Customer = class _Customer extends ReferenceModel {
|
|
293
|
+
constructor() {
|
|
294
|
+
super(...arguments);
|
|
295
|
+
__publicField$5(this, "getDetailed", withAsyncResourceVariant(
|
|
296
|
+
() => _Customer.get(this.id)
|
|
297
|
+
));
|
|
298
|
+
}
|
|
299
|
+
static ofId(id) {
|
|
300
|
+
return new _Customer(id);
|
|
301
|
+
}
|
|
302
|
+
static async getUuid(numberOrUuid) {
|
|
303
|
+
if (isUuid(numberOrUuid)) {
|
|
304
|
+
return numberOrUuid;
|
|
305
|
+
}
|
|
306
|
+
const allCustomers = await CustomerListItem.list();
|
|
307
|
+
const uuid = allCustomers.find(
|
|
308
|
+
(p) => p.data.customerNumber === numberOrUuid
|
|
309
|
+
)?.id;
|
|
310
|
+
assertObjectFound(uuid, _Customer, numberOrUuid);
|
|
311
|
+
return uuid;
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
__publicField$5(_Customer, "find", withAsyncResourceVariant(
|
|
315
|
+
async (id) => {
|
|
316
|
+
const data = await config.behaviors.customer.find(
|
|
317
|
+
await _Customer.getUuid(id)
|
|
318
|
+
);
|
|
319
|
+
if (data !== void 0) {
|
|
320
|
+
return new CustomerDetailed(data);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
));
|
|
324
|
+
__publicField$5(_Customer, "list", withAsyncResourceVariant(
|
|
325
|
+
async (query = {}) => {
|
|
326
|
+
const data = await config.behaviors.customer.list(query);
|
|
327
|
+
return Object.freeze(data.map((d) => new CustomerListItem(d)));
|
|
328
|
+
}
|
|
329
|
+
));
|
|
330
|
+
__publicField$5(_Customer, "get", withAsyncResourceVariant(
|
|
331
|
+
async (id) => {
|
|
332
|
+
const customer = await _Customer.find(id);
|
|
333
|
+
assertObjectFound(customer, _Customer, id);
|
|
334
|
+
return customer;
|
|
335
|
+
}
|
|
336
|
+
));
|
|
337
|
+
let Customer = _Customer;
|
|
338
|
+
class CustomerCommon extends classes(
|
|
339
|
+
DataModel,
|
|
340
|
+
Customer
|
|
341
|
+
) {
|
|
342
|
+
constructor(data) {
|
|
343
|
+
super([data], [data.customerId]);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
class CustomerDetailed extends classes(
|
|
347
|
+
CustomerCommon,
|
|
348
|
+
DataModel
|
|
349
|
+
) {
|
|
350
|
+
constructor(data) {
|
|
351
|
+
super([data], [data]);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
class CustomerListItem extends classes(
|
|
355
|
+
CustomerCommon,
|
|
356
|
+
DataModel
|
|
357
|
+
) {
|
|
358
|
+
constructor(data) {
|
|
359
|
+
super([data], [data]);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
var __defProp$4 = Object.defineProperty;
|
|
364
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
365
|
+
var __publicField$4 = (obj, key, value) => {
|
|
366
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
367
|
+
return value;
|
|
368
|
+
};
|
|
369
|
+
const _AppInstallation = class _AppInstallation extends ReferenceModel {
|
|
370
|
+
constructor() {
|
|
371
|
+
super(...arguments);
|
|
372
|
+
__publicField$4(this, "getDetailed", withAsyncResourceVariant(
|
|
373
|
+
() => _AppInstallation.get(this.id)
|
|
374
|
+
));
|
|
375
|
+
}
|
|
376
|
+
static ofId(id) {
|
|
377
|
+
return new _AppInstallation(id);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
__publicField$4(_AppInstallation, "find", withAsyncResourceVariant(
|
|
381
|
+
async (id) => {
|
|
382
|
+
const data = await config.behaviors.appInstallation.find(id);
|
|
383
|
+
if (data !== void 0) {
|
|
384
|
+
return new AppInstallationDetailed(data);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
));
|
|
388
|
+
__publicField$4(_AppInstallation, "get", withAsyncResourceVariant(
|
|
389
|
+
async (id) => {
|
|
390
|
+
const appInstallation = await _AppInstallation.find(id);
|
|
391
|
+
assertObjectFound(appInstallation, _AppInstallation, id);
|
|
392
|
+
return appInstallation;
|
|
393
|
+
}
|
|
394
|
+
));
|
|
395
|
+
__publicField$4(_AppInstallation, "list", withAsyncResourceVariant(
|
|
396
|
+
async (query = {}) => {
|
|
397
|
+
const data = await config.behaviors.appInstallation.list(query);
|
|
398
|
+
return data.map((d) => new AppInstallationListItem(d));
|
|
399
|
+
}
|
|
400
|
+
));
|
|
401
|
+
let AppInstallation = _AppInstallation;
|
|
402
|
+
class AppInstallationCommon extends classes(
|
|
403
|
+
DataModel,
|
|
404
|
+
AppInstallation
|
|
405
|
+
) {
|
|
406
|
+
constructor(data) {
|
|
407
|
+
super([data], [data.id]);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
class AppInstallationDetailed extends classes(
|
|
411
|
+
AppInstallationCommon,
|
|
412
|
+
DataModel
|
|
413
|
+
) {
|
|
414
|
+
constructor(data) {
|
|
415
|
+
super([data], [data]);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
class AppInstallationListItem extends classes(
|
|
419
|
+
AppInstallationCommon,
|
|
420
|
+
DataModel
|
|
421
|
+
) {
|
|
422
|
+
constructor(data) {
|
|
423
|
+
super([data], [data]);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
var __defProp$3 = Object.defineProperty;
|
|
428
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
429
|
+
var __publicField$3 = (obj, key, value) => {
|
|
430
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
431
|
+
return value;
|
|
432
|
+
};
|
|
433
|
+
class IngressTargetBase extends DataModel {
|
|
434
|
+
constructor(path, data) {
|
|
435
|
+
super(data);
|
|
436
|
+
__publicField$3(this, "path");
|
|
437
|
+
this.path = path;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
class IngressRedirectTarget extends IngressTargetBase {
|
|
441
|
+
constructor(path, data) {
|
|
442
|
+
super(path, data);
|
|
443
|
+
__publicField$3(this, "type", "redirect");
|
|
444
|
+
__publicField$3(this, "url");
|
|
445
|
+
this.url = new URL(data.url);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
class IngressDirectoryTarget extends IngressTargetBase {
|
|
449
|
+
constructor(path, data) {
|
|
450
|
+
super(path, data);
|
|
451
|
+
__publicField$3(this, "type", "directory");
|
|
452
|
+
__publicField$3(this, "directory");
|
|
453
|
+
this.directory = data.directory;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
class IngressAppInstallationTarget extends IngressTargetBase {
|
|
457
|
+
constructor(path, data) {
|
|
458
|
+
super(path, data);
|
|
459
|
+
__publicField$3(this, "type", "appInstallation");
|
|
460
|
+
__publicField$3(this, "appInstallation");
|
|
461
|
+
this.appInstallation = AppInstallation.ofId(data.installationId);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
class IngressUndefinedTarget extends IngressTargetBase {
|
|
465
|
+
constructor() {
|
|
466
|
+
super(...arguments);
|
|
467
|
+
__publicField$3(this, "type", "undefined");
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const ingressTargetFactory = (path, data) => {
|
|
471
|
+
if ("directory" in data) {
|
|
472
|
+
return new IngressDirectoryTarget(path, data);
|
|
473
|
+
}
|
|
474
|
+
if ("url" in data) {
|
|
475
|
+
return new IngressRedirectTarget(path, data);
|
|
476
|
+
}
|
|
477
|
+
if ("installationId" in data) {
|
|
478
|
+
return new IngressAppInstallationTarget(path, data);
|
|
479
|
+
}
|
|
480
|
+
if ("useDefaultPage" in data) {
|
|
481
|
+
return new IngressUndefinedTarget(path, data);
|
|
482
|
+
}
|
|
483
|
+
throw new Error("Ingress target type is not supported.");
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
var __defProp$2 = Object.defineProperty;
|
|
487
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
488
|
+
var __publicField$2 = (obj, key, value) => {
|
|
489
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
490
|
+
return value;
|
|
491
|
+
};
|
|
492
|
+
class IngressPath extends DataModel {
|
|
493
|
+
constructor(ingress, data) {
|
|
494
|
+
super(data);
|
|
495
|
+
__publicField$2(this, "ingress");
|
|
496
|
+
__publicField$2(this, "path");
|
|
497
|
+
__publicField$2(this, "url");
|
|
498
|
+
__publicField$2(this, "target");
|
|
499
|
+
this.ingress = ingress;
|
|
500
|
+
this.path = data.path;
|
|
501
|
+
this.url = new URL(data.path, ingress.baseUrl);
|
|
502
|
+
this.target = ingressTargetFactory(this, data.target);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
var __defProp$1 = Object.defineProperty;
|
|
507
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
508
|
+
var __publicField$1 = (obj, key, value) => {
|
|
509
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
510
|
+
return value;
|
|
511
|
+
};
|
|
512
|
+
const _Ingress = class _Ingress extends ReferenceModel {
|
|
513
|
+
constructor() {
|
|
514
|
+
super(...arguments);
|
|
515
|
+
__publicField$1(this, "getDetailed", withAsyncResourceVariant(
|
|
516
|
+
() => _Ingress.get(this.id)
|
|
517
|
+
));
|
|
518
|
+
}
|
|
519
|
+
static ofId(id) {
|
|
520
|
+
return new _Ingress(id);
|
|
521
|
+
}
|
|
522
|
+
static ofHostname(hostname) {
|
|
523
|
+
return _Ingress.ofId(hostname);
|
|
524
|
+
}
|
|
525
|
+
static async getUuid(hostnameOrUuid) {
|
|
526
|
+
if (isUuid(hostnameOrUuid)) {
|
|
527
|
+
return hostnameOrUuid;
|
|
528
|
+
}
|
|
529
|
+
const allIngress = await IngressListItem.list();
|
|
530
|
+
const uuid = allIngress.find(
|
|
531
|
+
(p) => p.data.isEnabled && p.data.hostname === hostnameOrUuid
|
|
532
|
+
)?.id;
|
|
533
|
+
assertObjectFound(uuid, _Ingress, hostnameOrUuid);
|
|
534
|
+
return uuid;
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
__publicField$1(_Ingress, "list", withAsyncResourceVariant(
|
|
538
|
+
async (query = {}) => {
|
|
539
|
+
const data = await config.behaviors.ingress.list(query);
|
|
540
|
+
return data.map((d) => new IngressListItem(d));
|
|
541
|
+
}
|
|
542
|
+
));
|
|
543
|
+
__publicField$1(_Ingress, "find", withAsyncResourceVariant(
|
|
544
|
+
async (id) => {
|
|
545
|
+
const data = await config.behaviors.ingress.find(
|
|
546
|
+
await _Ingress.getUuid(id)
|
|
547
|
+
);
|
|
548
|
+
if (data !== void 0) {
|
|
549
|
+
return new IngressDetailed(data);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
));
|
|
553
|
+
__publicField$1(_Ingress, "get", withAsyncResourceVariant(
|
|
554
|
+
async (id) => {
|
|
555
|
+
const ingress = await _Ingress.find(id);
|
|
556
|
+
assertObjectFound(ingress, _Ingress, id);
|
|
557
|
+
return ingress;
|
|
558
|
+
}
|
|
559
|
+
));
|
|
560
|
+
let Ingress = _Ingress;
|
|
561
|
+
class IngressCommon extends classes(
|
|
562
|
+
DataModel,
|
|
563
|
+
Ingress
|
|
564
|
+
) {
|
|
565
|
+
constructor(data) {
|
|
566
|
+
super([data], [data.id]);
|
|
567
|
+
__publicField$1(this, "baseUrl");
|
|
568
|
+
__publicField$1(this, "paths");
|
|
569
|
+
__publicField$1(this, "defaultPath");
|
|
570
|
+
this.baseUrl = `https://${data.hostname}`;
|
|
571
|
+
this.paths = Object.freeze(data.paths.map((p) => new IngressPath(this, p)));
|
|
572
|
+
const defaultPath = this.paths.find((p) => p.path === "/");
|
|
573
|
+
if (defaultPath === void 0) {
|
|
574
|
+
throw new Error(`Ingress ${this.describe()} has no default path.`);
|
|
575
|
+
}
|
|
576
|
+
this.defaultPath = defaultPath;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
class IngressDetailed extends classes(
|
|
580
|
+
IngressCommon,
|
|
581
|
+
DataModel
|
|
582
|
+
) {
|
|
583
|
+
constructor(data) {
|
|
584
|
+
super([data], [data]);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
class IngressListItem extends classes(
|
|
588
|
+
IngressCommon,
|
|
589
|
+
DataModel
|
|
590
|
+
) {
|
|
591
|
+
constructor(data) {
|
|
592
|
+
super([data], [data]);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
var __defProp = Object.defineProperty;
|
|
597
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
598
|
+
var __publicField = (obj, key, value) => {
|
|
599
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
600
|
+
return value;
|
|
601
|
+
};
|
|
602
|
+
const _Project = class _Project extends ReferenceModel {
|
|
603
|
+
constructor() {
|
|
604
|
+
super(...arguments);
|
|
605
|
+
__publicField(this, "getDetailed", withAsyncResourceVariant(
|
|
606
|
+
() => _Project.get(this.id)
|
|
607
|
+
));
|
|
608
|
+
__publicField(this, "listIngresses", withAsyncResourceVariant(
|
|
609
|
+
() => Ingress.list({ projectId: this.id })
|
|
610
|
+
));
|
|
611
|
+
__publicField(this, "getDefaultIngress", withAsyncResourceVariant(async () => {
|
|
612
|
+
const ingresses = await _Project.ofId(this.id).listIngresses();
|
|
613
|
+
const defaultIngress = ingresses.find((i) => i.data.isDefault);
|
|
614
|
+
assertObjectFound(defaultIngress, IngressListItem, this);
|
|
615
|
+
return defaultIngress;
|
|
616
|
+
}));
|
|
617
|
+
}
|
|
618
|
+
static ofId(id) {
|
|
619
|
+
return new _Project(id);
|
|
620
|
+
}
|
|
621
|
+
static async create(serverId, description) {
|
|
622
|
+
const { id } = await config.behaviors.project.create(serverId, description);
|
|
623
|
+
return new _Project(id);
|
|
624
|
+
}
|
|
625
|
+
async getUuid() {
|
|
626
|
+
return _Project.getUuid(this.id);
|
|
627
|
+
}
|
|
628
|
+
static async getUuid(shortIdOrUuid) {
|
|
629
|
+
if (isUuid(shortIdOrUuid)) {
|
|
630
|
+
return shortIdOrUuid;
|
|
631
|
+
}
|
|
632
|
+
const allProjects = await ProjectListItem.list();
|
|
633
|
+
const uuid = allProjects.find((p) => p.data.shortId === shortIdOrUuid)?.id;
|
|
634
|
+
assertObjectFound(uuid, _Project, shortIdOrUuid);
|
|
635
|
+
return uuid;
|
|
636
|
+
}
|
|
637
|
+
async updateDescription(description) {
|
|
638
|
+
await config.behaviors.project.updateDescription(
|
|
639
|
+
await this.getUuid(),
|
|
640
|
+
description
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
async leave() {
|
|
644
|
+
await config.behaviors.project.leave(await this.getUuid());
|
|
645
|
+
}
|
|
646
|
+
async delete() {
|
|
647
|
+
await config.behaviors.project.delete(await this.getUuid());
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
__publicField(_Project, "find", withAsyncResourceVariant(
|
|
651
|
+
async (id) => {
|
|
652
|
+
const data = await config.behaviors.project.find(
|
|
653
|
+
await _Project.getUuid(id)
|
|
654
|
+
);
|
|
655
|
+
if (data !== void 0) {
|
|
656
|
+
return new ProjectDetailed(data);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
));
|
|
660
|
+
__publicField(_Project, "get", withAsyncResourceVariant(
|
|
661
|
+
async (id) => {
|
|
662
|
+
const project = await _Project.find(id);
|
|
663
|
+
assertObjectFound(project, _Project, id);
|
|
664
|
+
return project;
|
|
665
|
+
}
|
|
666
|
+
));
|
|
667
|
+
__publicField(_Project, "list", withAsyncResourceVariant(
|
|
668
|
+
async (query = {}) => {
|
|
669
|
+
const data = await config.behaviors.project.list(query);
|
|
670
|
+
return Object.freeze(data.map((d) => new ProjectListItem(d)));
|
|
671
|
+
}
|
|
672
|
+
));
|
|
673
|
+
let Project = _Project;
|
|
674
|
+
class ProjectCommon extends classes(
|
|
675
|
+
DataModel,
|
|
676
|
+
Project
|
|
677
|
+
) {
|
|
678
|
+
constructor(data) {
|
|
679
|
+
super([data], [data.id]);
|
|
680
|
+
__publicField(this, "server");
|
|
681
|
+
__publicField(this, "customer");
|
|
682
|
+
this.server = data.serverId ? Server.ofId(data.serverId) : void 0;
|
|
683
|
+
this.customer = Customer.ofId(data.customerId);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
class ProjectDetailed extends classes(
|
|
687
|
+
ProjectCommon,
|
|
688
|
+
DataModel
|
|
689
|
+
) {
|
|
690
|
+
constructor(data) {
|
|
691
|
+
super([data], [data]);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
class ProjectListItem extends classes(
|
|
695
|
+
ProjectCommon,
|
|
696
|
+
DataModel
|
|
697
|
+
) {
|
|
698
|
+
constructor(data) {
|
|
699
|
+
super([data], [data]);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
export { Customer, CustomerDetailed, CustomerListItem, Ingress, IngressCommon, IngressDetailed, IngressListItem, Project, ProjectDetailed, ProjectListItem, Server, ServerDetailed, ServerListItem, setupApiBehaviors };
|
|
704
|
+
//# sourceMappingURL=index.mjs.map
|