@mercurjs/algolia 1.3.0 → 1.4.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.
|
@@ -1,107 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
-
const adminSdk = require("@medusajs/admin-sdk");
|
|
4
|
-
const ui = require("@medusajs/ui");
|
|
5
|
-
const reactQuery = require("@tanstack/react-query");
|
|
6
|
-
const mercurQuery = async (url, {
|
|
7
|
-
method,
|
|
8
|
-
body,
|
|
9
|
-
query,
|
|
10
|
-
headers
|
|
11
|
-
}) => {
|
|
12
|
-
const bearer = await window.localStorage.getItem("medusa_auth_token") || "";
|
|
13
|
-
const params = Object.entries(query || {}).reduce(
|
|
14
|
-
(acc, [key, value], index) => {
|
|
15
|
-
if (value && value !== void 0) {
|
|
16
|
-
const queryLength = Object.values(query || {}).filter(
|
|
17
|
-
(i) => i && i !== void 0
|
|
18
|
-
).length;
|
|
19
|
-
acc += `${key}=${value}${index + 1 <= queryLength ? "&" : ""}`;
|
|
20
|
-
}
|
|
21
|
-
return acc;
|
|
22
|
-
},
|
|
23
|
-
""
|
|
24
|
-
);
|
|
25
|
-
const response = await fetch(`${url}${params && `?${params}`}`, {
|
|
26
|
-
method,
|
|
27
|
-
headers: {
|
|
28
|
-
authorization: `Bearer ${bearer}`,
|
|
29
|
-
"Content-Type": "application/json",
|
|
30
|
-
...headers
|
|
31
|
-
},
|
|
32
|
-
body: body ? JSON.stringify(body) : null
|
|
33
|
-
});
|
|
34
|
-
if (!response.ok) {
|
|
35
|
-
const errorData = await response.json();
|
|
36
|
-
throw new Error(errorData.message || "Nieznany błąd serwera");
|
|
37
|
-
}
|
|
38
|
-
return response.json();
|
|
39
|
-
};
|
|
40
|
-
const useSyncAlgolia = () => {
|
|
41
|
-
return reactQuery.useMutation({
|
|
42
|
-
mutationFn: () => mercurQuery("/admin/algolia", {
|
|
43
|
-
method: "POST"
|
|
44
|
-
})
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
const useAlgolia = () => {
|
|
48
|
-
return reactQuery.useQuery({
|
|
49
|
-
queryKey: ["algolia"],
|
|
50
|
-
queryFn: () => mercurQuery("/admin/algolia", { method: "GET" })
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
const AlgoliaSearchEnginePage = () => {
|
|
54
|
-
const { data: algolia } = useAlgolia();
|
|
55
|
-
const { mutateAsync: triggerSynchronization } = useSyncAlgolia();
|
|
56
|
-
const handleTriggerSynchronization = async () => {
|
|
57
|
-
try {
|
|
58
|
-
await triggerSynchronization();
|
|
59
|
-
ui.toast.success("Synchronization triggered!");
|
|
60
|
-
} catch {
|
|
61
|
-
ui.toast.error("Error!");
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { children: [
|
|
65
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
|
|
66
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
67
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Algolia Search Engine" }),
|
|
68
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", size: "small", children: "Check Algolia Search Engine status" })
|
|
69
|
-
] }),
|
|
70
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: handleTriggerSynchronization, children: "Trigger Synchronization" })
|
|
71
|
-
] }),
|
|
72
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Body, { children: [
|
|
73
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { children: [
|
|
74
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: "Application ID" }),
|
|
75
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: algolia == null ? void 0 : algolia.appId })
|
|
76
|
-
] }),
|
|
77
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { children: [
|
|
78
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: "ProductIndex" }),
|
|
79
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: (algolia == null ? void 0 : algolia.productIndex) ? /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: "green", children: "Exists" }) : /* @__PURE__ */ jsxRuntime.jsx(ui.StatusBadge, { color: "red", children: "Doesn't exist" }) })
|
|
80
|
-
] })
|
|
81
|
-
] }) })
|
|
82
|
-
] });
|
|
83
|
-
};
|
|
84
|
-
const config = adminSdk.defineRouteConfig({
|
|
85
|
-
label: "Algolia Search Engine"
|
|
86
|
-
});
|
|
87
2
|
const widgetModule = { widgets: [] };
|
|
88
3
|
const routeModule = {
|
|
89
|
-
routes: [
|
|
90
|
-
{
|
|
91
|
-
Component: AlgoliaSearchEnginePage,
|
|
92
|
-
path: "/algolia"
|
|
93
|
-
}
|
|
94
|
-
]
|
|
4
|
+
routes: []
|
|
95
5
|
};
|
|
96
6
|
const menuItemModule = {
|
|
97
|
-
menuItems: [
|
|
98
|
-
{
|
|
99
|
-
label: config.label,
|
|
100
|
-
icon: void 0,
|
|
101
|
-
path: "/algolia",
|
|
102
|
-
nested: void 0
|
|
103
|
-
}
|
|
104
|
-
]
|
|
7
|
+
menuItems: []
|
|
105
8
|
};
|
|
106
9
|
const formModule = { customFields: {} };
|
|
107
10
|
const displayModule = {
|
|
@@ -1,106 +1,9 @@
|
|
|
1
|
-
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
-
import { defineRouteConfig } from "@medusajs/admin-sdk";
|
|
3
|
-
import { Container, Heading, Text, Button, Table, StatusBadge, toast } from "@medusajs/ui";
|
|
4
|
-
import { useQuery, useMutation } from "@tanstack/react-query";
|
|
5
|
-
const mercurQuery = async (url, {
|
|
6
|
-
method,
|
|
7
|
-
body,
|
|
8
|
-
query,
|
|
9
|
-
headers
|
|
10
|
-
}) => {
|
|
11
|
-
const bearer = await window.localStorage.getItem("medusa_auth_token") || "";
|
|
12
|
-
const params = Object.entries(query || {}).reduce(
|
|
13
|
-
(acc, [key, value], index) => {
|
|
14
|
-
if (value && value !== void 0) {
|
|
15
|
-
const queryLength = Object.values(query || {}).filter(
|
|
16
|
-
(i) => i && i !== void 0
|
|
17
|
-
).length;
|
|
18
|
-
acc += `${key}=${value}${index + 1 <= queryLength ? "&" : ""}`;
|
|
19
|
-
}
|
|
20
|
-
return acc;
|
|
21
|
-
},
|
|
22
|
-
""
|
|
23
|
-
);
|
|
24
|
-
const response = await fetch(`${url}${params && `?${params}`}`, {
|
|
25
|
-
method,
|
|
26
|
-
headers: {
|
|
27
|
-
authorization: `Bearer ${bearer}`,
|
|
28
|
-
"Content-Type": "application/json",
|
|
29
|
-
...headers
|
|
30
|
-
},
|
|
31
|
-
body: body ? JSON.stringify(body) : null
|
|
32
|
-
});
|
|
33
|
-
if (!response.ok) {
|
|
34
|
-
const errorData = await response.json();
|
|
35
|
-
throw new Error(errorData.message || "Nieznany błąd serwera");
|
|
36
|
-
}
|
|
37
|
-
return response.json();
|
|
38
|
-
};
|
|
39
|
-
const useSyncAlgolia = () => {
|
|
40
|
-
return useMutation({
|
|
41
|
-
mutationFn: () => mercurQuery("/admin/algolia", {
|
|
42
|
-
method: "POST"
|
|
43
|
-
})
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
const useAlgolia = () => {
|
|
47
|
-
return useQuery({
|
|
48
|
-
queryKey: ["algolia"],
|
|
49
|
-
queryFn: () => mercurQuery("/admin/algolia", { method: "GET" })
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
const AlgoliaSearchEnginePage = () => {
|
|
53
|
-
const { data: algolia } = useAlgolia();
|
|
54
|
-
const { mutateAsync: triggerSynchronization } = useSyncAlgolia();
|
|
55
|
-
const handleTriggerSynchronization = async () => {
|
|
56
|
-
try {
|
|
57
|
-
await triggerSynchronization();
|
|
58
|
-
toast.success("Synchronization triggered!");
|
|
59
|
-
} catch {
|
|
60
|
-
toast.error("Error!");
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
return /* @__PURE__ */ jsxs(Container, { children: [
|
|
64
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
|
|
65
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
66
|
-
/* @__PURE__ */ jsx(Heading, { children: "Algolia Search Engine" }),
|
|
67
|
-
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: "Check Algolia Search Engine status" })
|
|
68
|
-
] }),
|
|
69
|
-
/* @__PURE__ */ jsx(Button, { onClick: handleTriggerSynchronization, children: "Trigger Synchronization" })
|
|
70
|
-
] }),
|
|
71
|
-
/* @__PURE__ */ jsx(Table, { children: /* @__PURE__ */ jsxs(Table.Body, { children: [
|
|
72
|
-
/* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
73
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: "Application ID" }),
|
|
74
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: algolia == null ? void 0 : algolia.appId })
|
|
75
|
-
] }),
|
|
76
|
-
/* @__PURE__ */ jsxs(Table.Row, { children: [
|
|
77
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: "ProductIndex" }),
|
|
78
|
-
/* @__PURE__ */ jsx(Table.Cell, { children: (algolia == null ? void 0 : algolia.productIndex) ? /* @__PURE__ */ jsx(StatusBadge, { color: "green", children: "Exists" }) : /* @__PURE__ */ jsx(StatusBadge, { color: "red", children: "Doesn't exist" }) })
|
|
79
|
-
] })
|
|
80
|
-
] }) })
|
|
81
|
-
] });
|
|
82
|
-
};
|
|
83
|
-
const config = defineRouteConfig({
|
|
84
|
-
label: "Algolia Search Engine"
|
|
85
|
-
});
|
|
86
1
|
const widgetModule = { widgets: [] };
|
|
87
2
|
const routeModule = {
|
|
88
|
-
routes: [
|
|
89
|
-
{
|
|
90
|
-
Component: AlgoliaSearchEnginePage,
|
|
91
|
-
path: "/algolia"
|
|
92
|
-
}
|
|
93
|
-
]
|
|
3
|
+
routes: []
|
|
94
4
|
};
|
|
95
5
|
const menuItemModule = {
|
|
96
|
-
menuItems: [
|
|
97
|
-
{
|
|
98
|
-
label: config.label,
|
|
99
|
-
icon: void 0,
|
|
100
|
-
path: "/algolia",
|
|
101
|
-
nested: void 0
|
|
102
|
-
}
|
|
103
|
-
]
|
|
6
|
+
menuItems: []
|
|
104
7
|
};
|
|
105
8
|
const formModule = { customFields: {} };
|
|
106
9
|
const displayModule = {
|