strapi-plugin-meilisearch 0.13.0 → 0.13.2

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.
@@ -0,0 +1,986 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { useState, useEffect, memo } from "react";
4
+ import { Routes, Route } from "react-router-dom";
5
+ import { useNotification, useFetchClient, useRBAC, private_useAutoReloadOverlayBlocker, private_AutoReloadOverlayBlockerProvider, Page, Layouts, BackButton } from "@strapi/strapi/admin";
6
+ import { p as pluginId, P as PERMISSIONS } from "./index-CnETd4ds.mjs";
7
+ import { Tr, Td, Checkbox, Typography, Flex, Box, Button, Thead, Th, VisuallyHidden, Table, Tbody, Field, Link, Tabs } from "@strapi/design-system";
8
+ var __assign = function() {
9
+ __assign = Object.assign || function __assign2(t) {
10
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
11
+ s = arguments[i];
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
13
+ }
14
+ return t;
15
+ };
16
+ return __assign.apply(this, arguments);
17
+ };
18
+ function __rest(s, e) {
19
+ var t = {};
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
21
+ t[p] = s[p];
22
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
23
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
24
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
25
+ t[p[i]] = s[p[i]];
26
+ }
27
+ return t;
28
+ }
29
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
30
+ var e = new Error(message);
31
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
32
+ };
33
+ var reactIs$1 = { exports: {} };
34
+ var reactIs_production_min = {};
35
+ /** @license React v16.13.1
36
+ * react-is.production.min.js
37
+ *
38
+ * Copyright (c) Facebook, Inc. and its affiliates.
39
+ *
40
+ * This source code is licensed under the MIT license found in the
41
+ * LICENSE file in the root directory of this source tree.
42
+ */
43
+ var hasRequiredReactIs_production_min;
44
+ function requireReactIs_production_min() {
45
+ if (hasRequiredReactIs_production_min) return reactIs_production_min;
46
+ hasRequiredReactIs_production_min = 1;
47
+ var b = "function" === typeof Symbol && Symbol.for, c = b ? Symbol.for("react.element") : 60103, d = b ? Symbol.for("react.portal") : 60106, e = b ? Symbol.for("react.fragment") : 60107, f = b ? Symbol.for("react.strict_mode") : 60108, g = b ? Symbol.for("react.profiler") : 60114, h = b ? Symbol.for("react.provider") : 60109, k = b ? Symbol.for("react.context") : 60110, l = b ? Symbol.for("react.async_mode") : 60111, m = b ? Symbol.for("react.concurrent_mode") : 60111, n = b ? Symbol.for("react.forward_ref") : 60112, p = b ? Symbol.for("react.suspense") : 60113, q = b ? Symbol.for("react.suspense_list") : 60120, r = b ? Symbol.for("react.memo") : 60115, t = b ? Symbol.for("react.lazy") : 60116, v = b ? Symbol.for("react.block") : 60121, w = b ? Symbol.for("react.fundamental") : 60117, x = b ? Symbol.for("react.responder") : 60118, y = b ? Symbol.for("react.scope") : 60119;
48
+ function z(a) {
49
+ if ("object" === typeof a && null !== a) {
50
+ var u = a.$$typeof;
51
+ switch (u) {
52
+ case c:
53
+ switch (a = a.type, a) {
54
+ case l:
55
+ case m:
56
+ case e:
57
+ case g:
58
+ case f:
59
+ case p:
60
+ return a;
61
+ default:
62
+ switch (a = a && a.$$typeof, a) {
63
+ case k:
64
+ case n:
65
+ case t:
66
+ case r:
67
+ case h:
68
+ return a;
69
+ default:
70
+ return u;
71
+ }
72
+ }
73
+ case d:
74
+ return u;
75
+ }
76
+ }
77
+ }
78
+ function A(a) {
79
+ return z(a) === m;
80
+ }
81
+ reactIs_production_min.AsyncMode = l;
82
+ reactIs_production_min.ConcurrentMode = m;
83
+ reactIs_production_min.ContextConsumer = k;
84
+ reactIs_production_min.ContextProvider = h;
85
+ reactIs_production_min.Element = c;
86
+ reactIs_production_min.ForwardRef = n;
87
+ reactIs_production_min.Fragment = e;
88
+ reactIs_production_min.Lazy = t;
89
+ reactIs_production_min.Memo = r;
90
+ reactIs_production_min.Portal = d;
91
+ reactIs_production_min.Profiler = g;
92
+ reactIs_production_min.StrictMode = f;
93
+ reactIs_production_min.Suspense = p;
94
+ reactIs_production_min.isAsyncMode = function(a) {
95
+ return A(a) || z(a) === l;
96
+ };
97
+ reactIs_production_min.isConcurrentMode = A;
98
+ reactIs_production_min.isContextConsumer = function(a) {
99
+ return z(a) === k;
100
+ };
101
+ reactIs_production_min.isContextProvider = function(a) {
102
+ return z(a) === h;
103
+ };
104
+ reactIs_production_min.isElement = function(a) {
105
+ return "object" === typeof a && null !== a && a.$$typeof === c;
106
+ };
107
+ reactIs_production_min.isForwardRef = function(a) {
108
+ return z(a) === n;
109
+ };
110
+ reactIs_production_min.isFragment = function(a) {
111
+ return z(a) === e;
112
+ };
113
+ reactIs_production_min.isLazy = function(a) {
114
+ return z(a) === t;
115
+ };
116
+ reactIs_production_min.isMemo = function(a) {
117
+ return z(a) === r;
118
+ };
119
+ reactIs_production_min.isPortal = function(a) {
120
+ return z(a) === d;
121
+ };
122
+ reactIs_production_min.isProfiler = function(a) {
123
+ return z(a) === g;
124
+ };
125
+ reactIs_production_min.isStrictMode = function(a) {
126
+ return z(a) === f;
127
+ };
128
+ reactIs_production_min.isSuspense = function(a) {
129
+ return z(a) === p;
130
+ };
131
+ reactIs_production_min.isValidElementType = function(a) {
132
+ return "string" === typeof a || "function" === typeof a || a === e || a === m || a === g || a === f || a === p || a === q || "object" === typeof a && null !== a && (a.$$typeof === t || a.$$typeof === r || a.$$typeof === h || a.$$typeof === k || a.$$typeof === n || a.$$typeof === w || a.$$typeof === x || a.$$typeof === y || a.$$typeof === v);
133
+ };
134
+ reactIs_production_min.typeOf = z;
135
+ return reactIs_production_min;
136
+ }
137
+ var reactIs_development = {};
138
+ /** @license React v16.13.1
139
+ * react-is.development.js
140
+ *
141
+ * Copyright (c) Facebook, Inc. and its affiliates.
142
+ *
143
+ * This source code is licensed under the MIT license found in the
144
+ * LICENSE file in the root directory of this source tree.
145
+ */
146
+ var hasRequiredReactIs_development;
147
+ function requireReactIs_development() {
148
+ if (hasRequiredReactIs_development) return reactIs_development;
149
+ hasRequiredReactIs_development = 1;
150
+ if (process.env.NODE_ENV !== "production") {
151
+ (function() {
152
+ var hasSymbol = typeof Symbol === "function" && Symbol.for;
153
+ var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for("react.element") : 60103;
154
+ var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for("react.portal") : 60106;
155
+ var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for("react.fragment") : 60107;
156
+ var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for("react.strict_mode") : 60108;
157
+ var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for("react.profiler") : 60114;
158
+ var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for("react.provider") : 60109;
159
+ var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for("react.context") : 60110;
160
+ var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for("react.async_mode") : 60111;
161
+ var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for("react.concurrent_mode") : 60111;
162
+ var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for("react.forward_ref") : 60112;
163
+ var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for("react.suspense") : 60113;
164
+ var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for("react.suspense_list") : 60120;
165
+ var REACT_MEMO_TYPE = hasSymbol ? Symbol.for("react.memo") : 60115;
166
+ var REACT_LAZY_TYPE = hasSymbol ? Symbol.for("react.lazy") : 60116;
167
+ var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for("react.block") : 60121;
168
+ var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for("react.fundamental") : 60117;
169
+ var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for("react.responder") : 60118;
170
+ var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for("react.scope") : 60119;
171
+ function isValidElementType(type) {
172
+ return typeof type === "string" || typeof type === "function" || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
173
+ type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === "object" && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE);
174
+ }
175
+ function typeOf(object) {
176
+ if (typeof object === "object" && object !== null) {
177
+ var $$typeof = object.$$typeof;
178
+ switch ($$typeof) {
179
+ case REACT_ELEMENT_TYPE:
180
+ var type = object.type;
181
+ switch (type) {
182
+ case REACT_ASYNC_MODE_TYPE:
183
+ case REACT_CONCURRENT_MODE_TYPE:
184
+ case REACT_FRAGMENT_TYPE:
185
+ case REACT_PROFILER_TYPE:
186
+ case REACT_STRICT_MODE_TYPE:
187
+ case REACT_SUSPENSE_TYPE:
188
+ return type;
189
+ default:
190
+ var $$typeofType = type && type.$$typeof;
191
+ switch ($$typeofType) {
192
+ case REACT_CONTEXT_TYPE:
193
+ case REACT_FORWARD_REF_TYPE:
194
+ case REACT_LAZY_TYPE:
195
+ case REACT_MEMO_TYPE:
196
+ case REACT_PROVIDER_TYPE:
197
+ return $$typeofType;
198
+ default:
199
+ return $$typeof;
200
+ }
201
+ }
202
+ case REACT_PORTAL_TYPE:
203
+ return $$typeof;
204
+ }
205
+ }
206
+ return void 0;
207
+ }
208
+ var AsyncMode = REACT_ASYNC_MODE_TYPE;
209
+ var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
210
+ var ContextConsumer = REACT_CONTEXT_TYPE;
211
+ var ContextProvider = REACT_PROVIDER_TYPE;
212
+ var Element = REACT_ELEMENT_TYPE;
213
+ var ForwardRef = REACT_FORWARD_REF_TYPE;
214
+ var Fragment = REACT_FRAGMENT_TYPE;
215
+ var Lazy = REACT_LAZY_TYPE;
216
+ var Memo = REACT_MEMO_TYPE;
217
+ var Portal = REACT_PORTAL_TYPE;
218
+ var Profiler = REACT_PROFILER_TYPE;
219
+ var StrictMode = REACT_STRICT_MODE_TYPE;
220
+ var Suspense = REACT_SUSPENSE_TYPE;
221
+ var hasWarnedAboutDeprecatedIsAsyncMode = false;
222
+ function isAsyncMode(object) {
223
+ {
224
+ if (!hasWarnedAboutDeprecatedIsAsyncMode) {
225
+ hasWarnedAboutDeprecatedIsAsyncMode = true;
226
+ console["warn"]("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.");
227
+ }
228
+ }
229
+ return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
230
+ }
231
+ function isConcurrentMode(object) {
232
+ return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
233
+ }
234
+ function isContextConsumer(object) {
235
+ return typeOf(object) === REACT_CONTEXT_TYPE;
236
+ }
237
+ function isContextProvider(object) {
238
+ return typeOf(object) === REACT_PROVIDER_TYPE;
239
+ }
240
+ function isElement(object) {
241
+ return typeof object === "object" && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
242
+ }
243
+ function isForwardRef(object) {
244
+ return typeOf(object) === REACT_FORWARD_REF_TYPE;
245
+ }
246
+ function isFragment(object) {
247
+ return typeOf(object) === REACT_FRAGMENT_TYPE;
248
+ }
249
+ function isLazy(object) {
250
+ return typeOf(object) === REACT_LAZY_TYPE;
251
+ }
252
+ function isMemo(object) {
253
+ return typeOf(object) === REACT_MEMO_TYPE;
254
+ }
255
+ function isPortal(object) {
256
+ return typeOf(object) === REACT_PORTAL_TYPE;
257
+ }
258
+ function isProfiler(object) {
259
+ return typeOf(object) === REACT_PROFILER_TYPE;
260
+ }
261
+ function isStrictMode(object) {
262
+ return typeOf(object) === REACT_STRICT_MODE_TYPE;
263
+ }
264
+ function isSuspense(object) {
265
+ return typeOf(object) === REACT_SUSPENSE_TYPE;
266
+ }
267
+ reactIs_development.AsyncMode = AsyncMode;
268
+ reactIs_development.ConcurrentMode = ConcurrentMode;
269
+ reactIs_development.ContextConsumer = ContextConsumer;
270
+ reactIs_development.ContextProvider = ContextProvider;
271
+ reactIs_development.Element = Element;
272
+ reactIs_development.ForwardRef = ForwardRef;
273
+ reactIs_development.Fragment = Fragment;
274
+ reactIs_development.Lazy = Lazy;
275
+ reactIs_development.Memo = Memo;
276
+ reactIs_development.Portal = Portal;
277
+ reactIs_development.Profiler = Profiler;
278
+ reactIs_development.StrictMode = StrictMode;
279
+ reactIs_development.Suspense = Suspense;
280
+ reactIs_development.isAsyncMode = isAsyncMode;
281
+ reactIs_development.isConcurrentMode = isConcurrentMode;
282
+ reactIs_development.isContextConsumer = isContextConsumer;
283
+ reactIs_development.isContextProvider = isContextProvider;
284
+ reactIs_development.isElement = isElement;
285
+ reactIs_development.isForwardRef = isForwardRef;
286
+ reactIs_development.isFragment = isFragment;
287
+ reactIs_development.isLazy = isLazy;
288
+ reactIs_development.isMemo = isMemo;
289
+ reactIs_development.isPortal = isPortal;
290
+ reactIs_development.isProfiler = isProfiler;
291
+ reactIs_development.isStrictMode = isStrictMode;
292
+ reactIs_development.isSuspense = isSuspense;
293
+ reactIs_development.isValidElementType = isValidElementType;
294
+ reactIs_development.typeOf = typeOf;
295
+ })();
296
+ }
297
+ return reactIs_development;
298
+ }
299
+ if (process.env.NODE_ENV === "production") {
300
+ reactIs$1.exports = requireReactIs_production_min();
301
+ } else {
302
+ reactIs$1.exports = requireReactIs_development();
303
+ }
304
+ var reactIsExports = reactIs$1.exports;
305
+ var reactIs = reactIsExports;
306
+ var FORWARD_REF_STATICS = {
307
+ "$$typeof": true,
308
+ render: true,
309
+ defaultProps: true,
310
+ displayName: true,
311
+ propTypes: true
312
+ };
313
+ var MEMO_STATICS = {
314
+ "$$typeof": true,
315
+ compare: true,
316
+ defaultProps: true,
317
+ displayName: true,
318
+ propTypes: true,
319
+ type: true
320
+ };
321
+ var TYPE_STATICS = {};
322
+ TYPE_STATICS[reactIs.ForwardRef] = FORWARD_REF_STATICS;
323
+ TYPE_STATICS[reactIs.Memo] = MEMO_STATICS;
324
+ function invariant(condition, message, Err) {
325
+ if (Err === void 0) {
326
+ Err = Error;
327
+ }
328
+ if (!condition) {
329
+ throw new Err(message);
330
+ }
331
+ }
332
+ var defaultErrorHandler = function(error) {
333
+ if (process.env.NODE_ENV !== "production") {
334
+ console.error(error);
335
+ }
336
+ };
337
+ var defaultWarnHandler = function(warning) {
338
+ if (process.env.NODE_ENV !== "production") {
339
+ console.warn(warning);
340
+ }
341
+ };
342
+ var DEFAULT_INTL_CONFIG = {
343
+ formats: {},
344
+ messages: {},
345
+ timeZone: void 0,
346
+ defaultLocale: "en",
347
+ defaultFormats: {},
348
+ fallbackOnEmptyString: true,
349
+ onError: defaultErrorHandler,
350
+ onWarn: defaultWarnHandler
351
+ };
352
+ function invariantIntlContext(intl) {
353
+ invariant(intl, "[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.");
354
+ }
355
+ __assign(__assign({}, DEFAULT_INTL_CONFIG), { textComponent: React.Fragment });
356
+ var IntlContext = typeof window !== "undefined" && !window.__REACT_INTL_BYPASS_GLOBAL_CONTEXT__ ? window.__REACT_INTL_CONTEXT__ || (window.__REACT_INTL_CONTEXT__ = React.createContext(null)) : React.createContext(null);
357
+ IntlContext.Consumer;
358
+ IntlContext.Provider;
359
+ var Context = IntlContext;
360
+ function useIntl() {
361
+ var intl = React.useContext(Context);
362
+ invariantIntlContext(intl);
363
+ return intl;
364
+ }
365
+ var DisplayName;
366
+ (function(DisplayName2) {
367
+ DisplayName2["formatDate"] = "FormattedDate";
368
+ DisplayName2["formatTime"] = "FormattedTime";
369
+ DisplayName2["formatNumber"] = "FormattedNumber";
370
+ DisplayName2["formatList"] = "FormattedList";
371
+ DisplayName2["formatDisplayName"] = "FormattedDisplayName";
372
+ })(DisplayName || (DisplayName = {}));
373
+ var DisplayNameParts;
374
+ (function(DisplayNameParts2) {
375
+ DisplayNameParts2["formatDate"] = "FormattedDateParts";
376
+ DisplayNameParts2["formatTime"] = "FormattedTimeParts";
377
+ DisplayNameParts2["formatNumber"] = "FormattedNumberParts";
378
+ DisplayNameParts2["formatList"] = "FormattedListParts";
379
+ })(DisplayNameParts || (DisplayNameParts = {}));
380
+ function createFormattedDateTimePartsComponent(name) {
381
+ var ComponentParts = function(props) {
382
+ var intl = useIntl();
383
+ var value = props.value, children = props.children, formatProps = __rest(props, ["value", "children"]);
384
+ var date = typeof value === "string" ? new Date(value || 0) : value;
385
+ var formattedParts = name === "formatDate" ? intl.formatDateToParts(date, formatProps) : intl.formatTimeToParts(date, formatProps);
386
+ return children(formattedParts);
387
+ };
388
+ ComponentParts.displayName = DisplayNameParts[name];
389
+ return ComponentParts;
390
+ }
391
+ function createFormattedComponent(name) {
392
+ var Component = function(props) {
393
+ var intl = useIntl();
394
+ var value = props.value, children = props.children, formatProps = __rest(
395
+ props,
396
+ ["value", "children"]
397
+ );
398
+ var formattedValue = intl[name](value, formatProps);
399
+ if (typeof children === "function") {
400
+ return children(formattedValue);
401
+ }
402
+ var Text = intl.textComponent || React.Fragment;
403
+ return React.createElement(Text, null, formattedValue);
404
+ };
405
+ Component.displayName = DisplayName[name];
406
+ return Component;
407
+ }
408
+ createFormattedComponent("formatDate");
409
+ createFormattedComponent("formatTime");
410
+ createFormattedComponent("formatNumber");
411
+ createFormattedComponent("formatList");
412
+ createFormattedComponent("formatDisplayName");
413
+ createFormattedDateTimePartsComponent("formatDate");
414
+ createFormattedDateTimePartsComponent("formatTime");
415
+ const useI18n = () => {
416
+ const { formatMessage } = useIntl();
417
+ const i18n = (key, defaultMessage) => {
418
+ return formatMessage({
419
+ id: `${pluginId}.${key}`,
420
+ defaultMessage
421
+ });
422
+ };
423
+ return {
424
+ i18n
425
+ };
426
+ };
427
+ function useAlert() {
428
+ const { toggleNotification } = useNotification();
429
+ const { i18n } = useI18n();
430
+ function handleNotification({
431
+ type = "info",
432
+ message = i18n(
433
+ "plugin.message.something",
434
+ "Something occurred in Meilisearch"
435
+ ),
436
+ link,
437
+ blockTransition = true,
438
+ title
439
+ }) {
440
+ toggleNotification({
441
+ // optional
442
+ title,
443
+ // required
444
+ // type: 'info|success|warning',
445
+ type,
446
+ // required
447
+ message: i18n("notification.meilisearch.message", message),
448
+ // optional
449
+ link,
450
+ // optional: default = false
451
+ blockTransition,
452
+ // optional
453
+ onClose: () => localStorage.setItem("STRAPI_UPDATE_NOTIF", "true")
454
+ });
455
+ }
456
+ const checkForbiddenError = ({ response }) => {
457
+ const status = response?.data?.error?.status;
458
+ if (status && status === 403) {
459
+ handleNotification({
460
+ title: i18n("plugin.message.forbidden.title", "Forbidden"),
461
+ type: "warning",
462
+ message: i18n(
463
+ "plugin.message.forbidden.description",
464
+ "You do not have permission to do this action"
465
+ ),
466
+ blockTransition: false
467
+ });
468
+ }
469
+ };
470
+ return {
471
+ handleNotification,
472
+ checkForbiddenError
473
+ };
474
+ }
475
+ function useCollection() {
476
+ const [collections, setCollections] = useState([]);
477
+ const [refetchIndex, setRefetchIndex] = useState(true);
478
+ const [reloadNeeded, setReloadNeeded] = useState(false);
479
+ const [realTimeReports, setRealTimeReports] = useState(false);
480
+ const { handleNotification, checkForbiddenError } = useAlert();
481
+ const { i18n } = useI18n();
482
+ const { get, del, post, put } = useFetchClient();
483
+ const refetchCollection = () => setRefetchIndex((prevRefetchIndex) => !prevRefetchIndex);
484
+ const hookingTextRendering = ({ indexed, listened }) => {
485
+ if (indexed && listened)
486
+ return i18n("plugin.table.td.hookingText.hooked", "Hooked");
487
+ if (!indexed && !listened) return "/";
488
+ return i18n("plugin.table.td.hookingText.reload", "Reload needed");
489
+ };
490
+ const fetchCollections = async () => {
491
+ try {
492
+ const {
493
+ data: { data, error }
494
+ } = await get(`/${pluginId}/content-type/`);
495
+ if (error) {
496
+ handleNotification({
497
+ type: "warning",
498
+ message: error.message,
499
+ link: error.link
500
+ });
501
+ } else {
502
+ const collections2 = data.contentTypes.map((collection) => {
503
+ collection["reloadNeeded"] = hookingTextRendering({
504
+ indexed: collection.indexed,
505
+ listened: collection.listened
506
+ });
507
+ return collection;
508
+ });
509
+ const reload = collections2.find(
510
+ (col) => col.reloadNeeded === i18n("plugin.table.td.hookingText.reload", "Reload needed")
511
+ );
512
+ const isIndexing = collections2.find((col) => col.isIndexing === true);
513
+ if (!isIndexing) setRealTimeReports(false);
514
+ else setRealTimeReports(true);
515
+ if (reload) {
516
+ setReloadNeeded(true);
517
+ } else setReloadNeeded(false);
518
+ setCollections(collections2);
519
+ }
520
+ } catch (error) {
521
+ checkForbiddenError(error);
522
+ }
523
+ };
524
+ const deleteCollection = async ({ contentType }) => {
525
+ try {
526
+ const {
527
+ data: { error }
528
+ } = await del(`/${pluginId}/content-type/${contentType}`);
529
+ if (error) {
530
+ handleNotification({
531
+ type: "warning",
532
+ message: error.message,
533
+ link: error.link
534
+ });
535
+ } else {
536
+ refetchCollection();
537
+ handleNotification({
538
+ type: "success",
539
+ message: i18n(
540
+ "plugin.message.success.delete",
541
+ "Request to delete content-type is successful"
542
+ ),
543
+ blockTransition: false
544
+ });
545
+ }
546
+ } catch (error) {
547
+ checkForbiddenError(error);
548
+ }
549
+ };
550
+ const addCollection = async ({ contentType }) => {
551
+ try {
552
+ const {
553
+ data: { error }
554
+ } = await post(`/${pluginId}/content-type`, {
555
+ contentType
556
+ });
557
+ console.log(error);
558
+ if (error) {
559
+ handleNotification({
560
+ type: "warning",
561
+ message: error.message,
562
+ link: error.link
563
+ });
564
+ } else {
565
+ refetchCollection();
566
+ handleNotification({
567
+ type: "success",
568
+ message: i18n(
569
+ "plugin.message.success.add",
570
+ "Request to add a content-type is successful"
571
+ ),
572
+ blockTransition: false
573
+ });
574
+ }
575
+ } catch (error) {
576
+ checkForbiddenError(error);
577
+ }
578
+ };
579
+ const updateCollection = async ({ contentType }) => {
580
+ try {
581
+ const {
582
+ data: { error }
583
+ } = await put(`/${pluginId}/content-type`, {
584
+ contentType
585
+ });
586
+ if (error) {
587
+ handleNotification({
588
+ type: "warning",
589
+ message: error.message,
590
+ link: error.link
591
+ });
592
+ } else {
593
+ refetchCollection();
594
+ handleNotification({
595
+ type: "success",
596
+ message: i18n(
597
+ "plugin.message.success.update",
598
+ "Request to update content-type is successful"
599
+ ),
600
+ blockTransition: false
601
+ });
602
+ }
603
+ } catch (error) {
604
+ checkForbiddenError(error);
605
+ }
606
+ };
607
+ useEffect(() => {
608
+ fetchCollections();
609
+ }, [refetchIndex]);
610
+ useEffect(() => {
611
+ let interval;
612
+ if (realTimeReports) {
613
+ interval = setInterval(() => {
614
+ refetchCollection();
615
+ }, 1e3);
616
+ } else {
617
+ clearInterval(interval);
618
+ }
619
+ return () => clearInterval(interval);
620
+ }, [realTimeReports]);
621
+ return {
622
+ collections,
623
+ deleteCollection,
624
+ addCollection,
625
+ updateCollection,
626
+ reloadNeeded,
627
+ refetchCollection,
628
+ handleNotification
629
+ };
630
+ }
631
+ const CollectionColumn = ({
632
+ entry,
633
+ deleteCollection,
634
+ addCollection,
635
+ updateCollection
636
+ }) => {
637
+ const { i18n } = useI18n();
638
+ const {
639
+ allowedActions: { canCreate, canUpdate, canDelete }
640
+ } = useRBAC(PERMISSIONS.collections);
641
+ return /* @__PURE__ */ jsxs(Tr, { children: [
642
+ (canCreate || canDelete) && /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(
643
+ Checkbox,
644
+ {
645
+ "aria-label": `Select ${entry.collection}`,
646
+ onCheckedChange: () => {
647
+ if (entry.indexed)
648
+ deleteCollection({ contentType: entry.contentType });
649
+ else addCollection({ contentType: entry.contentType });
650
+ },
651
+ checked: entry.indexed
652
+ }
653
+ ) }),
654
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: entry.collection }) }),
655
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: entry.indexed ? i18n("plugin.table.td.yes", "Yes") : i18n("plugin.table.td.no", "No") }) }),
656
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: entry.isIndexing ? i18n("plugin.table.td.yes", "Yes") : i18n("plugin.table.td.no", "No") }) }),
657
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: entry.indexUid }) }),
658
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Typography, { textColor: "neutral800", children: [
659
+ entry.numberOfDocuments,
660
+ " / ",
661
+ entry.numberOfEntries
662
+ ] }) }),
663
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", children: entry.reloadNeeded }) }),
664
+ canUpdate && /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(Box, { paddingLeft: 1, children: entry.indexed && /* @__PURE__ */ jsx(
665
+ Button,
666
+ {
667
+ onClick: () => updateCollection({ contentType: entry.contentType }),
668
+ size: "S",
669
+ variant: "secondary",
670
+ children: i18n("plugin.update", "Update")
671
+ }
672
+ ) }) }) })
673
+ ] }, entry.contentType);
674
+ };
675
+ const CollectionColumn$1 = memo(CollectionColumn);
676
+ const CollectionTableHeader = () => {
677
+ const { i18n } = useI18n();
678
+ const {
679
+ allowedActions: { canCreate, canUpdate, canDelete }
680
+ } = useRBAC(PERMISSIONS.collections);
681
+ return /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
682
+ (canCreate || canDelete) && /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(VisuallyHidden, { children: "INDEX" }) }),
683
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: i18n("plugin.table.header.name", "NAME") }) }),
684
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: i18n("plugin.table.header.in-meilisearch", "IN MEILISEARCH ?") }) }),
685
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: i18n("plugin.table.header.indexing", "INDEXING ?") }) }),
686
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: i18n("plugin.table.header.index-name", "INDEX NAME") }) }),
687
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: i18n("plugin.table.header.documents", "DOCUMENTS") }) }),
688
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", children: i18n("plugin.table.header.hooks", "HOOKS") }) }),
689
+ canUpdate && /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(VisuallyHidden, { children: "Actions" }) })
690
+ ] }) });
691
+ };
692
+ const CollectionTableHeader$1 = memo(CollectionTableHeader);
693
+ const SERVER_HAS_NOT_BEEN_KILLED_MESSAGE = "did-not-kill-server";
694
+ const SERVER_HAS_BEEN_KILLED_MESSAGE = "server is down";
695
+ function serverRestartWatcher(response, didShutDownServer) {
696
+ return new Promise((resolve) => {
697
+ fetch(`${window.strapi.backendURL}/_health`, {
698
+ method: "HEAD",
699
+ mode: "no-cors",
700
+ headers: {
701
+ "Content-Type": "application/json",
702
+ "Keep-Alive": "false"
703
+ }
704
+ }).then((res) => {
705
+ if (res.status >= 400) {
706
+ throw new Error(SERVER_HAS_BEEN_KILLED_MESSAGE);
707
+ }
708
+ if (!didShutDownServer) {
709
+ throw new Error(SERVER_HAS_NOT_BEEN_KILLED_MESSAGE);
710
+ }
711
+ resolve(response);
712
+ }).catch((err) => {
713
+ setTimeout(() => {
714
+ return serverRestartWatcher(
715
+ response,
716
+ err.message !== SERVER_HAS_NOT_BEEN_KILLED_MESSAGE
717
+ ).then(resolve);
718
+ }, 100);
719
+ });
720
+ });
721
+ }
722
+ const Collection = () => {
723
+ const {
724
+ collections,
725
+ deleteCollection,
726
+ addCollection,
727
+ updateCollection,
728
+ reloadNeeded,
729
+ refetchCollection
730
+ } = useCollection();
731
+ const { lockAppWithAutoreload, unlockAppWithAutoreload } = private_useAutoReloadOverlayBlocker();
732
+ const { get } = useFetchClient();
733
+ const [reload, setReload] = useState(false);
734
+ const { i18n } = useI18n();
735
+ const ROW_COUNT = 6;
736
+ const COL_COUNT = 10;
737
+ const reloadServer = async () => {
738
+ try {
739
+ lockAppWithAutoreload();
740
+ await get(`/${pluginId}/reload`, true);
741
+ await serverRestartWatcher(true);
742
+ setReload(false);
743
+ } catch (err) {
744
+ console.error(err);
745
+ } finally {
746
+ unlockAppWithAutoreload();
747
+ refetchCollection();
748
+ }
749
+ };
750
+ useEffect(() => {
751
+ if (reload) reloadServer();
752
+ }, [reload]);
753
+ return /* @__PURE__ */ jsxs(Box, { background: "neutral100", children: [
754
+ /* @__PURE__ */ jsxs(Table, { colCount: COL_COUNT, rowCount: ROW_COUNT, children: [
755
+ /* @__PURE__ */ jsx(CollectionTableHeader$1, {}),
756
+ /* @__PURE__ */ jsx(Tbody, { children: collections.map((collection) => /* @__PURE__ */ jsx(
757
+ CollectionColumn$1,
758
+ {
759
+ entry: collection,
760
+ deleteCollection,
761
+ addCollection,
762
+ updateCollection
763
+ },
764
+ collection.collection
765
+ )) })
766
+ ] }),
767
+ reloadNeeded && /* @__PURE__ */ jsx(Box, { padding: 5, children: /* @__PURE__ */ jsx(Button, { onClick: () => setReload(true), children: i18n("plugin.reload-server", "Reload server") }) })
768
+ ] });
769
+ };
770
+ const CollectionTable = memo(Collection);
771
+ function useCredential() {
772
+ const [credentials, setCredentials] = useState({
773
+ host: "",
774
+ apiKey: "",
775
+ ApiKeyIsFromConfigFile: true,
776
+ HostIsFromConfigFile: true
777
+ });
778
+ const [refetchIndex, setRefetchIndex] = useState(true);
779
+ const [host, setHost] = useState("");
780
+ const [apiKey, setApiKey] = useState("");
781
+ const { handleNotification } = useAlert();
782
+ const { i18n } = useI18n();
783
+ const { get, post } = useFetchClient();
784
+ const refetchCredentials = () => setRefetchIndex((prevRefetchIndex) => !prevRefetchIndex);
785
+ const updateCredentials = async () => {
786
+ const {
787
+ data: { error }
788
+ } = await post(`/${pluginId}/credential`, {
789
+ apiKey,
790
+ host
791
+ });
792
+ if (error) {
793
+ handleNotification({
794
+ type: "warning",
795
+ message: error.message,
796
+ link: error.link
797
+ });
798
+ } else {
799
+ refetchCredentials();
800
+ handleNotification({
801
+ type: "success",
802
+ message: i18n(
803
+ "plugin.message.success.credentials",
804
+ "Credentials sucessfully updated!"
805
+ ),
806
+ blockTransition: false
807
+ });
808
+ }
809
+ };
810
+ const fetchCredentials = async () => {
811
+ const {
812
+ data: { data, error }
813
+ } = await get(`/${pluginId}/credential`);
814
+ if (error) {
815
+ handleNotification({
816
+ type: "warning",
817
+ message: error.message,
818
+ link: error.link
819
+ });
820
+ } else {
821
+ setCredentials(data);
822
+ setHost(data.host);
823
+ setApiKey(data.apiKey);
824
+ }
825
+ };
826
+ useEffect(() => {
827
+ fetchCredentials();
828
+ }, [refetchIndex]);
829
+ return {
830
+ credentials,
831
+ updateCredentials,
832
+ setHost,
833
+ setApiKey,
834
+ host,
835
+ apiKey
836
+ };
837
+ }
838
+ const Credentials = () => {
839
+ const { host, apiKey, credentials, setHost, setApiKey, updateCredentials } = useCredential();
840
+ const { i18n } = useI18n();
841
+ const {
842
+ allowedActions: { canEdit }
843
+ } = useRBAC(PERMISSIONS.settingsEdit);
844
+ return /* @__PURE__ */ jsxs(Box, { children: [
845
+ /* @__PURE__ */ jsx(Box, { padding: 2, children: /* @__PURE__ */ jsxs(
846
+ Field.Root,
847
+ {
848
+ id: "host",
849
+ hint: i18n(
850
+ "plugin.tab.settings.input.url.hint",
851
+ "The URL on which your Meilisearch is running"
852
+ ),
853
+ children: [
854
+ /* @__PURE__ */ jsx(Field.Label, { children: i18n("plugin.tab.settings.input.url.label", "Meilisearch URL") }),
855
+ /* @__PURE__ */ jsx(
856
+ Field.Input,
857
+ {
858
+ type: "text",
859
+ name: "host",
860
+ value: host,
861
+ placeholder: i18n(
862
+ "plugin.tab.settings.input.url.placeholder",
863
+ "URL"
864
+ ),
865
+ onChange: (e) => setHost(e.target.value),
866
+ disabled: credentials.HostIsFromConfigFile
867
+ }
868
+ ),
869
+ /* @__PURE__ */ jsx(Field.Hint, {})
870
+ ]
871
+ }
872
+ ) }),
873
+ /* @__PURE__ */ jsx(Box, { padding: 2, children: /* @__PURE__ */ jsxs(
874
+ Field.Root,
875
+ {
876
+ id: "apiKey",
877
+ hint: i18n(
878
+ "plugin.tab.settings.input.apiKey.hint",
879
+ "A valid API key with enough permission to create indexes (or the master key)."
880
+ ),
881
+ children: [
882
+ /* @__PURE__ */ jsx(Field.Label, { children: i18n(
883
+ "plugin.tab.settings.input.apiKey.label",
884
+ "Meilisearch API Key"
885
+ ) }),
886
+ /* @__PURE__ */ jsx(
887
+ Field.Input,
888
+ {
889
+ type: "password",
890
+ name: "apiKey",
891
+ placeholder: i18n(
892
+ "plugin.tab.settings.input.apiKey.placeholder",
893
+ "API key"
894
+ ),
895
+ value: apiKey,
896
+ onChange: (e) => setApiKey(e.target.value),
897
+ disabled: credentials.ApiKeyIsFromConfigFile
898
+ }
899
+ ),
900
+ /* @__PURE__ */ jsx(Field.Hint, {})
901
+ ]
902
+ }
903
+ ) }),
904
+ /* @__PURE__ */ jsx(Box, { paddingTop: 1, paddingLeft: 2, children: /* @__PURE__ */ jsxs(Typography, { variant: "pi", style: { color: "red" }, children: [
905
+ i18n(
906
+ "plugin.tab.settings.warning.credentials.1",
907
+ "Do not use this API key on your front-end as it has too much rights. Instead, use the public key available using"
908
+ ),
909
+ " ",
910
+ /* @__PURE__ */ jsx(
911
+ Link,
912
+ {
913
+ isExternal: true,
914
+ href: "https://www.meilisearch.com/docs/reference/api/keys#get-keys",
915
+ children: /* @__PURE__ */ jsx(Typography, { variant: "pi", style: { color: "red" }, children: i18n(
916
+ "plugin.tab.settings.warning.credentials.2",
917
+ "the key route"
918
+ ) })
919
+ }
920
+ ),
921
+ "."
922
+ ] }) }),
923
+ /* @__PURE__ */ jsx(Box, { paddingTop: 2, paddingLeft: 2, paddingRight: 2, paddingBottom: 2, children: canEdit && /* @__PURE__ */ jsx(
924
+ Button,
925
+ {
926
+ variant: "secondary",
927
+ onClick: () => updateCredentials(),
928
+ disabled: credentials.ApiKeyIsFromConfigFile && credentials.HostIsFromConfigFile,
929
+ children: i18n("plugin.save", "Save")
930
+ }
931
+ ) })
932
+ ] });
933
+ };
934
+ const Credentials$1 = memo(Credentials);
935
+ const Settings = () => {
936
+ return /* @__PURE__ */ jsx(Box, { padding: 5, children: /* @__PURE__ */ jsx(Credentials$1, {}) });
937
+ };
938
+ const PluginTabs = () => {
939
+ const { i18n } = useI18n();
940
+ const { allowedActions: allowedActionsCollection } = useRBAC(
941
+ PERMISSIONS.collections
942
+ );
943
+ const { allowedActions: allowedActionsSettings } = useRBAC(
944
+ PERMISSIONS.settings
945
+ );
946
+ const canSeeCollections = Object.values(allowedActionsCollection).some(
947
+ (value) => !!value
948
+ );
949
+ const canSeeSettings = Object.values(allowedActionsSettings).some(
950
+ (value) => !!value
951
+ );
952
+ return /* @__PURE__ */ jsxs(Tabs.Root, { defaultValue: "collections", children: [
953
+ /* @__PURE__ */ jsxs(Tabs.List, { children: [
954
+ /* @__PURE__ */ jsx(Tabs.Trigger, { value: "collections", children: i18n("plugin.tab.collections", "Collections") }),
955
+ /* @__PURE__ */ jsx(Tabs.Trigger, { value: "settings", children: i18n("plugin.tab.settings", "Settings") })
956
+ ] }),
957
+ /* @__PURE__ */ jsx(Tabs.Content, { value: "collections", children: canSeeCollections && /* @__PURE__ */ jsx(Box, { color: "neutral800", padding: 4, background: "neutral0", children: /* @__PURE__ */ jsx(CollectionTable, {}) }) }),
958
+ /* @__PURE__ */ jsx(Tabs.Content, { value: "settings", children: canSeeSettings && /* @__PURE__ */ jsx(Box, { color: "neutral800", padding: 4, background: "neutral0", children: /* @__PURE__ */ jsx(Settings, {}) }) })
959
+ ] });
960
+ };
961
+ const HomePage = () => {
962
+ const { i18n } = useI18n();
963
+ return /* @__PURE__ */ jsx(private_AutoReloadOverlayBlockerProvider, { children: /* @__PURE__ */ jsxs(Page.Main, { children: [
964
+ /* @__PURE__ */ jsx(
965
+ Layouts.Header,
966
+ {
967
+ title: i18n("plugin.name", "Meilisearch"),
968
+ subtitle: i18n(
969
+ "plugin.description",
970
+ "Search in your content-types with the Meilisearch plugin"
971
+ ),
972
+ navigationAction: /* @__PURE__ */ jsx(BackButton, {})
973
+ }
974
+ ),
975
+ /* @__PURE__ */ jsx(Layouts.Content, { children: /* @__PURE__ */ jsx(PluginTabs, {}) })
976
+ ] }) });
977
+ };
978
+ const App = () => {
979
+ return /* @__PURE__ */ jsx(Page.Protect, { permissions: PERMISSIONS.main, children: /* @__PURE__ */ jsxs(Routes, { children: [
980
+ /* @__PURE__ */ jsx(Route, { index: true, element: /* @__PURE__ */ jsx(HomePage, {}) }),
981
+ /* @__PURE__ */ jsx(Route, { path: "*", element: /* @__PURE__ */ jsx(Page.Error, {}) })
982
+ ] }) });
983
+ };
984
+ export {
985
+ App
986
+ };