@updraft-solutions/mcrit-sdk 0.1.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.
- package/README.md +240 -0
- package/dist/chunk-2DRKSYW4.cjs +99 -0
- package/dist/chunk-2M32EOYI.js +145 -0
- package/dist/chunk-AN55SAGU.js +1189 -0
- package/dist/chunk-D5DUVW34.js +176 -0
- package/dist/chunk-HQSF3WGF.cjs +14 -0
- package/dist/chunk-JGIAOBZI.js +99 -0
- package/dist/chunk-JRVRIKNM.cjs +168 -0
- package/dist/chunk-LVTDNDWE.cjs +124 -0
- package/dist/chunk-LXNCAKJZ.js +0 -0
- package/dist/chunk-MF7G76QS.cjs +176 -0
- package/dist/chunk-MI4YBENQ.cjs +145 -0
- package/dist/chunk-MOOGM3DW.cjs +1 -0
- package/dist/chunk-NQV2D3FJ.js +14 -0
- package/dist/chunk-TJXWL42D.js +124 -0
- package/dist/chunk-VYT5KQWF.js +168 -0
- package/dist/chunk-XKZQ5W7E.cjs +1189 -0
- package/dist/courses/index.cjs +7 -0
- package/dist/courses/index.d.cts +58 -0
- package/dist/courses/index.d.ts +58 -0
- package/dist/courses/index.js +7 -0
- package/dist/crew/index.cjs +10 -0
- package/dist/crew/index.d.cts +102 -0
- package/dist/crew/index.d.ts +102 -0
- package/dist/crew/index.js +10 -0
- package/dist/crew/vue.cjs +34 -0
- package/dist/crew/vue.d.cts +31 -0
- package/dist/crew/vue.d.ts +31 -0
- package/dist/crew/vue.js +34 -0
- package/dist/format/index.cjs +44 -0
- package/dist/format/index.d.cts +69 -0
- package/dist/format/index.d.ts +69 -0
- package/dist/format/index.js +44 -0
- package/dist/index.cjs +261 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +261 -0
- package/dist/media/index.cjs +30 -0
- package/dist/media/index.d.cts +89 -0
- package/dist/media/index.d.ts +89 -0
- package/dist/media/index.js +30 -0
- package/dist/models-CY3MmvCg.d.cts +33801 -0
- package/dist/models-CY3MmvCg.d.ts +33801 -0
- package/dist/money/index.cjs +18 -0
- package/dist/money/index.d.cts +66 -0
- package/dist/money/index.d.ts +66 -0
- package/dist/money/index.js +18 -0
- package/dist/pagination/index.cjs +6 -0
- package/dist/pagination/index.d.cts +16 -0
- package/dist/pagination/index.d.ts +16 -0
- package/dist/pagination/index.js +6 -0
- package/dist/schemas/index.cjs +158 -0
- package/dist/schemas/index.d.cts +1019 -0
- package/dist/schemas/index.d.ts +1019 -0
- package/dist/schemas/index.js +158 -0
- package/dist/types/index.cjs +1 -0
- package/dist/types/index.d.cts +143 -0
- package/dist/types/index.d.ts +143 -0
- package/dist/types/index.js +1 -0
- package/package.json +171 -0
- package/src/courses/index.ts +202 -0
- package/src/crew/index.ts +255 -0
- package/src/crew/vue.ts +70 -0
- package/src/format/index.ts +265 -0
- package/src/index.ts +76 -0
- package/src/media/index.ts +224 -0
- package/src/money/index.ts +168 -0
- package/src/pagination/index.ts +27 -0
- package/src/schemas/common.ts +73 -0
- package/src/schemas/faq.ts +94 -0
- package/src/schemas/fee.ts +37 -0
- package/src/schemas/index.ts +6 -0
- package/src/schemas/models.ts +996 -0
- package/src/schemas/report.ts +306 -0
- package/src/schemas/safety-report.ts +163 -0
- package/src/types/api.ts +37 -0
- package/src/types/compliance.ts +44 -0
- package/src/types/index.ts +3 -0
- package/src/types/models.ts +124 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// src/format/index.ts
|
|
2
|
+
import moment from "moment-timezone";
|
|
3
|
+
var DEFAULT_TZ = "UTC";
|
|
4
|
+
var DATE_FORMATS = Object.freeze({
|
|
5
|
+
DATE: "DD.MM.YYYY",
|
|
6
|
+
TIME: "HH:mm",
|
|
7
|
+
TIME_TZ: "HH:mm z",
|
|
8
|
+
DATETIME: "DD.MM.YYYY HH:mm",
|
|
9
|
+
DATETIME_TZ: "DD.MM.YYYY HH:mm z",
|
|
10
|
+
YEAR: "YYYY",
|
|
11
|
+
DAY: "DD",
|
|
12
|
+
MONTH_SHORT: "MMM"
|
|
13
|
+
});
|
|
14
|
+
var TIME_FORMATS = Object.freeze({
|
|
15
|
+
TIME: "HH:mm",
|
|
16
|
+
TIME_WITH_SECONDS: "HH:mm:ss"
|
|
17
|
+
});
|
|
18
|
+
function isValidDate(date) {
|
|
19
|
+
return moment(date).isValid();
|
|
20
|
+
}
|
|
21
|
+
function isValidDateStrict(date) {
|
|
22
|
+
return typeof date === "string" && /^\d{4}-\d{2}-\d{2}$/.test(date) && moment(date, "YYYY-MM-DD", true).isValid();
|
|
23
|
+
}
|
|
24
|
+
function formatDate(date, format = DATE_FORMATS.DATE, locale = "de") {
|
|
25
|
+
if (!isValidDateStrict(date)) {
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
return moment(date, "YYYY-MM-DD").locale(locale).format(format);
|
|
29
|
+
}
|
|
30
|
+
function formatTime(time, format = TIME_FORMATS.TIME) {
|
|
31
|
+
if (typeof time !== "string" || !time) {
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
const parts = time.trim().split(/[:.\s]/).map(Number).filter((n) => !Number.isNaN(n));
|
|
35
|
+
const [hh = 0, mm = 0, ss = 0] = parts;
|
|
36
|
+
const safeHH = Math.min(Math.max(hh, 0), 23);
|
|
37
|
+
const safeMM = Math.min(Math.max(mm, 0), 59);
|
|
38
|
+
const safeSS = Math.min(Math.max(ss, 0), 59);
|
|
39
|
+
const pad = (n) => n.toString().padStart(2, "0");
|
|
40
|
+
if (format === TIME_FORMATS.TIME) {
|
|
41
|
+
return `${pad(safeHH)}:${pad(safeMM)}`;
|
|
42
|
+
}
|
|
43
|
+
return `${pad(safeHH)}:${pad(safeMM)}:${pad(safeSS)}`;
|
|
44
|
+
}
|
|
45
|
+
function formatDateTime(dateTime, timezone = DEFAULT_TZ, format = DATE_FORMATS.DATETIME, locale = "de") {
|
|
46
|
+
if (!dateTime || !isValidDate(dateTime)) {
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
49
|
+
return moment(dateTime).locale(locale).tz(timezone).format(format);
|
|
50
|
+
}
|
|
51
|
+
function bytesToHuman(bytes) {
|
|
52
|
+
if (!bytes || bytes === 0) {
|
|
53
|
+
return "0 Bytes";
|
|
54
|
+
}
|
|
55
|
+
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
|
|
56
|
+
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
57
|
+
return `${parseFloat((bytes / 2 ** (i * 10)).toFixed(2))} ${sizes[i]}`;
|
|
58
|
+
}
|
|
59
|
+
function monthString(date) {
|
|
60
|
+
return date ? moment(date).format("MMMM YYYY") : "";
|
|
61
|
+
}
|
|
62
|
+
function getMonthFromDate(date) {
|
|
63
|
+
return date ? moment(date).format("MMM") : "";
|
|
64
|
+
}
|
|
65
|
+
function yearString(date, timezone = DEFAULT_TZ) {
|
|
66
|
+
return date ? moment(date).tz(timezone).format("YYYY") : "";
|
|
67
|
+
}
|
|
68
|
+
function percentage(value) {
|
|
69
|
+
if (value === null || value === void 0) {
|
|
70
|
+
return "-";
|
|
71
|
+
}
|
|
72
|
+
return `${parseFloat(String(value)).toFixed(2)}%`;
|
|
73
|
+
}
|
|
74
|
+
function membershipStatus(value) {
|
|
75
|
+
switch (value?.toLowerCase()) {
|
|
76
|
+
case "confirmed":
|
|
77
|
+
return { text: "Aktiv", color: "success" };
|
|
78
|
+
case "denied":
|
|
79
|
+
return { text: "Inaktiv", color: "error" };
|
|
80
|
+
case "pending":
|
|
81
|
+
return { text: "In Bearbeitung", color: "warning" };
|
|
82
|
+
default:
|
|
83
|
+
return { text: "Unbekannter Status", color: "default" };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function dayString(date, timezone = DEFAULT_TZ) {
|
|
87
|
+
return date ? moment(date).tz(timezone).format("DD") : "";
|
|
88
|
+
}
|
|
89
|
+
function dateString(date, timezone = DEFAULT_TZ) {
|
|
90
|
+
return date ? moment(date).tz(timezone).format("DD.MM.YYYY") : "";
|
|
91
|
+
}
|
|
92
|
+
function dateTimeString(date, timezone = DEFAULT_TZ, includeTimezone = false) {
|
|
93
|
+
if (!date) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
let formatted = moment(date).tz(timezone).format("DD.MM.YYYY HH:mm");
|
|
97
|
+
if (includeTimezone) {
|
|
98
|
+
formatted += ` ${moment(date).tz(timezone).format("z")}`;
|
|
99
|
+
}
|
|
100
|
+
return formatted;
|
|
101
|
+
}
|
|
102
|
+
function timeString(date, timezone = DEFAULT_TZ, includeTimezone = false) {
|
|
103
|
+
if (!date) {
|
|
104
|
+
return "";
|
|
105
|
+
}
|
|
106
|
+
let formatted = moment(date).tz(timezone).format("HH:mm");
|
|
107
|
+
if (includeTimezone) {
|
|
108
|
+
formatted += ` ${moment(date).tz(timezone).format("z")}`;
|
|
109
|
+
}
|
|
110
|
+
return formatted;
|
|
111
|
+
}
|
|
112
|
+
function timeUntil(dateTime, locale = "de") {
|
|
113
|
+
if (!dateTime) {
|
|
114
|
+
return "";
|
|
115
|
+
}
|
|
116
|
+
return moment(dateTime).locale(locale).fromNow();
|
|
117
|
+
}
|
|
118
|
+
function minutesFormatted(minutes) {
|
|
119
|
+
if (minutes == null) {
|
|
120
|
+
return "";
|
|
121
|
+
}
|
|
122
|
+
const sign = minutes < 0 ? "-" : "";
|
|
123
|
+
const abs = Math.abs(minutes);
|
|
124
|
+
const hours = Math.floor(abs / 60);
|
|
125
|
+
const remaining = abs % 60;
|
|
126
|
+
return `${sign}${hours < 10 ? "0" : ""}${hours}:${`0${remaining}`.slice(-2)}`;
|
|
127
|
+
}
|
|
128
|
+
function crewObjectToString(crew, { includeRoles = false } = {}) {
|
|
129
|
+
if (!crew) {
|
|
130
|
+
return "No Crew";
|
|
131
|
+
}
|
|
132
|
+
if (typeof crew === "string") {
|
|
133
|
+
return crew;
|
|
134
|
+
}
|
|
135
|
+
const names = crew.map((member) => {
|
|
136
|
+
if (includeRoles && member.role) {
|
|
137
|
+
return `${member.name} (${member.role})`;
|
|
138
|
+
}
|
|
139
|
+
return member.name;
|
|
140
|
+
}).filter((n) => Boolean(n)).join(", ");
|
|
141
|
+
return names.length === 0 ? "No Crew" : names;
|
|
142
|
+
}
|
|
143
|
+
function timeDiffInDays(startDateTime, endDateTime) {
|
|
144
|
+
if (!startDateTime || !endDateTime) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
const diff = moment(endDateTime).diff(moment(startDateTime), "days");
|
|
148
|
+
return diff ? `+${diff}` : null;
|
|
149
|
+
}
|
|
150
|
+
function bookingDuration(booking) {
|
|
151
|
+
const minutes = moment(booking.etaZ).diff(moment(booking.etdZ), "minutes");
|
|
152
|
+
return `${`0${Math.floor(minutes / 60)}`.slice(-2)}:${`0${minutes % 60}`.slice(-2)}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export {
|
|
156
|
+
DATE_FORMATS,
|
|
157
|
+
TIME_FORMATS,
|
|
158
|
+
formatDate,
|
|
159
|
+
formatTime,
|
|
160
|
+
formatDateTime,
|
|
161
|
+
bytesToHuman,
|
|
162
|
+
monthString,
|
|
163
|
+
getMonthFromDate,
|
|
164
|
+
yearString,
|
|
165
|
+
percentage,
|
|
166
|
+
membershipStatus,
|
|
167
|
+
dayString,
|
|
168
|
+
dateString,
|
|
169
|
+
dateTimeString,
|
|
170
|
+
timeString,
|
|
171
|
+
timeUntil,
|
|
172
|
+
minutesFormatted,
|
|
173
|
+
crewObjectToString,
|
|
174
|
+
timeDiffInDays,
|
|
175
|
+
bookingDuration
|
|
176
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/pagination/index.ts
|
|
2
|
+
function paginationMeta(options, total) {
|
|
3
|
+
const start = (options.page - 1) * options.itemsPerPage + 1;
|
|
4
|
+
const end = Math.min(options.page * options.itemsPerPage, total);
|
|
5
|
+
return {
|
|
6
|
+
start: total === 0 ? 0 : start,
|
|
7
|
+
end,
|
|
8
|
+
total
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
exports.paginationMeta = paginationMeta;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// src/money/index.ts
|
|
2
|
+
import Dinero from "dinero.js";
|
|
3
|
+
import { filter, head, sortBy } from "lodash-es";
|
|
4
|
+
Dinero.globalLocale = "de-DE";
|
|
5
|
+
function money(amount) {
|
|
6
|
+
try {
|
|
7
|
+
let parsed = amount;
|
|
8
|
+
if (parsed && typeof parsed === "object") {
|
|
9
|
+
const obj = parsed;
|
|
10
|
+
if (obj.value && typeof obj.value === "object" && typeof obj.value.amount !== "undefined") {
|
|
11
|
+
parsed = obj.value.amount;
|
|
12
|
+
} else if (typeof obj.amount !== "undefined") {
|
|
13
|
+
parsed = obj.amount;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const int = parseInt(String(parsed ?? "0"), 10);
|
|
17
|
+
if (Number.isNaN(int)) {
|
|
18
|
+
throw new Error("Invalid amount");
|
|
19
|
+
}
|
|
20
|
+
return Dinero({ amount: int, currency: "EUR" });
|
|
21
|
+
} catch (e) {
|
|
22
|
+
console.error("[mcrit-sdk/money] failed to parse amount:", amount, e);
|
|
23
|
+
return Dinero({ amount: 0, currency: "EUR" });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function moneyFormatted(dinero) {
|
|
27
|
+
return dinero ? dinero.toFormat() : "";
|
|
28
|
+
}
|
|
29
|
+
function parsePrice(price) {
|
|
30
|
+
if (!price) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
...price,
|
|
35
|
+
net_total: money(price.net_total?.amount ?? 0),
|
|
36
|
+
gross_total: money(price.gross_total?.amount ?? 0)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function priceFor(parsed, netGross) {
|
|
40
|
+
if (netGross === "net") {
|
|
41
|
+
return parsed.net_total;
|
|
42
|
+
}
|
|
43
|
+
if (netGross === "gross") {
|
|
44
|
+
return parsed.gross_total;
|
|
45
|
+
}
|
|
46
|
+
return parsed;
|
|
47
|
+
}
|
|
48
|
+
function parseFee(fee) {
|
|
49
|
+
if (!fee) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
currentPrice(netGross = null) {
|
|
54
|
+
const parsed = parsePrice(fee.price ?? null);
|
|
55
|
+
return parsed ? priceFor(parsed, netGross) : null;
|
|
56
|
+
},
|
|
57
|
+
upcomingPrice(netGross = null) {
|
|
58
|
+
const now = Date.now();
|
|
59
|
+
const upcoming = head(
|
|
60
|
+
sortBy(
|
|
61
|
+
filter(fee.prices ?? [], (p) => {
|
|
62
|
+
const t = p.valid_from ? Date.parse(p.valid_from) : NaN;
|
|
63
|
+
return Number.isFinite(t) && t > now;
|
|
64
|
+
}),
|
|
65
|
+
(p) => Date.parse(p.valid_from ?? "")
|
|
66
|
+
)
|
|
67
|
+
);
|
|
68
|
+
if (!upcoming) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const parsed = parsePrice(upcoming);
|
|
72
|
+
return parsed ? priceFor(parsed, netGross) : null;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function displayFee(fee, netGross = "gross", fallback = "Keine Geb\xFChr hinterlegt") {
|
|
77
|
+
const current = parseFee(fee)?.currentPrice(netGross);
|
|
78
|
+
if (current && "toFormat" in current) {
|
|
79
|
+
return current.toFormat();
|
|
80
|
+
}
|
|
81
|
+
return fallback;
|
|
82
|
+
}
|
|
83
|
+
function fromCents(amount) {
|
|
84
|
+
return Dinero({ amount, currency: "EUR" });
|
|
85
|
+
}
|
|
86
|
+
function formatToEuroString(amount) {
|
|
87
|
+
const cents = parseInt(String(amount ?? "0"), 10);
|
|
88
|
+
return `\u20AC ${fromCents(Number.isNaN(cents) ? 0 : cents).setLocale("de-DE").toFormat("0,0.00")}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export {
|
|
92
|
+
money,
|
|
93
|
+
moneyFormatted,
|
|
94
|
+
parsePrice,
|
|
95
|
+
parseFee,
|
|
96
|
+
displayFee,
|
|
97
|
+
fromCents,
|
|
98
|
+
formatToEuroString
|
|
99
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/media/index.ts
|
|
2
|
+
var HeaderConversion = {
|
|
3
|
+
Dense: "header_dense",
|
|
4
|
+
Large: "header_large"
|
|
5
|
+
};
|
|
6
|
+
var ImageConversion = {
|
|
7
|
+
GalleryMedium: "gallery_medium",
|
|
8
|
+
GalleryFull: "gallery_large",
|
|
9
|
+
Thumb: "thumb"
|
|
10
|
+
};
|
|
11
|
+
var DocumentConversion = {
|
|
12
|
+
Preview: "document_preview"
|
|
13
|
+
};
|
|
14
|
+
var ThumbnailConversion = {
|
|
15
|
+
Square: "thumb"
|
|
16
|
+
};
|
|
17
|
+
var AvatarConversion = {
|
|
18
|
+
Square: "thumb"
|
|
19
|
+
};
|
|
20
|
+
var MediaType = {
|
|
21
|
+
IMAGE: "image",
|
|
22
|
+
DOCUMENT: "document",
|
|
23
|
+
VIDEO: "video",
|
|
24
|
+
AUDIO: "audio",
|
|
25
|
+
UNKNOWN: "unknown"
|
|
26
|
+
};
|
|
27
|
+
var MimeTypes = {
|
|
28
|
+
IMAGES: [
|
|
29
|
+
"image/jpeg",
|
|
30
|
+
"image/jpg",
|
|
31
|
+
"image/png",
|
|
32
|
+
"image/gif",
|
|
33
|
+
"image/webp",
|
|
34
|
+
"image/svg+xml",
|
|
35
|
+
"image/bmp",
|
|
36
|
+
"image/tiff"
|
|
37
|
+
],
|
|
38
|
+
DOCUMENTS: [
|
|
39
|
+
"application/pdf",
|
|
40
|
+
"application/msword",
|
|
41
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
42
|
+
"application/vnd.ms-excel",
|
|
43
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
44
|
+
"application/vnd.ms-powerpoint",
|
|
45
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
46
|
+
"text/plain",
|
|
47
|
+
"text/csv",
|
|
48
|
+
"application/rtf"
|
|
49
|
+
],
|
|
50
|
+
VIDEOS: [
|
|
51
|
+
"video/mp4",
|
|
52
|
+
"video/webm",
|
|
53
|
+
"video/ogg",
|
|
54
|
+
"video/avi",
|
|
55
|
+
"video/mov",
|
|
56
|
+
"video/wmv",
|
|
57
|
+
"video/flv",
|
|
58
|
+
"video/x-matroska"
|
|
59
|
+
],
|
|
60
|
+
AUDIO: ["audio/mpeg", "audio/wav", "audio/ogg", "audio/aac", "audio/flac", "audio/mp3"]
|
|
61
|
+
};
|
|
62
|
+
function getMediaType(mimeType) {
|
|
63
|
+
if (!mimeType) {
|
|
64
|
+
return MediaType.UNKNOWN;
|
|
65
|
+
}
|
|
66
|
+
const mt = mimeType;
|
|
67
|
+
if (MimeTypes.IMAGES.includes(mt)) return MediaType.IMAGE;
|
|
68
|
+
if (MimeTypes.DOCUMENTS.includes(mt)) return MediaType.DOCUMENT;
|
|
69
|
+
if (MimeTypes.VIDEOS.includes(mt)) return MediaType.VIDEO;
|
|
70
|
+
if (MimeTypes.AUDIO.includes(mt)) return MediaType.AUDIO;
|
|
71
|
+
return MediaType.UNKNOWN;
|
|
72
|
+
}
|
|
73
|
+
function getDocumentIcon(mimeType) {
|
|
74
|
+
switch (mimeType) {
|
|
75
|
+
case "application/pdf":
|
|
76
|
+
return "mdi-file-pdf-box";
|
|
77
|
+
case "application/msword":
|
|
78
|
+
case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
|
|
79
|
+
return "mdi-file-word";
|
|
80
|
+
case "application/vnd.ms-excel":
|
|
81
|
+
case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
|
|
82
|
+
return "mdi-file-excel";
|
|
83
|
+
case "application/vnd.ms-powerpoint":
|
|
84
|
+
case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
|
|
85
|
+
return "mdi-file-powerpoint";
|
|
86
|
+
case "text/plain":
|
|
87
|
+
return "mdi-file-document";
|
|
88
|
+
case "text/csv":
|
|
89
|
+
return "mdi-file-delimited";
|
|
90
|
+
default:
|
|
91
|
+
return "mdi-file";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function getMediaIcon(mimeType) {
|
|
95
|
+
const t = getMediaType(mimeType);
|
|
96
|
+
switch (t) {
|
|
97
|
+
case MediaType.IMAGE:
|
|
98
|
+
return "mdi-image";
|
|
99
|
+
case MediaType.VIDEO:
|
|
100
|
+
return "mdi-video";
|
|
101
|
+
case MediaType.AUDIO:
|
|
102
|
+
return "mdi-music";
|
|
103
|
+
case MediaType.DOCUMENT:
|
|
104
|
+
return getDocumentIcon(mimeType);
|
|
105
|
+
default:
|
|
106
|
+
return "mdi-file";
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function canPreview(mimeType) {
|
|
110
|
+
const t = getMediaType(mimeType);
|
|
111
|
+
return t === MediaType.IMAGE || t === MediaType.VIDEO || t === MediaType.AUDIO;
|
|
112
|
+
}
|
|
113
|
+
function getMediaDisplayName(mimeType, labels = {}) {
|
|
114
|
+
const defaults = {
|
|
115
|
+
image: "Bild",
|
|
116
|
+
video: "Video",
|
|
117
|
+
audio: "Audio",
|
|
118
|
+
document: "Dokument",
|
|
119
|
+
unknown: "Datei"
|
|
120
|
+
};
|
|
121
|
+
const t = getMediaType(mimeType);
|
|
122
|
+
return _nullishCoalesce(labels[t], () => ( defaults[t]));
|
|
123
|
+
}
|
|
124
|
+
function mapSingle(m) {
|
|
125
|
+
const galleryFull = _nullishCoalesce(_optionalChain([m, 'optionalAccess', _ => _.conversions, 'optionalAccess', _2 => _2[ImageConversion.GalleryFull]]), () => ( _optionalChain([m, 'optionalAccess', _3 => _3.url])));
|
|
126
|
+
const thumb = _nullishCoalesce(_optionalChain([m, 'optionalAccess', _4 => _4.conversions, 'optionalAccess', _5 => _5[ImageConversion.Thumb]]), () => ( _optionalChain([m, 'optionalAccess', _6 => _6.url])));
|
|
127
|
+
const documentPreview = _nullishCoalesce(_optionalChain([m, 'optionalAccess', _7 => _7.conversions, 'optionalAccess', _8 => _8[DocumentConversion.Preview]]), () => ( null));
|
|
128
|
+
return {
|
|
129
|
+
href: galleryFull,
|
|
130
|
+
src: galleryFull,
|
|
131
|
+
thumbnail: thumb,
|
|
132
|
+
documentPreview,
|
|
133
|
+
mediaType: getMediaType(_optionalChain([m, 'optionalAccess', _9 => _9.mime_type])),
|
|
134
|
+
mimeType: _optionalChain([m, 'optionalAccess', _10 => _10.mime_type]),
|
|
135
|
+
icon: getMediaIcon(_optionalChain([m, 'optionalAccess', _11 => _11.mime_type])),
|
|
136
|
+
previewable: canPreview(_optionalChain([m, 'optionalAccess', _12 => _12.mime_type])),
|
|
137
|
+
fileName: _nullishCoalesce(_optionalChain([m, 'optionalAccess', _13 => _13.file_name]), () => ( _optionalChain([m, 'optionalAccess', _14 => _14.name]))),
|
|
138
|
+
size: _optionalChain([m, 'optionalAccess', _15 => _15.size]),
|
|
139
|
+
alt: _nullishCoalesce(_nullishCoalesce(_optionalChain([m, 'optionalAccess', _16 => _16.alt]), () => ( _optionalChain([m, 'optionalAccess', _17 => _17.description]))), () => ( _optionalChain([m, 'optionalAccess', _18 => _18.file_name]))),
|
|
140
|
+
title: _nullishCoalesce(_nullishCoalesce(_optionalChain([m, 'optionalAccess', _19 => _19.title]), () => ( _optionalChain([m, 'optionalAccess', _20 => _20.description]))), () => ( _optionalChain([m, 'optionalAccess', _21 => _21.file_name]))),
|
|
141
|
+
original: m
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function mapMediaConversions(media) {
|
|
145
|
+
if (!media) {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
if (Array.isArray(media)) {
|
|
149
|
+
return media.map(mapSingle);
|
|
150
|
+
}
|
|
151
|
+
return [mapSingle(media)];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
exports.HeaderConversion = HeaderConversion; exports.ImageConversion = ImageConversion; exports.DocumentConversion = DocumentConversion; exports.ThumbnailConversion = ThumbnailConversion; exports.AvatarConversion = AvatarConversion; exports.MediaType = MediaType; exports.MimeTypes = MimeTypes; exports.getMediaType = getMediaType; exports.getDocumentIcon = getDocumentIcon; exports.getMediaIcon = getMediaIcon; exports.canPreview = canPreview; exports.getMediaDisplayName = getMediaDisplayName; exports.mapMediaConversions = mapMediaConversions;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunk2DRKSYW4cjs = require('./chunk-2DRKSYW4.cjs');
|
|
5
|
+
|
|
6
|
+
// src/courses/index.ts
|
|
7
|
+
var _lodashes = require('lodash-es');
|
|
8
|
+
var DEFAULT_VARIANT = "default";
|
|
9
|
+
function getPivotData(courseFee) {
|
|
10
|
+
return {
|
|
11
|
+
count: _nullishCoalesce(_nullishCoalesce(_optionalChain([courseFee, 'access', _ => _.pivot, 'optionalAccess', _2 => _2.count]), () => ( courseFee.count)), () => ( 1)),
|
|
12
|
+
variant: _nullishCoalesce(_nullishCoalesce(_optionalChain([courseFee, 'access', _3 => _3.pivot, 'optionalAccess', _4 => _4.variant]), () => ( courseFee.variant)), () => ( null)),
|
|
13
|
+
isOptional: _nullishCoalesce(_nullishCoalesce(_optionalChain([courseFee, 'access', _5 => _5.pivot, 'optionalAccess', _6 => _6.is_optional]), () => ( courseFee.is_optional)), () => ( false)),
|
|
14
|
+
sortOrder: _nullishCoalesce(_nullishCoalesce(_optionalChain([courseFee, 'access', _7 => _7.pivot, 'optionalAccess', _8 => _8.sort_order]), () => ( courseFee.sort_order)), () => ( 0))
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function getFeeData(courseFee) {
|
|
18
|
+
return _nullishCoalesce(courseFee.fee, () => ( courseFee));
|
|
19
|
+
}
|
|
20
|
+
function getCourseFeeTitle(courseFee) {
|
|
21
|
+
const feeData = getFeeData(courseFee);
|
|
22
|
+
if (feeData.title) {
|
|
23
|
+
return feeData.title;
|
|
24
|
+
}
|
|
25
|
+
if (feeData.ident) {
|
|
26
|
+
return feeData.ident;
|
|
27
|
+
}
|
|
28
|
+
if (courseFee.id) {
|
|
29
|
+
return `Fee #${courseFee.id}`;
|
|
30
|
+
}
|
|
31
|
+
return "Unknown fee";
|
|
32
|
+
}
|
|
33
|
+
function sortBySortOrder(items) {
|
|
34
|
+
return [...items].sort((a, b) => a.sortOrder - b.sortOrder);
|
|
35
|
+
}
|
|
36
|
+
function calculateTotal(parsedFees) {
|
|
37
|
+
return parsedFees.reduce(
|
|
38
|
+
(total, pf) => pf.lineTotal ? total.add(pf.lineTotal) : total,
|
|
39
|
+
_chunk2DRKSYW4cjs.money.call(void 0, 0)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
function asDinero(price) {
|
|
43
|
+
if (!price) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
if ("multiply" in price && typeof price.multiply === "function") {
|
|
47
|
+
return price;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function parseCourseFee(courseFee, netGross) {
|
|
52
|
+
const feeData = getFeeData(courseFee);
|
|
53
|
+
const pivotData = getPivotData(courseFee);
|
|
54
|
+
const parsed = _chunk2DRKSYW4cjs.parseFee.call(void 0, feeData);
|
|
55
|
+
const unitPrice = asDinero(_nullishCoalesce(_optionalChain([parsed, 'optionalAccess', _9 => _9.currentPrice, 'call', _10 => _10(netGross)]), () => ( null)));
|
|
56
|
+
const lineTotal = unitPrice ? unitPrice.multiply(pivotData.count) : null;
|
|
57
|
+
const upcomingRaw = _nullishCoalesce(_optionalChain([parsed, 'optionalAccess', _11 => _11.upcomingPrice, 'call', _12 => _12(null)]), () => ( null));
|
|
58
|
+
const hasUpcomingPrice = upcomingRaw !== null;
|
|
59
|
+
const upcomingParsed = upcomingRaw && !("multiply" in upcomingRaw) ? upcomingRaw : null;
|
|
60
|
+
const upcomingPrice = upcomingParsed ? netGross === "net" ? upcomingParsed.net_total : upcomingParsed.gross_total : null;
|
|
61
|
+
return {
|
|
62
|
+
fee: courseFee,
|
|
63
|
+
count: pivotData.count,
|
|
64
|
+
variant: pivotData.variant || DEFAULT_VARIANT,
|
|
65
|
+
isOptional: pivotData.isOptional,
|
|
66
|
+
sortOrder: pivotData.sortOrder,
|
|
67
|
+
unitPrice,
|
|
68
|
+
lineTotal,
|
|
69
|
+
title: getCourseFeeTitle(courseFee),
|
|
70
|
+
hasUpcomingPrice,
|
|
71
|
+
upcomingPrice,
|
|
72
|
+
upcomingPriceValidFrom: _nullishCoalesce(_optionalChain([upcomingParsed, 'optionalAccess', _13 => _13.valid_from]), () => ( null))
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function parseCourse(course) {
|
|
76
|
+
if (!course) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
totalCost(netGross = "gross") {
|
|
81
|
+
const fees = _nullishCoalesce(course.fees, () => ( []));
|
|
82
|
+
if (fees.length === 0) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const parsed = fees.map((f) => parseCourseFee(f, netGross));
|
|
86
|
+
const total = calculateTotal(parsed);
|
|
87
|
+
return total.getAmount() === 0 ? null : total;
|
|
88
|
+
},
|
|
89
|
+
feesWithCost(netGross = "gross") {
|
|
90
|
+
const fees = _nullishCoalesce(course.fees, () => ( []));
|
|
91
|
+
return sortBySortOrder(fees.map((f) => parseCourseFee(f, netGross)));
|
|
92
|
+
},
|
|
93
|
+
variants(netGross = "gross") {
|
|
94
|
+
const fees = _nullishCoalesce(course.fees, () => ( []));
|
|
95
|
+
if (fees.length === 0) {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
const parsed = fees.map((f) => parseCourseFee(f, netGross));
|
|
99
|
+
const grouped = _lodashes.groupBy.call(void 0, parsed, (pf) => pf.variant);
|
|
100
|
+
const commonFees = _nullishCoalesce(grouped[DEFAULT_VARIANT], () => ( []));
|
|
101
|
+
if (Object.keys(grouped).length === 1 && commonFees.length > 0) {
|
|
102
|
+
return [
|
|
103
|
+
{
|
|
104
|
+
variant: DEFAULT_VARIANT,
|
|
105
|
+
fees: sortBySortOrder(commonFees),
|
|
106
|
+
totalCost: calculateTotal(commonFees)
|
|
107
|
+
}
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
return Object.entries(grouped).filter(([variant]) => variant !== DEFAULT_VARIANT).map(([variant, variantFees]) => {
|
|
111
|
+
const all = sortBySortOrder([...variantFees, ...commonFees]);
|
|
112
|
+
return {
|
|
113
|
+
variant,
|
|
114
|
+
fees: all,
|
|
115
|
+
totalCost: calculateTotal(all)
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
exports.parseCourse = parseCourse;
|
|
File without changes
|