@deenruv/in-realization-plugin 1.0.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 (64) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +51 -0
  3. package/dist/plugin-server/api/admin-order.resolver.d.ts +7 -0
  4. package/dist/plugin-server/api/admin-order.resolver.js +42 -0
  5. package/dist/plugin-server/api/admin.resolver.d.ts +28 -0
  6. package/dist/plugin-server/api/admin.resolver.js +60 -0
  7. package/dist/plugin-server/api/order.resolver.d.ts +11 -0
  8. package/dist/plugin-server/api/order.resolver.js +43 -0
  9. package/dist/plugin-server/consts.d.ts +9 -0
  10. package/dist/plugin-server/consts.js +4 -0
  11. package/dist/plugin-server/entities/order-realization.entity.d.ts +13 -0
  12. package/dist/plugin-server/entities/order-realization.entity.js +56 -0
  13. package/dist/plugin-server/extensions/realization.extension.d.ts +2 -0
  14. package/dist/plugin-server/extensions/realization.extension.js +62 -0
  15. package/dist/plugin-server/index.d.ts +5 -0
  16. package/dist/plugin-server/index.js +79 -0
  17. package/dist/plugin-server/services/order-register.service.d.ts +28 -0
  18. package/dist/plugin-server/services/order-register.service.js +89 -0
  19. package/dist/plugin-server/services/pdf.service.d.ts +17 -0
  20. package/dist/plugin-server/services/pdf.service.js +166 -0
  21. package/dist/plugin-server/services/realization.d.ts +2 -0
  22. package/dist/plugin-server/services/realization.js +130 -0
  23. package/dist/plugin-server/services/storage.service.d.ts +23 -0
  24. package/dist/plugin-server/services/storage.service.js +134 -0
  25. package/dist/plugin-server/services/types.d.ts +18 -0
  26. package/dist/plugin-server/services/types.js +2 -0
  27. package/dist/plugin-server/zeus/const.d.ts +6 -0
  28. package/dist/plugin-server/zeus/const.js +3697 -0
  29. package/dist/plugin-server/zeus/index.d.ts +18858 -0
  30. package/dist/plugin-server/zeus/index.js +1094 -0
  31. package/dist/plugin-server/zeus/typedDocumentNode.d.ts +3 -0
  32. package/dist/plugin-server/zeus/typedDocumentNode.js +16 -0
  33. package/dist/plugin-ui/components/InRealizationButton.d.ts +2 -0
  34. package/dist/plugin-ui/components/InRealizationButton.js +35 -0
  35. package/dist/plugin-ui/components/InRealizationCard.d.ts +2 -0
  36. package/dist/plugin-ui/components/InRealizationCard.js +7 -0
  37. package/dist/plugin-ui/components/InRealizationStateModal.d.ts +5 -0
  38. package/dist/plugin-ui/components/InRealizationStateModal.js +124 -0
  39. package/dist/plugin-ui/graphql/index.d.ts +1 -0
  40. package/dist/plugin-ui/graphql/index.js +1 -0
  41. package/dist/plugin-ui/graphql/mutations.d.ts +18 -0
  42. package/dist/plugin-ui/graphql/mutations.js +9 -0
  43. package/dist/plugin-ui/graphql/queries.d.ts +5 -0
  44. package/dist/plugin-ui/graphql/queries.js +6 -0
  45. package/dist/plugin-ui/graphql/selectors.d.ts +39 -0
  46. package/dist/plugin-ui/graphql/selectors.js +25 -0
  47. package/dist/plugin-ui/index.d.ts +1 -0
  48. package/dist/plugin-ui/index.js +17 -0
  49. package/dist/plugin-ui/locales/en/index.d.ts +5 -0
  50. package/dist/plugin-ui/locales/en/index.js +2 -0
  51. package/dist/plugin-ui/locales/en/realization.json +4 -0
  52. package/dist/plugin-ui/locales/pl/index.d.ts +5 -0
  53. package/dist/plugin-ui/locales/pl/index.js +2 -0
  54. package/dist/plugin-ui/locales/pl/realization.json +4 -0
  55. package/dist/plugin-ui/translation-ns.d.ts +1 -0
  56. package/dist/plugin-ui/translation-ns.js +1 -0
  57. package/dist/plugin-ui/tsconfig.json +18 -0
  58. package/dist/plugin-ui/zeus/const.d.ts +6 -0
  59. package/dist/plugin-ui/zeus/const.js +3694 -0
  60. package/dist/plugin-ui/zeus/index.d.ts +18858 -0
  61. package/dist/plugin-ui/zeus/index.js +1086 -0
  62. package/dist/plugin-ui/zeus/typedDocumentNode.d.ts +3 -0
  63. package/dist/plugin-ui/zeus/typedDocumentNode.js +9 -0
  64. package/package.json +54 -0
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PDFService = void 0;
13
+ const jsx_runtime_1 = require("react/jsx-runtime");
14
+ const realization_js_1 = require("./realization.js");
15
+ const common_1 = require("@nestjs/common");
16
+ const core_1 = require("@deenruv/core");
17
+ const renderer_1 = require("@react-pdf/renderer");
18
+ const storage_service_js_1 = require("./storage.service.js");
19
+ let PDFService = class PDFService {
20
+ constructor(connection, storageService, productOptionGroupService, translator) {
21
+ this.connection = connection;
22
+ this.storageService = storageService;
23
+ this.productOptionGroupService = productOptionGroupService;
24
+ this.translator = translator;
25
+ this.generateRealizationDocument = async (ctx, props) => {
26
+ const { options, user, order } = props;
27
+ const lines = await Promise.all(order.lines.map(async (line) => {
28
+ var _a;
29
+ const data = await this.getOptionsFromLines(ctx, line);
30
+ const additionalAsset = (_a = options === null || options === void 0 ? void 0 : options.assets) === null || _a === void 0 ? void 0 : _a.find((asset) => Number(asset.orderLineID) === Number(line.id));
31
+ const image = (additionalAsset === null || additionalAsset === void 0 ? void 0 : additionalAsset.preview)
32
+ ? `${additionalAsset.preview}?format=jpg`
33
+ : null;
34
+ return Object.assign(Object.assign({}, line), { options: data, additionalAsset: image });
35
+ }));
36
+ const _order = Object.assign(Object.assign({}, order), { lines });
37
+ const filename = `zamowienie-${order.code}-kartka-${options.color}.pdf`;
38
+ const blob = await (0, renderer_1.pdf)((0, jsx_runtime_1.jsx)(realization_js_1.RealizationPDF, { options: options, user: user, order: _order })).toBlob();
39
+ return {
40
+ createReadStream: () => blob,
41
+ filename,
42
+ mimetype: "application/pdf",
43
+ };
44
+ };
45
+ //TODO SAME FUNCTION IS IN ORDER I SHOULD CACHE IT AS MUCH AS POSSIBLE + MOVE AS GLOBAL SERVICE?
46
+ this.getOptionsFromLines = async (ctx, orderLine) => {
47
+ try {
48
+ const modifiedCustomFields = orderLine.customFields;
49
+ let json = null;
50
+ try {
51
+ json = JSON.parse(modifiedCustomFields.attributes);
52
+ }
53
+ catch (e) {
54
+ json = null;
55
+ }
56
+ let results = [];
57
+ if (json) {
58
+ results = await Promise.all(Object.entries(json).map(async ([code, value]) => {
59
+ const cleanTag = `${code}-${value.replace(/ /g, "-")}`;
60
+ const facetValue = await this.connection
61
+ .getRepository(ctx, core_1.FacetValue)
62
+ .findOne({
63
+ where: { code: value, facet: { code } },
64
+ relations: ["facet", "customFields.image"],
65
+ });
66
+ const options = await this.productOptionGroupService.getOptionGroupsByProductId(ctx, orderLine.productVariant.productId);
67
+ if (options.length > 0) {
68
+ const option = options.find((o) => o.code === code);
69
+ if (option) {
70
+ const optionValue = option.options.find((o) => o.code === value);
71
+ if (optionValue) {
72
+ const image = await this.connection
73
+ .getRepository(ctx, core_1.Asset)
74
+ .findOne({
75
+ relations: ["tags"],
76
+ where: {
77
+ tags: { value: `${option.code}-${optionValue.code}` },
78
+ },
79
+ });
80
+ return {
81
+ code: option.name,
82
+ value: optionValue.name,
83
+ hexColor: null,
84
+ image: image || null,
85
+ asHandle: null,
86
+ cleanCode: optionValue.code,
87
+ cleanValue: optionValue.name,
88
+ };
89
+ }
90
+ }
91
+ }
92
+ let result = null;
93
+ const facetCustomFields = facetValue
94
+ ? (facetValue.facet.customFields || {})
95
+ : null;
96
+ if (facetValue && (facetCustomFields === null || facetCustomFields === void 0 ? void 0 : facetCustomFields.usedForColors)) {
97
+ const facetValueCustomFields = (facetValue.customFields ||
98
+ {});
99
+ result = {
100
+ code: this.translator.translate(facetValue.facet, ctx).name || code,
101
+ value: this.translator.translate(facetValue, ctx).name || value,
102
+ hexColor: (facetValueCustomFields === null || facetValueCustomFields === void 0 ? void 0 : facetValueCustomFields.hexColor) || null,
103
+ image: (facetValueCustomFields === null || facetValueCustomFields === void 0 ? void 0 : facetValueCustomFields.image) || null,
104
+ asHandle: (facetCustomFields === null || facetCustomFields === void 0 ? void 0 : facetCustomFields.usedForProductCreations)
105
+ ? value
106
+ : null,
107
+ cleanCode: code,
108
+ cleanValue: value,
109
+ };
110
+ }
111
+ else {
112
+ const image = await this.connection
113
+ .getRepository(ctx, core_1.Asset)
114
+ .findOne({
115
+ relations: ["tags"],
116
+ where: { tags: { value: cleanTag } },
117
+ });
118
+ result = {
119
+ code,
120
+ value,
121
+ hexColor: null,
122
+ image: image !== null && image !== void 0 ? image : null,
123
+ asHandle: null,
124
+ cleanCode: code,
125
+ cleanValue: value,
126
+ };
127
+ }
128
+ return result;
129
+ }));
130
+ }
131
+ return results;
132
+ }
133
+ catch (e) {
134
+ console.error("Error resolving order line options", e);
135
+ return [];
136
+ }
137
+ };
138
+ }
139
+ async generateRealizationPDF(ctx, { options, order }) {
140
+ try {
141
+ const loggedUser = ctx.activeUserId;
142
+ const user = await this.connection
143
+ .getRepository(ctx, core_1.Administrator)
144
+ .findOne({ where: { id: loggedUser } });
145
+ const file = await this.generateRealizationDocument(ctx, {
146
+ order,
147
+ options,
148
+ user,
149
+ });
150
+ const url = await this.storageService.uploadWithSignature(file);
151
+ return { url, key: file.filename };
152
+ }
153
+ catch (e) {
154
+ console.log(e);
155
+ return null;
156
+ }
157
+ }
158
+ };
159
+ exports.PDFService = PDFService;
160
+ exports.PDFService = PDFService = __decorate([
161
+ (0, common_1.Injectable)(),
162
+ __metadata("design:paramtypes", [core_1.TransactionalConnection,
163
+ storage_service_js_1.StorageService,
164
+ core_1.ProductOptionGroupService,
165
+ core_1.TranslatorService])
166
+ ], PDFService);
@@ -0,0 +1,2 @@
1
+ import { PDFProps } from "./types.js";
2
+ export declare function RealizationPDF({ options, order, user, }: Omit<PDFProps, "assets">): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RealizationPDF = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const renderer_1 = require("@react-pdf/renderer");
6
+ const s = renderer_1.StyleSheet.create({
7
+ logo: { width: 90, height: 20, position: "absolute", top: 35, right: 35 },
8
+ card: { paddingHorizontal: 15 },
9
+ page: { fontFamily: "Roboto" },
10
+ body: { paddingTop: 35, paddingBottom: 65 },
11
+ price: { fontSize: 16, fontWeight: "bold", textDecoration: "underline" },
12
+ line: {
13
+ display: "flex",
14
+ flexDirection: "row",
15
+ justifyContent: "space-between",
16
+ padding: "4 2",
17
+ },
18
+ smText: { fontSize: 8 },
19
+ mdText: { fontSize: 12 },
20
+ lgText: { fontSize: 16 },
21
+ flex: { display: "flex", flexDirection: "row" },
22
+ flexCenter: {
23
+ display: "flex",
24
+ justifyContent: "center",
25
+ alignItems: "center",
26
+ },
27
+ flexCol: { display: "flex", flexDirection: "column" },
28
+ rotatedText: { transform: "rotate(-90deg)" },
29
+ borderT: { borderTopWidth: 1, borderColor: "black", borderStyle: "solid" },
30
+ borderB: { borderBottomWidth: 1, borderColor: "black", borderStyle: "solid" },
31
+ borderL: { borderLeftWidth: 1, borderColor: "black", borderStyle: "solid" },
32
+ emptySpace: { height: 64 },
33
+ pageNumber: {
34
+ position: "absolute",
35
+ fontSize: 12,
36
+ bottom: 30,
37
+ left: 0,
38
+ right: 0,
39
+ textAlign: "center",
40
+ color: "grey",
41
+ },
42
+ });
43
+ renderer_1.Font.register({
44
+ family: "Roboto",
45
+ src: "https://cdnjs.cloudflare.com/ajax/libs/ink/3.1.10/fonts/Roboto/roboto-light-webfont.ttf",
46
+ });
47
+ renderer_1.Font.register({
48
+ family: "Roboto",
49
+ src: "https://cdnjs.cloudflare.com/ajax/libs/ink/3.1.10/fonts/Roboto/roboto-bold-webfont.ttf",
50
+ });
51
+ renderer_1.Font.register({
52
+ family: "Roboto",
53
+ src: "https://cdnjs.cloudflare.com/ajax/libs/ink/3.1.10/fonts/Roboto/roboto-medium-webfont.ttf",
54
+ });
55
+ const allRealizationData = {
56
+ colorL: "Kolor kartki",
57
+ orderL: "Zamówienie",
58
+ terminL: "Ostateczny termin realizacji",
59
+ SKUL: "SKU:",
60
+ deliveryL: "Dostawa",
61
+ paymentL: "Płatność",
62
+ additionalL: "Inne",
63
+ };
64
+ const subPagesSymbolMapping = {
65
+ 1: "a",
66
+ 2: "b",
67
+ 3: "c",
68
+ 4: "d",
69
+ 5: "e",
70
+ };
71
+ function RealizationPDF({ options, order, user, }) {
72
+ var _a, _b;
73
+ const payment = order.payments ? order.payments[0] : null;
74
+ const postalCode = (_a = order.shippingAddress.postalCode) !== null && _a !== void 0 ? _a : "";
75
+ const city = (_b = order.shippingAddress.city) !== null && _b !== void 0 ? _b : "";
76
+ const hasCustomOptions = options.note.includes("#custom");
77
+ const orderItems = order.lines.reduce((acc, line) => {
78
+ for (let i = 0; i < line.quantity; i++) {
79
+ acc.push(line);
80
+ }
81
+ return acc;
82
+ }, []);
83
+ return ((0, jsx_runtime_1.jsx)(renderer_1.Document, { children: orderItems.map((line, orderLineIndex) => ((0, jsx_runtime_1.jsxs)(renderer_1.Page, { break: true, style: Object.assign(Object.assign(Object.assign({}, s.body), s.page), s.card), size: "A5", children: [hasCustomOptions && ((0, jsx_runtime_1.jsx)(renderer_1.View, { style: Object.assign(Object.assign({}, s.flex), { gap: 4, position: "absolute", top: 15, left: 15, fontSize: 10, width: 150 }), children: (0, jsx_runtime_1.jsx)(renderer_1.Text, { children: "NIESTANDARDOWE" }) })), (0, jsx_runtime_1.jsxs)(renderer_1.View, { style: Object.assign(Object.assign({}, s.flex), { justifyContent: "space-between" }), children: [(0, jsx_runtime_1.jsxs)(renderer_1.View, { children: [(0, jsx_runtime_1.jsxs)(renderer_1.Text, { style: s.smText, children: [allRealizationData.orderL, " ", order.id] }), (0, jsx_runtime_1.jsx)(renderer_1.View, { style: { maxWidth: "50%" }, children: (0, jsx_runtime_1.jsxs)(renderer_1.Text, { style: s.smText, wrap: true, children: [allRealizationData.SKUL, " ", line.productVariant.sku] }) })] }), (0, jsx_runtime_1.jsx)(renderer_1.View, { style: Object.assign(Object.assign({}, s.flex), { marginBottom: 12 }), children: (0, jsx_runtime_1.jsxs)(renderer_1.Text, { style: Object.assign(Object.assign({}, s.smText), { textAlign: "right", position: "relative", top: 4 }), children: [user === null || user === void 0 ? void 0 : user.firstName, " ", user === null || user === void 0 ? void 0 : user.lastName] }) })] }), (0, jsx_runtime_1.jsxs)(renderer_1.View, { style: { display: "flex", flexDirection: "column", gap: 8 }, children: [(0, jsx_runtime_1.jsx)(renderer_1.View, { children: (0, jsx_runtime_1.jsx)(OrderLine, { orderLine: line, options: options, payment: payment, shipping: order.shippingMethod, orderId: order.id, postalCode: postalCode, city: city }) }), (0, jsx_runtime_1.jsx)(renderer_1.View, { break: true, children: (0, jsx_runtime_1.jsx)(OrderLine, { second: true, orderLine: line, options: options, payment: payment, shipping: order.shippingMethod, orderId: order.id, postalCode: postalCode, city: city }) })] }), (0, jsx_runtime_1.jsx)(renderer_1.Text, { style: s.pageNumber, render: ({ subPageNumber, subPageTotalPages }) => {
84
+ const totalPages = orderItems.length;
85
+ const currentPage = orderLineIndex + 1;
86
+ if (subPageTotalPages > 1) {
87
+ return `${currentPage}${subPagesSymbolMapping[subPageNumber]} / ${totalPages}`;
88
+ }
89
+ return `${currentPage} / ${totalPages}`;
90
+ }, fixed: true })] }, line.id))) }));
91
+ }
92
+ exports.RealizationPDF = RealizationPDF;
93
+ function OrderLine({ second, orderLine, options, payment, shipping, orderId, postalCode, city, }) {
94
+ var _a, _b, _c;
95
+ const hasCustomOptions = options.note.includes("#custom");
96
+ const customOptions = (_c = (_b = (_a = options.note) === null || _a === void 0 ? void 0 : _a.split("#custom")) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c.split(",").filter(Boolean).map((o) => {
97
+ const [code, value] = o.split(":");
98
+ return { code: `${code}`, value };
99
+ });
100
+ return ((0, jsx_runtime_1.jsxs)(renderer_1.View, { style: Object.assign(Object.assign({ zIndex: 10, position: "relative" }, s.borderT), s.borderB), children: [!second && (orderLine === null || orderLine === void 0 ? void 0 : orderLine.additionalAsset) && ((0, jsx_runtime_1.jsx)(renderer_1.Image, { style: {
101
+ top: -50,
102
+ right: 55,
103
+ position: "absolute",
104
+ display: "flex",
105
+ justifyContent: "center",
106
+ alignItems: "center",
107
+ width: "auto",
108
+ maxWidth: "150px",
109
+ height: 90,
110
+ zIndex: 100,
111
+ }, src: orderLine.additionalAsset })), (0, jsx_runtime_1.jsxs)(renderer_1.View, { style: s.flex, children: [(0, jsx_runtime_1.jsx)(renderer_1.View, { style: Object.assign(Object.assign(Object.assign({}, s.borderL), s.flexCenter), { position: "relative", width: 18 }), children: (0, jsx_runtime_1.jsx)(renderer_1.Text, { style: Object.assign(Object.assign(Object.assign(Object.assign({}, s.flex), s.flexCenter), s.mdText), { width: "100%", textAlign: "center", transform: "rotate(-90deg)" }), children: options.plannedAt }) }), (0, jsx_runtime_1.jsxs)(renderer_1.View, { style: Object.assign(Object.assign({}, s.borderL), { width: 65, padding: "4 8", display: "flex", flexDirection: "column", textOverflow: "ellipsis", gap: 8 }), children: [(0, jsx_runtime_1.jsx)(renderer_1.Text, { style: Object.assign(Object.assign({}, s.lgText), { marginTop: 6 }), children: orderId }), (0, jsx_runtime_1.jsx)(renderer_1.Text, { style: Object.assign(Object.assign({}, s.smText), { marginTop: 4 }), children: city.toUpperCase() }), (0, jsx_runtime_1.jsx)(renderer_1.Text, { style: Object.assign({}, s.smText), children: postalCode })] }), (0, jsx_runtime_1.jsxs)(renderer_1.View, { style: Object.assign(Object.assign({}, s.borderL), { width: "68%" }), children: [(0, jsx_runtime_1.jsx)(renderer_1.View, { style: { marginTop: second ? 8 : 32, padding: "4 2" }, children: (0, jsx_runtime_1.jsx)(renderer_1.Text, { style: s.mdText, children: orderLine.product.name }) }), (hasCustomOptions ? customOptions : orderLine.options).map((option, i) => ((0, jsx_runtime_1.jsxs)(renderer_1.View, { style: Object.assign(Object.assign(Object.assign({}, s.borderT), s.smText), s.line), children: [(0, jsx_runtime_1.jsx)(renderer_1.Text, { wrap: true, children: option.code }), (0, jsx_runtime_1.jsx)(renderer_1.Text, { wrap: true, style: { maxWidth: "80%" }, children: option.value })] }, "custom option key" + i))), !hasCustomOptions && options.note ? ((0, jsx_runtime_1.jsxs)(renderer_1.View, { style: Object.assign(Object.assign(Object.assign({}, s.borderT), s.smText), s.line), children: [(0, jsx_runtime_1.jsx)(renderer_1.Text, { children: allRealizationData.additionalL }), (0, jsx_runtime_1.jsx)(renderer_1.Text, { children: options.note })] })) : null, (0, jsx_runtime_1.jsx)(renderer_1.View, { style: Object.assign(Object.assign({}, s.borderT), s.emptySpace) })] }), (0, jsx_runtime_1.jsxs)(renderer_1.View, { style: Object.assign(Object.assign({}, s.borderL), { display: "flex", justifyContent: "space-between", alignItems: "center", position: "relative", width: 32, gap: 4 }), children: [(0, jsx_runtime_1.jsx)(renderer_1.View, { style: {
112
+ position: "absolute",
113
+ display: "flex",
114
+ flexDirection: "column",
115
+ transform: "rotate(-90deg)",
116
+ left: -12,
117
+ top: 2,
118
+ width: 96,
119
+ height: 64,
120
+ }, children: (0, jsx_runtime_1.jsxs)(renderer_1.Text, { style: Object.assign({}, s.smText), children: [" ", (shipping === null || shipping === void 0 ? void 0 : shipping.name) || "—"] }) }), (0, jsx_runtime_1.jsxs)(renderer_1.View, { style: {
121
+ display: "flex",
122
+ flexDirection: "column",
123
+ transform: "rotate(-90deg)",
124
+ position: "absolute",
125
+ left: -16,
126
+ bottom: 38,
127
+ width: 128,
128
+ height: 64,
129
+ }, children: [(0, jsx_runtime_1.jsx)(renderer_1.Text, { style: Object.assign({}, s.smText), children: allRealizationData.paymentL }), (0, jsx_runtime_1.jsx)(renderer_1.Text, { style: Object.assign({}, s.smText), children: (payment === null || payment === void 0 ? void 0 : payment.method) || "-" })] })] })] })] }));
130
+ }
@@ -0,0 +1,23 @@
1
+ import { CreateAssetInput } from "@deenruv/common/lib/generated-types";
2
+ import { InRealizationPluginOptions } from "../consts.js";
3
+ export declare class StorageLogger {
4
+ private logger;
5
+ log: (message: string) => void;
6
+ error: (message: string) => void;
7
+ constructor(ctx: string);
8
+ }
9
+ export declare class StorageService {
10
+ private config;
11
+ private logger;
12
+ constructor(config: InRealizationPluginOptions);
13
+ uploadFile(file: CreateAssetInput["file"]): Promise<string>;
14
+ deleteFile(key: string): Promise<void>;
15
+ getFile(key: string): Promise<import("@aws-sdk/client-s3").GetObjectCommandOutput>;
16
+ uploadWithSignature(file: CreateAssetInput["file"]): Promise<string>;
17
+ uploadWithoutSignature(file: CreateAssetInput["file"]): Promise<string>;
18
+ getSingedFileUrl(key: string): Promise<string>;
19
+ getFileUrl(key: string): Promise<string>;
20
+ private doPublicURL;
21
+ private getURL;
22
+ private writeFile;
23
+ }
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.StorageService = exports.StorageLogger = void 0;
19
+ const common_1 = require("@nestjs/common");
20
+ const consts_js_1 = require("../consts.js");
21
+ const core_1 = require("@deenruv/core");
22
+ const client_s3_1 = require("@aws-sdk/client-s3");
23
+ const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
24
+ const mime_types_1 = __importDefault(require("mime-types"));
25
+ class StorageLogger {
26
+ constructor(ctx) {
27
+ this.logger = new core_1.Logger();
28
+ this.log = (message) => this.logger.log(message, ctx);
29
+ this.error = (message) => this.logger.error(message, undefined, ctx);
30
+ }
31
+ }
32
+ exports.StorageLogger = StorageLogger;
33
+ let StorageService = class StorageService {
34
+ constructor(config) {
35
+ this.config = config;
36
+ this.logger = new StorageLogger("StorageService - PDF");
37
+ }
38
+ async uploadFile(file) {
39
+ const { createReadStream, filename, mimetype } = await file;
40
+ try {
41
+ const { ContentLength: size = 0 } = await this.getFile(filename);
42
+ if (size > 0)
43
+ await this.deleteFile(filename);
44
+ }
45
+ catch (_a) { }
46
+ const stream = createReadStream();
47
+ return await this.writeFile(filename, stream, mimetype);
48
+ }
49
+ async deleteFile(key) {
50
+ try {
51
+ await this.config.s3.client.send(new client_s3_1.DeleteObjectCommand({
52
+ Bucket: this.config.s3.bucket,
53
+ Key: key,
54
+ }));
55
+ this.logger.log("File deleted");
56
+ }
57
+ catch (error) {
58
+ this.logger.error("File does not exist");
59
+ throw error;
60
+ }
61
+ }
62
+ async getFile(key) {
63
+ try {
64
+ const result = await this.config.s3.client.send(new client_s3_1.GetObjectCommand({
65
+ Bucket: this.config.s3.bucket,
66
+ Key: key,
67
+ }));
68
+ this.logger.log("File exists");
69
+ return result;
70
+ }
71
+ catch (error) {
72
+ this.logger.error("File does not exist");
73
+ throw error;
74
+ }
75
+ }
76
+ async uploadWithSignature(file) {
77
+ const key = await this.uploadFile(file);
78
+ const url = await this.getSingedFileUrl(key);
79
+ return url;
80
+ }
81
+ async uploadWithoutSignature(file) {
82
+ const key = await this.uploadFile(file);
83
+ const url = await this.getFileUrl(key);
84
+ return url;
85
+ }
86
+ async getSingedFileUrl(key) {
87
+ const url = await this.getURL(key, true);
88
+ this.logger.log("Obtained file URL, signed");
89
+ return url;
90
+ }
91
+ async getFileUrl(key) {
92
+ const url = await this.getURL(key, false);
93
+ this.logger.log("Obtained file URL, not signed");
94
+ return url;
95
+ }
96
+ doPublicURL(key) {
97
+ return `https://${this.config.s3.bucket}/${key}`;
98
+ }
99
+ async getURL(key, singed) {
100
+ return singed
101
+ ? await (0, s3_request_presigner_1.getSignedUrl)(this.config.s3.client, new client_s3_1.GetObjectCommand({
102
+ Bucket: this.config.s3.bucket,
103
+ Key: key,
104
+ }), { expiresIn: this.config.s3.expiresIn })
105
+ : this.doPublicURL(key);
106
+ }
107
+ async writeFile(key, data, mimeType) {
108
+ mimeType = (!mimeType && mime_types_1.default.contentType(key)) || mimeType;
109
+ const metaData = {};
110
+ let buffer;
111
+ if (data instanceof Blob) {
112
+ buffer = Buffer.from(await data.arrayBuffer());
113
+ }
114
+ else {
115
+ buffer = data;
116
+ }
117
+ const uploaded = await this.config.s3.client.send(new client_s3_1.PutObjectCommand({
118
+ Bucket: this.config.s3.bucket,
119
+ Key: key,
120
+ Body: buffer,
121
+ ContentType: mimeType,
122
+ Metadata: metaData,
123
+ }));
124
+ if (uploaded)
125
+ this.logger.log("File uploaded");
126
+ return key;
127
+ }
128
+ };
129
+ exports.StorageService = StorageService;
130
+ exports.StorageService = StorageService = __decorate([
131
+ (0, common_1.Injectable)(),
132
+ __param(0, (0, common_1.Inject)(consts_js_1.PLUGIN_INIT_OPTIONS)),
133
+ __metadata("design:paramtypes", [Object])
134
+ ], StorageService);
@@ -0,0 +1,18 @@
1
+ import { Administrator, Order, ShippingMethod } from "@deenruv/core";
2
+ export type PDFProps = {
3
+ user: Administrator | null;
4
+ order: Order & {
5
+ shippingMethod: ShippingMethod;
6
+ };
7
+ options: {
8
+ assets?: {
9
+ id: string;
10
+ orderLineID: string;
11
+ preview: string;
12
+ }[];
13
+ plannedAt: string;
14
+ finalPlannedAt: string;
15
+ note: string;
16
+ color: string;
17
+ };
18
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export declare const AllTypesProps: Record<string, any>;
2
+ export declare const ReturnTypes: Record<string, any>;
3
+ export declare const Ops: {
4
+ query: "Query";
5
+ mutation: "Mutation";
6
+ };