@agilo/medusa-analytics-plugin 1.2.0 → 1.2.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.
|
@@ -9,9 +9,11 @@ const dateFns = require("date-fns");
|
|
|
9
9
|
const reactAriaComponents = require("react-aria-components");
|
|
10
10
|
const reactRouterDom = require("react-router-dom");
|
|
11
11
|
const recharts = require("recharts");
|
|
12
|
+
const Medusa = require("@medusajs/js-sdk");
|
|
12
13
|
const clsx = require("clsx");
|
|
13
14
|
const tailwindMerge = require("tailwind-merge");
|
|
14
15
|
const reactQuery = require("@tanstack/react-query");
|
|
16
|
+
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
15
17
|
function _interopNamespace(e) {
|
|
16
18
|
if (e && e.__esModule) return e;
|
|
17
19
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
@@ -30,6 +32,7 @@ function _interopNamespace(e) {
|
|
|
30
32
|
return Object.freeze(n);
|
|
31
33
|
}
|
|
32
34
|
const React__namespace = /* @__PURE__ */ _interopNamespace(React);
|
|
35
|
+
const Medusa__default = /* @__PURE__ */ _interopDefault(Medusa);
|
|
33
36
|
function $2b4dce13dd5a17fa$export$842a2cf37af977e1(amount, numerator) {
|
|
34
37
|
return amount - numerator * Math.floor(amount / numerator);
|
|
35
38
|
}
|
|
@@ -827,6 +830,12 @@ function generateColorsForData(data, keyField, saturation = 70, lightness = 50)
|
|
|
827
830
|
(item) => generateStableColor(String(item[keyField]), saturation, lightness)
|
|
828
831
|
);
|
|
829
832
|
}
|
|
833
|
+
const sdk = new Medusa__default.default({
|
|
834
|
+
baseUrl: __BACKEND_URL__ || "/",
|
|
835
|
+
auth: {
|
|
836
|
+
type: "session"
|
|
837
|
+
}
|
|
838
|
+
});
|
|
830
839
|
const BarChart = ({
|
|
831
840
|
data,
|
|
832
841
|
xAxisDataKey,
|
|
@@ -1072,17 +1081,15 @@ const ProductsTable = ({ products }) => {
|
|
|
1072
1081
|
products.length > PAGE_SIZE$1 && /* @__PURE__ */ jsxRuntime.jsx(ui.DataTable.Pagination, {})
|
|
1073
1082
|
] });
|
|
1074
1083
|
};
|
|
1075
|
-
const BACKEND_URL$2 = __BACKEND_URL__ === "/" ? "" : __BACKEND_URL__;
|
|
1076
1084
|
async function retrieveProductAnalytics(date) {
|
|
1077
1085
|
if (!date || !date.from || !(date == null ? void 0 : date.to)) {
|
|
1078
1086
|
return void 0;
|
|
1079
1087
|
}
|
|
1080
1088
|
const dateFrom = dateFns.format(date.from, "yyyy-MM-dd");
|
|
1081
1089
|
const dateTo = dateFns.format(date.to, "yyyy-MM-dd");
|
|
1082
|
-
const
|
|
1083
|
-
|
|
1090
|
+
const productAnalytics = await sdk.client.fetch(
|
|
1091
|
+
`/admin/agilo-analytics/products?date_from=${dateFrom}&date_to=${dateTo}`
|
|
1084
1092
|
);
|
|
1085
|
-
const productAnalytics = await data.json();
|
|
1086
1093
|
return productAnalytics;
|
|
1087
1094
|
}
|
|
1088
1095
|
const useProductAnalytics = (query, options) => {
|
|
@@ -1095,21 +1102,14 @@ const useProductAnalytics = (query, options) => {
|
|
|
1095
1102
|
...options
|
|
1096
1103
|
});
|
|
1097
1104
|
};
|
|
1098
|
-
const BACKEND_URL$1 = __BACKEND_URL__ === "/" ? "" : __BACKEND_URL__;
|
|
1099
1105
|
async function retrieveOrderAnalytics(preset, date) {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
);
|
|
1104
|
-
|
|
1105
|
-
return orderAnalytics2;
|
|
1106
|
+
let url = `/admin/agilo-analytics/orders?preset=${preset}`;
|
|
1107
|
+
if (date && date.from && date.to) {
|
|
1108
|
+
const dateFrom = dateFns.format(date.from, "yyyy-MM-dd");
|
|
1109
|
+
const dateTo = dateFns.format(date.to, "yyyy-MM-dd");
|
|
1110
|
+
url = `/admin/agilo-analytics/orders?preset=custom&date_from=${dateFrom}&date_to=${dateTo}`;
|
|
1106
1111
|
}
|
|
1107
|
-
const
|
|
1108
|
-
const dateTo = dateFns.format(date.to, "yyyy-MM-dd");
|
|
1109
|
-
const data = await fetch(
|
|
1110
|
-
`${BACKEND_URL$1}/admin/agilo-analytics/orders?date_from=${dateFrom}&date_to=${dateTo}&preset=${preset}`
|
|
1111
|
-
);
|
|
1112
|
-
const orderAnalytics = await data.json();
|
|
1112
|
+
const orderAnalytics = await sdk.client.fetch(url);
|
|
1113
1113
|
return orderAnalytics;
|
|
1114
1114
|
}
|
|
1115
1115
|
const useOrderAnalytics = (preset, query, options) => {
|
|
@@ -1212,17 +1212,15 @@ const ProductsTableSkeleton = () => {
|
|
|
1212
1212
|
/* @__PURE__ */ jsxRuntime.jsx(ui.DataTable.Table, {})
|
|
1213
1213
|
] });
|
|
1214
1214
|
};
|
|
1215
|
-
const BACKEND_URL = __BACKEND_URL__ === "/" ? "" : __BACKEND_URL__;
|
|
1216
1215
|
async function retrieveCustomersAnalytics(date) {
|
|
1217
1216
|
if (!date || !date.from || !(date == null ? void 0 : date.to)) {
|
|
1218
1217
|
return void 0;
|
|
1219
1218
|
}
|
|
1220
1219
|
const dateFrom = dateFns.format(date.from, "yyyy-MM-dd");
|
|
1221
1220
|
const dateTo = dateFns.format(date.to, "yyyy-MM-dd");
|
|
1222
|
-
const
|
|
1223
|
-
|
|
1221
|
+
const customersAnalytics = await sdk.client.fetch(
|
|
1222
|
+
`/admin/agilo-analytics/customers?date_from=${dateFrom}&date_to=${dateTo}`
|
|
1224
1223
|
);
|
|
1225
|
-
const customersAnalytics = await data.json();
|
|
1226
1224
|
return customersAnalytics;
|
|
1227
1225
|
}
|
|
1228
1226
|
const useCustomerAnalytics = (query, options) => {
|
|
@@ -1312,42 +1310,42 @@ const StackedBarChart = ({
|
|
|
1312
1310
|
};
|
|
1313
1311
|
const dummyData = [
|
|
1314
1312
|
{
|
|
1315
|
-
a: "
|
|
1313
|
+
a: "a1",
|
|
1316
1314
|
b: "b",
|
|
1317
1315
|
c: 0,
|
|
1318
1316
|
d: 0,
|
|
1319
1317
|
e: /* @__PURE__ */ new Date()
|
|
1320
1318
|
},
|
|
1321
1319
|
{
|
|
1322
|
-
a: "
|
|
1320
|
+
a: "a2",
|
|
1323
1321
|
b: "b",
|
|
1324
1322
|
c: 0,
|
|
1325
1323
|
d: 0,
|
|
1326
1324
|
e: /* @__PURE__ */ new Date()
|
|
1327
1325
|
},
|
|
1328
1326
|
{
|
|
1329
|
-
a: "
|
|
1327
|
+
a: "a3",
|
|
1330
1328
|
b: "b",
|
|
1331
1329
|
c: 0,
|
|
1332
1330
|
d: 0,
|
|
1333
1331
|
e: /* @__PURE__ */ new Date()
|
|
1334
1332
|
},
|
|
1335
1333
|
{
|
|
1336
|
-
a: "
|
|
1334
|
+
a: "a4",
|
|
1337
1335
|
b: "b",
|
|
1338
1336
|
c: 0,
|
|
1339
1337
|
d: 0,
|
|
1340
1338
|
e: /* @__PURE__ */ new Date()
|
|
1341
1339
|
},
|
|
1342
1340
|
{
|
|
1343
|
-
a: "
|
|
1341
|
+
a: "a5",
|
|
1344
1342
|
b: "b",
|
|
1345
1343
|
c: 0,
|
|
1346
1344
|
d: 0,
|
|
1347
1345
|
e: /* @__PURE__ */ new Date()
|
|
1348
1346
|
},
|
|
1349
1347
|
{
|
|
1350
|
-
a: "
|
|
1348
|
+
a: "a6",
|
|
1351
1349
|
b: "b",
|
|
1352
1350
|
c: 0,
|
|
1353
1351
|
d: 0,
|
|
@@ -9,6 +9,7 @@ import { format, parse, startOfMonth, endOfMonth, subMonths } from "date-fns";
|
|
|
9
9
|
import { DateRangePicker, Group, DateInput, DateSegment, Button, Popover, Dialog, RangeCalendar, Heading as Heading$1, CalendarGrid, CalendarCell } from "react-aria-components";
|
|
10
10
|
import { useNavigate, useSearchParams } from "react-router-dom";
|
|
11
11
|
import { ResponsiveContainer, BarChart as BarChart$1, CartesianGrid, XAxis, YAxis, Tooltip, Bar, LineChart as LineChart$1, Line, Cell, PieChart as PieChart$1, Pie } from "recharts";
|
|
12
|
+
import Medusa from "@medusajs/js-sdk";
|
|
12
13
|
import { clsx } from "clsx";
|
|
13
14
|
import { twMerge } from "tailwind-merge";
|
|
14
15
|
import { useQuery } from "@tanstack/react-query";
|
|
@@ -809,6 +810,12 @@ function generateColorsForData(data, keyField, saturation = 70, lightness = 50)
|
|
|
809
810
|
(item) => generateStableColor(String(item[keyField]), saturation, lightness)
|
|
810
811
|
);
|
|
811
812
|
}
|
|
813
|
+
const sdk = new Medusa({
|
|
814
|
+
baseUrl: __BACKEND_URL__ || "/",
|
|
815
|
+
auth: {
|
|
816
|
+
type: "session"
|
|
817
|
+
}
|
|
818
|
+
});
|
|
812
819
|
const BarChart = ({
|
|
813
820
|
data,
|
|
814
821
|
xAxisDataKey,
|
|
@@ -1054,17 +1061,15 @@ const ProductsTable = ({ products }) => {
|
|
|
1054
1061
|
products.length > PAGE_SIZE$1 && /* @__PURE__ */ jsx(DataTable.Pagination, {})
|
|
1055
1062
|
] });
|
|
1056
1063
|
};
|
|
1057
|
-
const BACKEND_URL$2 = __BACKEND_URL__ === "/" ? "" : __BACKEND_URL__;
|
|
1058
1064
|
async function retrieveProductAnalytics(date) {
|
|
1059
1065
|
if (!date || !date.from || !(date == null ? void 0 : date.to)) {
|
|
1060
1066
|
return void 0;
|
|
1061
1067
|
}
|
|
1062
1068
|
const dateFrom = format(date.from, "yyyy-MM-dd");
|
|
1063
1069
|
const dateTo = format(date.to, "yyyy-MM-dd");
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1070
|
+
const productAnalytics = await sdk.client.fetch(
|
|
1071
|
+
`/admin/agilo-analytics/products?date_from=${dateFrom}&date_to=${dateTo}`
|
|
1066
1072
|
);
|
|
1067
|
-
const productAnalytics = await data.json();
|
|
1068
1073
|
return productAnalytics;
|
|
1069
1074
|
}
|
|
1070
1075
|
const useProductAnalytics = (query, options) => {
|
|
@@ -1077,21 +1082,14 @@ const useProductAnalytics = (query, options) => {
|
|
|
1077
1082
|
...options
|
|
1078
1083
|
});
|
|
1079
1084
|
};
|
|
1080
|
-
const BACKEND_URL$1 = __BACKEND_URL__ === "/" ? "" : __BACKEND_URL__;
|
|
1081
1085
|
async function retrieveOrderAnalytics(preset, date) {
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
);
|
|
1086
|
-
|
|
1087
|
-
return orderAnalytics2;
|
|
1086
|
+
let url = `/admin/agilo-analytics/orders?preset=${preset}`;
|
|
1087
|
+
if (date && date.from && date.to) {
|
|
1088
|
+
const dateFrom = format(date.from, "yyyy-MM-dd");
|
|
1089
|
+
const dateTo = format(date.to, "yyyy-MM-dd");
|
|
1090
|
+
url = `/admin/agilo-analytics/orders?preset=custom&date_from=${dateFrom}&date_to=${dateTo}`;
|
|
1088
1091
|
}
|
|
1089
|
-
const
|
|
1090
|
-
const dateTo = format(date.to, "yyyy-MM-dd");
|
|
1091
|
-
const data = await fetch(
|
|
1092
|
-
`${BACKEND_URL$1}/admin/agilo-analytics/orders?date_from=${dateFrom}&date_to=${dateTo}&preset=${preset}`
|
|
1093
|
-
);
|
|
1094
|
-
const orderAnalytics = await data.json();
|
|
1092
|
+
const orderAnalytics = await sdk.client.fetch(url);
|
|
1095
1093
|
return orderAnalytics;
|
|
1096
1094
|
}
|
|
1097
1095
|
const useOrderAnalytics = (preset, query, options) => {
|
|
@@ -1194,17 +1192,15 @@ const ProductsTableSkeleton = () => {
|
|
|
1194
1192
|
/* @__PURE__ */ jsx(DataTable.Table, {})
|
|
1195
1193
|
] });
|
|
1196
1194
|
};
|
|
1197
|
-
const BACKEND_URL = __BACKEND_URL__ === "/" ? "" : __BACKEND_URL__;
|
|
1198
1195
|
async function retrieveCustomersAnalytics(date) {
|
|
1199
1196
|
if (!date || !date.from || !(date == null ? void 0 : date.to)) {
|
|
1200
1197
|
return void 0;
|
|
1201
1198
|
}
|
|
1202
1199
|
const dateFrom = format(date.from, "yyyy-MM-dd");
|
|
1203
1200
|
const dateTo = format(date.to, "yyyy-MM-dd");
|
|
1204
|
-
const
|
|
1205
|
-
|
|
1201
|
+
const customersAnalytics = await sdk.client.fetch(
|
|
1202
|
+
`/admin/agilo-analytics/customers?date_from=${dateFrom}&date_to=${dateTo}`
|
|
1206
1203
|
);
|
|
1207
|
-
const customersAnalytics = await data.json();
|
|
1208
1204
|
return customersAnalytics;
|
|
1209
1205
|
}
|
|
1210
1206
|
const useCustomerAnalytics = (query, options) => {
|
|
@@ -1294,42 +1290,42 @@ const StackedBarChart = ({
|
|
|
1294
1290
|
};
|
|
1295
1291
|
const dummyData = [
|
|
1296
1292
|
{
|
|
1297
|
-
a: "
|
|
1293
|
+
a: "a1",
|
|
1298
1294
|
b: "b",
|
|
1299
1295
|
c: 0,
|
|
1300
1296
|
d: 0,
|
|
1301
1297
|
e: /* @__PURE__ */ new Date()
|
|
1302
1298
|
},
|
|
1303
1299
|
{
|
|
1304
|
-
a: "
|
|
1300
|
+
a: "a2",
|
|
1305
1301
|
b: "b",
|
|
1306
1302
|
c: 0,
|
|
1307
1303
|
d: 0,
|
|
1308
1304
|
e: /* @__PURE__ */ new Date()
|
|
1309
1305
|
},
|
|
1310
1306
|
{
|
|
1311
|
-
a: "
|
|
1307
|
+
a: "a3",
|
|
1312
1308
|
b: "b",
|
|
1313
1309
|
c: 0,
|
|
1314
1310
|
d: 0,
|
|
1315
1311
|
e: /* @__PURE__ */ new Date()
|
|
1316
1312
|
},
|
|
1317
1313
|
{
|
|
1318
|
-
a: "
|
|
1314
|
+
a: "a4",
|
|
1319
1315
|
b: "b",
|
|
1320
1316
|
c: 0,
|
|
1321
1317
|
d: 0,
|
|
1322
1318
|
e: /* @__PURE__ */ new Date()
|
|
1323
1319
|
},
|
|
1324
1320
|
{
|
|
1325
|
-
a: "
|
|
1321
|
+
a: "a5",
|
|
1326
1322
|
b: "b",
|
|
1327
1323
|
c: 0,
|
|
1328
1324
|
d: 0,
|
|
1329
1325
|
e: /* @__PURE__ */ new Date()
|
|
1330
1326
|
},
|
|
1331
1327
|
{
|
|
1332
|
-
a: "
|
|
1328
|
+
a: "a6",
|
|
1333
1329
|
b: "b",
|
|
1334
1330
|
c: 0,
|
|
1335
1331
|
d: 0,
|