@bigbinary/neeto-webhooks-frontend 2.0.2 → 2.1.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.
@@ -0,0 +1,1714 @@
1
+ import React, { useState, useRef, useEffect, useCallback } from 'react';
2
+ import { prop, pluck, assoc, mergeRight } from 'ramda';
3
+ import { useRouteMatch, useHistory, useParams, Switch as Switch$1, Route } from 'react-router-dom';
4
+ import { isPresent, removeBy, isNotEmpty, removeById, findBy } from '@bigbinary/neeto-cist';
5
+ import { DEFAULT_STALE_TIME, SINGULAR, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_INDEX, PLURAL } from '@bigbinary/neeto-commons-frontend/constants';
6
+ import { useQueryParams, useMutationWithInvalidation, withT } from '@bigbinary/neeto-commons-frontend/react-utils';
7
+ import Container from '@bigbinary/neeto-molecules/Container';
8
+ import Header$2 from '@bigbinary/neeto-molecules/Header';
9
+ import HelpPopover from '@bigbinary/neeto-molecules/HelpPopover';
10
+ import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
11
+ import TableWrapper from '@bigbinary/neeto-molecules/TableWrapper';
12
+ import NoData from '@bigbinary/neetoui/NoData';
13
+ import Table from '@bigbinary/neetoui/Table';
14
+ import { useTranslation } from 'react-i18next';
15
+ import { QueryClient, QueryCache, QueryClientProvider, useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
16
+ import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
17
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
18
+ import axios from 'axios';
19
+ import DateFormat from '@bigbinary/neeto-molecules/DateFormat';
20
+ import Button from '@bigbinary/neetoui/Button';
21
+ import Pane from '@bigbinary/neetoui/Pane';
22
+ import Typography from '@bigbinary/neetoui/Typography';
23
+ import Tab from '@bigbinary/neetoui/Tab';
24
+ import Tag from '@bigbinary/neetoui/Tag';
25
+ import { t as t$1 } from 'i18next';
26
+ import { buildUrl } from '@bigbinary/neeto-commons-frontend/utils';
27
+ import Alert from '@bigbinary/neetoui/Alert';
28
+ import Plus from '@bigbinary/neeto-icons/Plus';
29
+ import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
30
+ import Spinner from '@bigbinary/neetoui/Spinner';
31
+ import Input from '@bigbinary/neetoui/formik/Input';
32
+ import Form from '@bigbinary/neetoui/formik/Form';
33
+ import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
34
+ import Select from '@bigbinary/neetoui/formik/Select';
35
+ import Switch from '@bigbinary/neetoui/formik/Switch';
36
+ import Textarea from '@bigbinary/neetoui/formik/Textarea';
37
+ import * as yup from 'yup';
38
+
39
+ var HELP_LINK_URLS = {
40
+ webhook: "https://neetocalhelp.neetokb.com/p/a-4bb6c2a2",
41
+ secrets: "https://neetocalhelp.neetokb.com/p/a-80de90bd",
42
+ deliveries: "https://help.neetocal.com/articles/managing-webhook-deliveries"
43
+ };
44
+
45
+ var getDeliveriesPath = function getDeliveriesPath(webhooksPath) {
46
+ return "".concat(webhooksPath, "/:webhookId/deliveries");
47
+ };
48
+ var getDeliveryDetailsPath = function getDeliveryDetailsPath(deliveriesPath) {
49
+ return "".concat(deliveriesPath, "/:deliveryId/");
50
+ };
51
+
52
+ function _arrayLikeToArray(arr, len) {
53
+ if (len == null || len > arr.length) len = arr.length;
54
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
55
+ return arr2;
56
+ }
57
+
58
+ function _arrayWithoutHoles(arr) {
59
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
60
+ }
61
+
62
+ function _iterableToArray(iter) {
63
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
64
+ }
65
+
66
+ function _unsupportedIterableToArray(o, minLen) {
67
+ if (!o) return;
68
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
69
+ var n = Object.prototype.toString.call(o).slice(8, -1);
70
+ if (n === "Object" && o.constructor) n = o.constructor.name;
71
+ if (n === "Map" || n === "Set") return Array.from(o);
72
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
73
+ }
74
+
75
+ function _nonIterableSpread() {
76
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
77
+ }
78
+
79
+ function _toConsumableArray(arr) {
80
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
81
+ }
82
+
83
+ function _typeof$1(o) {
84
+ "@babel/helpers - typeof";
85
+
86
+ return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
87
+ return typeof o;
88
+ } : function (o) {
89
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
90
+ }, _typeof$1(o);
91
+ }
92
+
93
+ function _toPrimitive(input, hint) {
94
+ if (_typeof$1(input) !== "object" || input === null) return input;
95
+ var prim = input[Symbol.toPrimitive];
96
+ if (prim !== undefined) {
97
+ var res = prim.call(input, hint || "default");
98
+ if (_typeof$1(res) !== "object") return res;
99
+ throw new TypeError("@@toPrimitive must return a primitive value.");
100
+ }
101
+ return (hint === "string" ? String : Number)(input);
102
+ }
103
+
104
+ function _toPropertyKey(arg) {
105
+ var key = _toPrimitive(arg, "string");
106
+ return _typeof$1(key) === "symbol" ? key : String(key);
107
+ }
108
+
109
+ function _defineProperty(obj, key, value) {
110
+ key = _toPropertyKey(key);
111
+ if (key in obj) {
112
+ Object.defineProperty(obj, key, {
113
+ value: value,
114
+ enumerable: true,
115
+ configurable: true,
116
+ writable: true
117
+ });
118
+ } else {
119
+ obj[key] = value;
120
+ }
121
+ return obj;
122
+ }
123
+
124
+ var queryClient = new QueryClient({
125
+ queryCache: new QueryCache(),
126
+ defaultOptions: {
127
+ queries: {
128
+ staleTime: DEFAULT_STALE_TIME
129
+ }
130
+ }
131
+ });
132
+
133
+ function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
134
+ function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
135
+ var withReactQuery = function withReactQuery(Component) {
136
+ var QueryWrapper = function QueryWrapper(props) {
137
+ return /*#__PURE__*/jsxs(QueryClientProvider, {
138
+ client: queryClient,
139
+ children: [/*#__PURE__*/jsx(Component, _objectSpread$2({}, props)), /*#__PURE__*/jsx(ReactQueryDevtools, {
140
+ initialIsOpen: false,
141
+ position: "bottom"
142
+ })]
143
+ });
144
+ };
145
+ return QueryWrapper;
146
+ };
147
+
148
+ var baseUrl$2 = "/webhooks";
149
+ var fetch$1 = function fetch(webhookId, params) {
150
+ return axios.get("".concat(baseUrl$2, "/webhooks/").concat(webhookId, "/deliveries"), {
151
+ params: params
152
+ });
153
+ };
154
+ var show$1 = function show(id, webhookId) {
155
+ return axios.get("".concat(baseUrl$2, "/webhooks/").concat(webhookId, "/deliveries/").concat(id));
156
+ };
157
+ var redeliver = function redeliver(delivery_id, webhookId) {
158
+ return axios.post("".concat(baseUrl$2, "/webhooks/").concat(webhookId, "/deliveries/").concat(delivery_id, "/redeliver"));
159
+ };
160
+ var deliveriesApi = {
161
+ fetch: fetch$1,
162
+ show: show$1,
163
+ redeliver: redeliver
164
+ };
165
+
166
+ var QUERY_KEYS = {
167
+ DELIVERY_LIST: "delivery-list",
168
+ DELIVERY_DETAILS: "delivery-details",
169
+ WEBHOOK_LIST: "webhook-list",
170
+ WEBHOOK_DETAILS: "webhook-details",
171
+ EVENTS_LIST: "events-list"
172
+ };
173
+ var DELIVERY_STALE_TIME = 3200000; // 1 hour
174
+ var WEBHOOK_STALE_TIME = 3200000; // 1 hour
175
+ var POST_REDELIVERY_ON_SUCCESS_TIMEOUT = 5000; // 5 seconds
176
+
177
+ var useFetchDeliveries = function useFetchDeliveries(webhookId, params) {
178
+ return useQuery({
179
+ queryKey: [QUERY_KEYS.DELIVERY_LIST, webhookId, params],
180
+ queryFn: function queryFn() {
181
+ return deliveriesApi.fetch(webhookId, params);
182
+ },
183
+ staleTime: DELIVERY_STALE_TIME
184
+ });
185
+ };
186
+ var useShowDelivery = function useShowDelivery(id, webhookId) {
187
+ return useQuery({
188
+ queryKey: [QUERY_KEYS.DELIVERY_DETAILS, id, webhookId],
189
+ queryFn: function queryFn() {
190
+ return deliveriesApi.show(id, webhookId);
191
+ },
192
+ staleTime: DELIVERY_STALE_TIME,
193
+ enabled: !!id
194
+ });
195
+ };
196
+ var useRedeliverWebhook = function useRedeliverWebhook(deliveryId, webhookSid) {
197
+ var queryClient = useQueryClient();
198
+ return useMutation({
199
+ mutationFn: function mutationFn() {
200
+ return deliveriesApi.redeliver(deliveryId, webhookSid);
201
+ },
202
+ onSuccess: function onSuccess() {
203
+ setTimeout(function () {
204
+ return queryClient.invalidateQueries({
205
+ queryKey: [QUERY_KEYS.DELIVERY_LIST]
206
+ });
207
+ }, POST_REDELIVERY_ON_SUCCESS_TIMEOUT);
208
+ }
209
+ });
210
+ };
211
+
212
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
213
+ try {
214
+ var info = gen[key](arg);
215
+ var value = info.value;
216
+ } catch (error) {
217
+ reject(error);
218
+ return;
219
+ }
220
+ if (info.done) {
221
+ resolve(value);
222
+ } else {
223
+ Promise.resolve(value).then(_next, _throw);
224
+ }
225
+ }
226
+ function _asyncToGenerator(fn) {
227
+ return function () {
228
+ var self = this,
229
+ args = arguments;
230
+ return new Promise(function (resolve, reject) {
231
+ var gen = fn.apply(self, args);
232
+ function _next(value) {
233
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
234
+ }
235
+ function _throw(err) {
236
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
237
+ }
238
+ _next(undefined);
239
+ });
240
+ };
241
+ }
242
+
243
+ function getDefaultExportFromCjs (x) {
244
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
245
+ }
246
+
247
+ var regeneratorRuntime$1 = {exports: {}};
248
+
249
+ var _typeof = {exports: {}};
250
+
251
+ _typeof.exports;
252
+
253
+ (function (module) {
254
+ function _typeof(o) {
255
+ "@babel/helpers - typeof";
256
+
257
+ return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
258
+ return typeof o;
259
+ } : function (o) {
260
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
261
+ }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(o);
262
+ }
263
+ module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
264
+ } (_typeof));
265
+
266
+ var _typeofExports = _typeof.exports;
267
+
268
+ regeneratorRuntime$1.exports;
269
+
270
+ (function (module) {
271
+ var _typeof = _typeofExports["default"];
272
+ function _regeneratorRuntime() {
273
+ module.exports = _regeneratorRuntime = function _regeneratorRuntime() {
274
+ return e;
275
+ }, module.exports.__esModule = true, module.exports["default"] = module.exports;
276
+ var t,
277
+ e = {},
278
+ r = Object.prototype,
279
+ n = r.hasOwnProperty,
280
+ o = Object.defineProperty || function (t, e, r) {
281
+ t[e] = r.value;
282
+ },
283
+ i = "function" == typeof Symbol ? Symbol : {},
284
+ a = i.iterator || "@@iterator",
285
+ c = i.asyncIterator || "@@asyncIterator",
286
+ u = i.toStringTag || "@@toStringTag";
287
+ function define(t, e, r) {
288
+ return Object.defineProperty(t, e, {
289
+ value: r,
290
+ enumerable: !0,
291
+ configurable: !0,
292
+ writable: !0
293
+ }), t[e];
294
+ }
295
+ try {
296
+ define({}, "");
297
+ } catch (t) {
298
+ define = function define(t, e, r) {
299
+ return t[e] = r;
300
+ };
301
+ }
302
+ function wrap(t, e, r, n) {
303
+ var i = e && e.prototype instanceof Generator ? e : Generator,
304
+ a = Object.create(i.prototype),
305
+ c = new Context(n || []);
306
+ return o(a, "_invoke", {
307
+ value: makeInvokeMethod(t, r, c)
308
+ }), a;
309
+ }
310
+ function tryCatch(t, e, r) {
311
+ try {
312
+ return {
313
+ type: "normal",
314
+ arg: t.call(e, r)
315
+ };
316
+ } catch (t) {
317
+ return {
318
+ type: "throw",
319
+ arg: t
320
+ };
321
+ }
322
+ }
323
+ e.wrap = wrap;
324
+ var h = "suspendedStart",
325
+ l = "suspendedYield",
326
+ f = "executing",
327
+ s = "completed",
328
+ y = {};
329
+ function Generator() {}
330
+ function GeneratorFunction() {}
331
+ function GeneratorFunctionPrototype() {}
332
+ var p = {};
333
+ define(p, a, function () {
334
+ return this;
335
+ });
336
+ var d = Object.getPrototypeOf,
337
+ v = d && d(d(values([])));
338
+ v && v !== r && n.call(v, a) && (p = v);
339
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
340
+ function defineIteratorMethods(t) {
341
+ ["next", "throw", "return"].forEach(function (e) {
342
+ define(t, e, function (t) {
343
+ return this._invoke(e, t);
344
+ });
345
+ });
346
+ }
347
+ function AsyncIterator(t, e) {
348
+ function invoke(r, o, i, a) {
349
+ var c = tryCatch(t[r], t, o);
350
+ if ("throw" !== c.type) {
351
+ var u = c.arg,
352
+ h = u.value;
353
+ return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
354
+ invoke("next", t, i, a);
355
+ }, function (t) {
356
+ invoke("throw", t, i, a);
357
+ }) : e.resolve(h).then(function (t) {
358
+ u.value = t, i(u);
359
+ }, function (t) {
360
+ return invoke("throw", t, i, a);
361
+ });
362
+ }
363
+ a(c.arg);
364
+ }
365
+ var r;
366
+ o(this, "_invoke", {
367
+ value: function value(t, n) {
368
+ function callInvokeWithMethodAndArg() {
369
+ return new e(function (e, r) {
370
+ invoke(t, n, e, r);
371
+ });
372
+ }
373
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
374
+ }
375
+ });
376
+ }
377
+ function makeInvokeMethod(e, r, n) {
378
+ var o = h;
379
+ return function (i, a) {
380
+ if (o === f) throw new Error("Generator is already running");
381
+ if (o === s) {
382
+ if ("throw" === i) throw a;
383
+ return {
384
+ value: t,
385
+ done: !0
386
+ };
387
+ }
388
+ for (n.method = i, n.arg = a;;) {
389
+ var c = n.delegate;
390
+ if (c) {
391
+ var u = maybeInvokeDelegate(c, n);
392
+ if (u) {
393
+ if (u === y) continue;
394
+ return u;
395
+ }
396
+ }
397
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
398
+ if (o === h) throw o = s, n.arg;
399
+ n.dispatchException(n.arg);
400
+ } else "return" === n.method && n.abrupt("return", n.arg);
401
+ o = f;
402
+ var p = tryCatch(e, r, n);
403
+ if ("normal" === p.type) {
404
+ if (o = n.done ? s : l, p.arg === y) continue;
405
+ return {
406
+ value: p.arg,
407
+ done: n.done
408
+ };
409
+ }
410
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
411
+ }
412
+ };
413
+ }
414
+ function maybeInvokeDelegate(e, r) {
415
+ var n = r.method,
416
+ o = e.iterator[n];
417
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
418
+ var i = tryCatch(o, e.iterator, r.arg);
419
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
420
+ var a = i.arg;
421
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
422
+ }
423
+ function pushTryEntry(t) {
424
+ var e = {
425
+ tryLoc: t[0]
426
+ };
427
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
428
+ }
429
+ function resetTryEntry(t) {
430
+ var e = t.completion || {};
431
+ e.type = "normal", delete e.arg, t.completion = e;
432
+ }
433
+ function Context(t) {
434
+ this.tryEntries = [{
435
+ tryLoc: "root"
436
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
437
+ }
438
+ function values(e) {
439
+ if (e || "" === e) {
440
+ var r = e[a];
441
+ if (r) return r.call(e);
442
+ if ("function" == typeof e.next) return e;
443
+ if (!isNaN(e.length)) {
444
+ var o = -1,
445
+ i = function next() {
446
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
447
+ return next.value = t, next.done = !0, next;
448
+ };
449
+ return i.next = i;
450
+ }
451
+ }
452
+ throw new TypeError(_typeof(e) + " is not iterable");
453
+ }
454
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
455
+ value: GeneratorFunctionPrototype,
456
+ configurable: !0
457
+ }), o(GeneratorFunctionPrototype, "constructor", {
458
+ value: GeneratorFunction,
459
+ configurable: !0
460
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
461
+ var e = "function" == typeof t && t.constructor;
462
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
463
+ }, e.mark = function (t) {
464
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
465
+ }, e.awrap = function (t) {
466
+ return {
467
+ __await: t
468
+ };
469
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
470
+ return this;
471
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
472
+ void 0 === i && (i = Promise);
473
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
474
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
475
+ return t.done ? t.value : a.next();
476
+ });
477
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
478
+ return this;
479
+ }), define(g, "toString", function () {
480
+ return "[object Generator]";
481
+ }), e.keys = function (t) {
482
+ var e = Object(t),
483
+ r = [];
484
+ for (var n in e) r.push(n);
485
+ return r.reverse(), function next() {
486
+ for (; r.length;) {
487
+ var t = r.pop();
488
+ if (t in e) return next.value = t, next.done = !1, next;
489
+ }
490
+ return next.done = !0, next;
491
+ };
492
+ }, e.values = values, Context.prototype = {
493
+ constructor: Context,
494
+ reset: function reset(e) {
495
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
496
+ },
497
+ stop: function stop() {
498
+ this.done = !0;
499
+ var t = this.tryEntries[0].completion;
500
+ if ("throw" === t.type) throw t.arg;
501
+ return this.rval;
502
+ },
503
+ dispatchException: function dispatchException(e) {
504
+ if (this.done) throw e;
505
+ var r = this;
506
+ function handle(n, o) {
507
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
508
+ }
509
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
510
+ var i = this.tryEntries[o],
511
+ a = i.completion;
512
+ if ("root" === i.tryLoc) return handle("end");
513
+ if (i.tryLoc <= this.prev) {
514
+ var c = n.call(i, "catchLoc"),
515
+ u = n.call(i, "finallyLoc");
516
+ if (c && u) {
517
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
518
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
519
+ } else if (c) {
520
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
521
+ } else {
522
+ if (!u) throw new Error("try statement without catch or finally");
523
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
524
+ }
525
+ }
526
+ }
527
+ },
528
+ abrupt: function abrupt(t, e) {
529
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
530
+ var o = this.tryEntries[r];
531
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
532
+ var i = o;
533
+ break;
534
+ }
535
+ }
536
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
537
+ var a = i ? i.completion : {};
538
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
539
+ },
540
+ complete: function complete(t, e) {
541
+ if ("throw" === t.type) throw t.arg;
542
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
543
+ },
544
+ finish: function finish(t) {
545
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
546
+ var r = this.tryEntries[e];
547
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
548
+ }
549
+ },
550
+ "catch": function _catch(t) {
551
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
552
+ var r = this.tryEntries[e];
553
+ if (r.tryLoc === t) {
554
+ var n = r.completion;
555
+ if ("throw" === n.type) {
556
+ var o = n.arg;
557
+ resetTryEntry(r);
558
+ }
559
+ return o;
560
+ }
561
+ }
562
+ throw new Error("illegal catch attempt");
563
+ },
564
+ delegateYield: function delegateYield(e, r, n) {
565
+ return this.delegate = {
566
+ iterator: values(e),
567
+ resultName: r,
568
+ nextLoc: n
569
+ }, "next" === this.method && (this.arg = t), y;
570
+ }
571
+ }, e;
572
+ }
573
+ module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports;
574
+ } (regeneratorRuntime$1));
575
+
576
+ var regeneratorRuntimeExports = regeneratorRuntime$1.exports;
577
+
578
+ // TODO(Babel 8): Remove this file.
579
+
580
+ var runtime = regeneratorRuntimeExports();
581
+ var regenerator = runtime;
582
+
583
+ // Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736=
584
+ try {
585
+ regeneratorRuntime = runtime;
586
+ } catch (accidentalStrictMode) {
587
+ if (typeof globalThis === "object") {
588
+ globalThis.regeneratorRuntime = runtime;
589
+ } else {
590
+ Function("r", "regeneratorRuntime = r")(runtime);
591
+ }
592
+ }
593
+
594
+ var _regeneratorRuntime = /*@__PURE__*/getDefaultExportFromCjs(regenerator);
595
+
596
+ function _arrayWithHoles(arr) {
597
+ if (Array.isArray(arr)) return arr;
598
+ }
599
+
600
+ function _iterableToArrayLimit(r, l) {
601
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
602
+ if (null != t) {
603
+ var e,
604
+ n,
605
+ i,
606
+ u,
607
+ a = [],
608
+ f = !0,
609
+ o = !1;
610
+ try {
611
+ if (i = (t = t.call(r)).next, 0 === l) {
612
+ if (Object(t) !== t) return;
613
+ f = !1;
614
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
615
+ } catch (r) {
616
+ o = !0, n = r;
617
+ } finally {
618
+ try {
619
+ if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
620
+ } finally {
621
+ if (o) throw n;
622
+ }
623
+ }
624
+ return a;
625
+ }
626
+ }
627
+
628
+ function _nonIterableRest() {
629
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
630
+ }
631
+
632
+ function _slicedToArray(arr, i) {
633
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
634
+ }
635
+
636
+ var DELIVERY_TAB = {
637
+ response: "response",
638
+ request: "request"
639
+ };
640
+
641
+ var Snippet = function Snippet(_ref) {
642
+ var children = _ref.children,
643
+ _ref$dataCy = _ref.dataCy,
644
+ dataCy = _ref$dataCy === void 0 ? "" : _ref$dataCy;
645
+ return /*#__PURE__*/jsx("div", {
646
+ className: "neeto-ui-rounded neeto-ui-border-gray-300 neeto-ui-bg-gray-100 my-2 whitespace-pre-wrap break-all border p-4",
647
+ "data-cy": dataCy,
648
+ children: children
649
+ });
650
+ };
651
+
652
+ var TransactionDetails = function TransactionDetails(_ref) {
653
+ var delivery = _ref.delivery;
654
+ var _useState = useState(DELIVERY_TAB.request),
655
+ _useState2 = _slicedToArray(_useState, 2),
656
+ activeHeader = _useState2[0],
657
+ setActiveHeader = _useState2[1];
658
+ var _useTranslation = useTranslation(),
659
+ t = _useTranslation.t;
660
+ var status = delivery.status,
661
+ identifier = delivery.identifier,
662
+ responseStatusCode = delivery.responseStatusCode,
663
+ sid = delivery.sid;
664
+ var renderPayload = function renderPayload() {
665
+ try {
666
+ return JSON.stringify(JSON.parse(delivery.requestBody), null, 2);
667
+ } catch (_unused) {
668
+ return "";
669
+ }
670
+ };
671
+ return /*#__PURE__*/jsxs(Fragment, {
672
+ children: [/*#__PURE__*/jsxs("div", {
673
+ className: "neeto-ui-bg-white sticky top-0 mb-2 flex w-full flex-col",
674
+ children: [/*#__PURE__*/jsxs("div", {
675
+ className: "flex w-full flex-col space-y-2 pb-4",
676
+ children: [/*#__PURE__*/jsxs("span", {
677
+ className: "flex items-center space-x-1",
678
+ children: [t("neetoWebhooks.delivery.sid"), ":", /*#__PURE__*/jsx(Typography, {
679
+ className: "px-2 font-bold",
680
+ "data-cy": "delivery-sid",
681
+ style: "body2",
682
+ children: sid
683
+ })]
684
+ }), /*#__PURE__*/jsxs("span", {
685
+ className: "flex items-center space-x-1",
686
+ children: [t("neetoWebhooks.delivery.deliveryId"), ":", /*#__PURE__*/jsx(Typography, {
687
+ className: "px-2 font-bold",
688
+ "data-cy": "delivery-identifier",
689
+ style: "body2",
690
+ children: identifier
691
+ })]
692
+ }), /*#__PURE__*/jsxs("span", {
693
+ className: "flex items-center",
694
+ children: [t("neetoWebhooks.common.responseStatus"), ":", /*#__PURE__*/jsx(Typography, {
695
+ className: "px-2 font-bold",
696
+ "data-cy": "delivery-response-code",
697
+ style: "body2",
698
+ children: responseStatusCode
699
+ }), /*#__PURE__*/jsx(Tag, {
700
+ style: status === "success" ? "success" : "warning",
701
+ children: status
702
+ })]
703
+ })]
704
+ }), /*#__PURE__*/jsxs(Tab, {
705
+ children: [/*#__PURE__*/jsx(Tab.Item, {
706
+ active: activeHeader === DELIVERY_TAB.request,
707
+ onClick: function onClick() {
708
+ return setActiveHeader(DELIVERY_TAB.request);
709
+ },
710
+ children: t("neetoWebhooks.delivery.request")
711
+ }), /*#__PURE__*/jsx(Tab.Item, {
712
+ active: activeHeader === DELIVERY_TAB.response,
713
+ onClick: function onClick() {
714
+ return setActiveHeader(DELIVERY_TAB.response);
715
+ },
716
+ children: t("neetoWebhooks.delivery.response")
717
+ })]
718
+ })]
719
+ }), /*#__PURE__*/jsx("div", {
720
+ className: "mt-2 w-full",
721
+ children: activeHeader === DELIVERY_TAB.request ? /*#__PURE__*/jsxs("div", {
722
+ className: "space-y-4",
723
+ children: [/*#__PURE__*/jsxs("div", {
724
+ children: [/*#__PURE__*/jsx(Typography, {
725
+ style: "h5",
726
+ children: t("neetoWebhooks.delivery.header")
727
+ }), /*#__PURE__*/jsx(Snippet, {
728
+ dataCy: "delivery-request-header",
729
+ children: delivery.requestHeader
730
+ })]
731
+ }), /*#__PURE__*/jsxs("div", {
732
+ children: [/*#__PURE__*/jsx(Typography, {
733
+ style: "h5",
734
+ children: t("neetoWebhooks.delivery.payload")
735
+ }), /*#__PURE__*/jsx(Snippet, {
736
+ dataCy: "delivery-request-payload",
737
+ children: renderPayload()
738
+ })]
739
+ })]
740
+ }) : /*#__PURE__*/jsxs("div", {
741
+ className: "space-y-4",
742
+ children: [/*#__PURE__*/jsxs("div", {
743
+ children: [/*#__PURE__*/jsx(Typography, {
744
+ style: "h5",
745
+ children: t("neetoWebhooks.delivery.header")
746
+ }), /*#__PURE__*/jsx(Snippet, {
747
+ dataCy: "delivery-response-header",
748
+ children: delivery.responseHeader
749
+ })]
750
+ }), /*#__PURE__*/jsxs("div", {
751
+ children: [/*#__PURE__*/jsx(Typography, {
752
+ style: "h5",
753
+ children: t("neetoWebhooks.delivery.body")
754
+ }), /*#__PURE__*/jsx(Snippet, {
755
+ dataCy: "delivery-response-body",
756
+ children: delivery.responseBody
757
+ })]
758
+ })]
759
+ })
760
+ })]
761
+ });
762
+ };
763
+
764
+ var Details = function Details(_ref) {
765
+ var onClose = _ref.onClose,
766
+ deliveryId = _ref.deliveryId,
767
+ webhookSid = _ref.webhookSid;
768
+ var _useTranslation = useTranslation(),
769
+ t = _useTranslation.t;
770
+ var _useRedeliverWebhook = useRedeliverWebhook(deliveryId, webhookSid),
771
+ isRedelivering = _useRedeliverWebhook.isPending,
772
+ redeliverWebhook = _useRedeliverWebhook.mutateAsync;
773
+ var _useShowDelivery = useShowDelivery(deliveryId, webhookSid),
774
+ isLoading = _useShowDelivery.isPending,
775
+ _useShowDelivery$data = _useShowDelivery.data,
776
+ _useShowDelivery$data2 = _useShowDelivery$data === void 0 ? {} : _useShowDelivery$data,
777
+ delivery = _useShowDelivery$data2.delivery;
778
+ var handleRedeliverClick = /*#__PURE__*/function () {
779
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
780
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
781
+ while (1) switch (_context.prev = _context.next) {
782
+ case 0:
783
+ _context.next = 2;
784
+ return redeliverWebhook();
785
+ case 2:
786
+ case "end":
787
+ return _context.stop();
788
+ }
789
+ }, _callee);
790
+ }));
791
+ return function handleRedeliverClick() {
792
+ return _ref2.apply(this, arguments);
793
+ };
794
+ }();
795
+ return /*#__PURE__*/jsx(Pane, {
796
+ onClose: onClose,
797
+ isOpen: isPresent(deliveryId),
798
+ size: "large",
799
+ children: /*#__PURE__*/jsx(Fragment, {
800
+ children: isLoading ? /*#__PURE__*/jsx(PageLoader, {}) : /*#__PURE__*/jsxs(Fragment, {
801
+ children: [/*#__PURE__*/jsx(Pane.Header, {
802
+ children: /*#__PURE__*/jsxs(Fragment, {
803
+ children: [/*#__PURE__*/jsx(DateFormat.Date, {
804
+ date: delivery.createdAt,
805
+ tooltipProps: {
806
+ disabled: true
807
+ },
808
+ typographyProps: {
809
+ style: "h2",
810
+ weight: "semibold"
811
+ }
812
+ }), /*#__PURE__*/jsx("span", {
813
+ children: " \u2022 "
814
+ }), /*#__PURE__*/jsx(DateFormat.Time, {
815
+ date: delivery.createdAt,
816
+ tooltipProps: {
817
+ disabled: true
818
+ },
819
+ typographyProps: {
820
+ style: "h2",
821
+ weight: "normal"
822
+ }
823
+ })]
824
+ })
825
+ }), /*#__PURE__*/jsx(Pane.Body, {
826
+ children: isPresent(delivery) && /*#__PURE__*/jsx(TransactionDetails, {
827
+ delivery: delivery
828
+ })
829
+ }), /*#__PURE__*/jsxs(Pane.Footer, {
830
+ className: "gap-x-2",
831
+ children: [event && /*#__PURE__*/jsx(Button, {
832
+ disabled: isRedelivering,
833
+ label: t("neetoWebhooks.delivery.redeliver"),
834
+ loading: isRedelivering,
835
+ style: "primary",
836
+ onClick: handleRedeliverClick
837
+ }), /*#__PURE__*/jsx(Button, {
838
+ label: t("neetoWebhooks.buttons.cancel"),
839
+ style: "text",
840
+ onClick: onClose
841
+ })]
842
+ })]
843
+ })
844
+ })
845
+ });
846
+ };
847
+
848
+ var buildColumns$1 = function buildColumns(_ref) {
849
+ var deliveryDetailsPath = _ref.deliveryDetailsPath;
850
+ return [{
851
+ title: t$1("neetoWebhooks.delivery.deliveryId"),
852
+ key: "identifier",
853
+ dataIndex: "identifier",
854
+ width: 390,
855
+ render: function render(_, delivery) {
856
+ return /*#__PURE__*/jsxs("div", {
857
+ className: "flex items-center gap-x-3",
858
+ children: [/*#__PURE__*/jsx(Button, {
859
+ style: "link",
860
+ to: buildUrl(deliveryDetailsPath, {
861
+ deliveryId: delivery.sid
862
+ }),
863
+ weight: "semibold",
864
+ children: delivery.identifier
865
+ }), delivery.redelivery && /*#__PURE__*/jsx(Tag, {
866
+ style: "info",
867
+ children: t$1("neetoWebhooks.delivery.redelivery")
868
+ })]
869
+ });
870
+ }
871
+ }, {
872
+ title: t$1("neetoWebhooks.tableHeaders.createdAt"),
873
+ key: "createdAt",
874
+ dataIndex: "createdAt",
875
+ width: 280,
876
+ render: function render(createdAt) {
877
+ return /*#__PURE__*/jsx("div", {
878
+ className: "flex items-center justify-between space-x-1",
879
+ children: /*#__PURE__*/jsx(Typography, {
880
+ children: /*#__PURE__*/jsx(DateFormat.DateTime, {
881
+ date: createdAt
882
+ })
883
+ })
884
+ });
885
+ }
886
+ }, {
887
+ title: t$1("neetoWebhooks.common.responseStatus"),
888
+ key: "responseStatusCode",
889
+ width: 160,
890
+ render: function render(_ref2) {
891
+ var responseStatusCode = _ref2.responseStatusCode,
892
+ status = _ref2.status;
893
+ return /*#__PURE__*/jsxs("span", {
894
+ className: "flex items-center",
895
+ children: [/*#__PURE__*/jsx(Typography, {
896
+ className: "px-2",
897
+ style: "body2",
898
+ children: responseStatusCode
899
+ }), /*#__PURE__*/jsx(Tag, {
900
+ style: status === "success" ? "success" : "warning",
901
+ children: status
902
+ })]
903
+ });
904
+ }
905
+ }, {
906
+ title: t$1("neetoWebhooks.common.event", SINGULAR),
907
+ key: "event",
908
+ dataIndex: "event",
909
+ width: 270,
910
+ render: prop("label")
911
+ }];
912
+ };
913
+
914
+ var Deliveries = function Deliveries(_ref) {
915
+ var webhooksUrl = _ref.webhooksUrl,
916
+ hostBreadcrumbs = _ref.breadcrumbs,
917
+ helpLink = _ref.helpLink;
918
+ var _useRouteMatch = useRouteMatch(),
919
+ deliveriesUrl = _useRouteMatch.url;
920
+ var history = useHistory();
921
+ var _useTranslation = useTranslation(),
922
+ t = _useTranslation.t;
923
+ var _useParams = useParams(),
924
+ webhookId = _useParams.webhookId,
925
+ deliveryId = _useParams.deliveryId;
926
+ var _useQueryParams = useQueryParams(),
927
+ _useQueryParams$page = _useQueryParams.page,
928
+ page = _useQueryParams$page === void 0 ? DEFAULT_PAGE_INDEX : _useQueryParams$page;
929
+ var deliveryDetailsPath = getDeliveryDetailsPath(deliveriesUrl);
930
+ var _useFetchDeliveries = useFetchDeliveries(webhookId, {
931
+ page: page,
932
+ pageSize: DEFAULT_PAGE_SIZE
933
+ }),
934
+ isLoading = _useFetchDeliveries.isLoading,
935
+ isFetching = _useFetchDeliveries.isFetching,
936
+ _useFetchDeliveries$d = _useFetchDeliveries.data,
937
+ _useFetchDeliveries$d2 = _useFetchDeliveries$d === void 0 ? {} : _useFetchDeliveries$d,
938
+ endpoint = _useFetchDeliveries$d2.endpoint,
939
+ totalCount = _useFetchDeliveries$d2.totalCount,
940
+ _useFetchDeliveries$d3 = _useFetchDeliveries$d2.deliveries,
941
+ deliveries = _useFetchDeliveries$d3 === void 0 ? [] : _useFetchDeliveries$d3;
942
+ var breadcrumbsWithoutWebhooksTitle = removeBy({
943
+ text: t("neetoWebhooks.webhook.title")
944
+ }, hostBreadcrumbs);
945
+ var breadcrumbs = [].concat(_toConsumableArray(breadcrumbsWithoutWebhooksTitle), [{
946
+ link: webhooksUrl,
947
+ text: t("neetoWebhooks.webhook.title")
948
+ }, {
949
+ link: window.location.pathname,
950
+ text: endpoint
951
+ }]);
952
+ if (isLoading) return /*#__PURE__*/jsx(PageLoader, {});
953
+ return /*#__PURE__*/jsxs(Container, {
954
+ className: "w-full",
955
+ children: [/*#__PURE__*/jsx(Header$2, {
956
+ breadcrumbs: breadcrumbs,
957
+ title: /*#__PURE__*/jsxs("div", {
958
+ className: "flex items-center gap-x-2",
959
+ children: [t("neetoWebhooks.delivery.title"), /*#__PURE__*/jsx(HelpPopover, {
960
+ description: t("neetoWebhooks.delivery.helpDescription"),
961
+ helpLinkProps: {
962
+ href: helpLink
963
+ },
964
+ title: t("neetoWebhooks.delivery.title")
965
+ })]
966
+ })
967
+ }), isNotEmpty(deliveries) ? /*#__PURE__*/jsx(TableWrapper, {
968
+ hasPagination: totalCount > DEFAULT_PAGE_SIZE,
969
+ children: /*#__PURE__*/jsx(Table, {
970
+ totalCount: totalCount,
971
+ fixedHeight: true,
972
+ columnData: buildColumns$1({
973
+ deliveryDetailsPath: deliveryDetailsPath
974
+ }),
975
+ currentPageNumber: page,
976
+ defaultPageSize: DEFAULT_PAGE_SIZE,
977
+ loading: isFetching,
978
+ rowData: deliveries
979
+ })
980
+ }) : /*#__PURE__*/jsx("div", {
981
+ className: "flex h-full w-full items-center justify-center",
982
+ children: /*#__PURE__*/jsx(NoData, {
983
+ description: t("neetoWebhooks.delivery.empty.description"),
984
+ title: t("neetoWebhooks.delivery.empty.title")
985
+ })
986
+ }), /*#__PURE__*/jsx(Details, {
987
+ deliveryId: deliveryId,
988
+ webhookSid: webhookId,
989
+ onClose: function onClose() {
990
+ return history.goBack();
991
+ }
992
+ })]
993
+ });
994
+ };
995
+ var Deliveries$1 = withReactQuery(Deliveries);
996
+
997
+ var baseUrl$1 = "/webhooks/webhooks";
998
+ var fetch = function fetch(params) {
999
+ return axios.get(baseUrl$1, {
1000
+ params: params
1001
+ });
1002
+ };
1003
+ var create = function create(payload) {
1004
+ return axios.post(baseUrl$1, {
1005
+ webhook: payload
1006
+ });
1007
+ };
1008
+ var show = function show(id) {
1009
+ return axios.get("".concat(baseUrl$1, "/").concat(id));
1010
+ };
1011
+ var update = function update(id, payload) {
1012
+ return axios.put("".concat(baseUrl$1, "/").concat(id), {
1013
+ webhook: payload
1014
+ });
1015
+ };
1016
+ var destroy = function destroy(id) {
1017
+ return axios["delete"]("".concat(baseUrl$1, "/").concat(id));
1018
+ };
1019
+ var webhooksApi = {
1020
+ fetch: fetch,
1021
+ create: create,
1022
+ show: show,
1023
+ update: update,
1024
+ destroy: destroy
1025
+ };
1026
+
1027
+ var useFetchWebhooks = function useFetchWebhooks(params) {
1028
+ return useQuery({
1029
+ queryKey: [QUERY_KEYS.WEBHOOK_LIST, params],
1030
+ queryFn: function queryFn() {
1031
+ return webhooksApi.fetch(params);
1032
+ },
1033
+ staleTime: WEBHOOK_STALE_TIME
1034
+ });
1035
+ };
1036
+ var useCreateWebhook = function useCreateWebhook(options) {
1037
+ return useMutationWithInvalidation(webhooksApi.create, {
1038
+ keysToInvalidate: [[QUERY_KEYS.WEBHOOK_LIST]],
1039
+ onSuccess: function onSuccess() {
1040
+ var _options$onSuccess;
1041
+ options === null || options === void 0 || (_options$onSuccess = options.onSuccess) === null || _options$onSuccess === void 0 || _options$onSuccess.call(options);
1042
+ }
1043
+ });
1044
+ };
1045
+ var useShowWebhook = function useShowWebhook(id) {
1046
+ return useQuery({
1047
+ queryKey: [QUERY_KEYS.WEBHOOK_DETAILS, id],
1048
+ queryFn: function queryFn() {
1049
+ return webhooksApi.show(id);
1050
+ },
1051
+ enabled: !!id,
1052
+ staleTime: WEBHOOK_STALE_TIME
1053
+ });
1054
+ };
1055
+ var useUpdateWebhook = function useUpdateWebhook(id, options) {
1056
+ return useMutationWithInvalidation(function (_ref) {
1057
+ var id = _ref.id,
1058
+ payload = _ref.payload;
1059
+ return webhooksApi.update(id, payload);
1060
+ }, {
1061
+ keysToInvalidate: [[QUERY_KEYS.WEBHOOK_LIST], [QUERY_KEYS.WEBHOOK_DETAILS, id], [QUERY_KEYS.DELIVERY_LIST, id]],
1062
+ onSuccess: function onSuccess() {
1063
+ var _options$onSuccess2;
1064
+ options === null || options === void 0 || (_options$onSuccess2 = options.onSuccess) === null || _options$onSuccess2 === void 0 || _options$onSuccess2.call(options);
1065
+ }
1066
+ });
1067
+ };
1068
+ var useDestroyWebhook = function useDestroyWebhook(options) {
1069
+ return useMutationWithInvalidation(webhooksApi.destroy, {
1070
+ keysToInvalidate: [[QUERY_KEYS.WEBHOOK_LIST]],
1071
+ onSuccess: function onSuccess() {
1072
+ var _options$onSuccess3;
1073
+ options === null || options === void 0 || (_options$onSuccess3 = options.onSuccess) === null || _options$onSuccess3 === void 0 || _options$onSuccess3.call(options);
1074
+ }
1075
+ });
1076
+ };
1077
+
1078
+ var baseUrl = "/webhooks/events/all";
1079
+ var all = function all() {
1080
+ return axios.get(baseUrl);
1081
+ };
1082
+ var eventsApi = {
1083
+ all: all
1084
+ };
1085
+
1086
+ var useFetchEvents = function useFetchEvents() {
1087
+ return useQuery({
1088
+ queryKey: [QUERY_KEYS.EVENTS_LIST],
1089
+ queryFn: eventsApi.all,
1090
+ staleTime: WEBHOOK_STALE_TIME
1091
+ });
1092
+ };
1093
+
1094
+ // Unique ID creation requires a high quality random # generator. In the browser we therefore
1095
+ // require the crypto API and do not support built-in fallback to lower quality random number
1096
+ // generators (like Math.random()).
1097
+ let getRandomValues;
1098
+ const rnds8 = new Uint8Array(16);
1099
+ function rng() {
1100
+ // lazy load so that environments that need to polyfill have a chance to do so
1101
+ if (!getRandomValues) {
1102
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
1103
+ getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
1104
+
1105
+ if (!getRandomValues) {
1106
+ throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
1107
+ }
1108
+ }
1109
+
1110
+ return getRandomValues(rnds8);
1111
+ }
1112
+
1113
+ /**
1114
+ * Convert array of 16 byte values to UUID string format of the form:
1115
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
1116
+ */
1117
+
1118
+ const byteToHex = [];
1119
+
1120
+ for (let i = 0; i < 256; ++i) {
1121
+ byteToHex.push((i + 0x100).toString(16).slice(1));
1122
+ }
1123
+
1124
+ function unsafeStringify(arr, offset = 0) {
1125
+ // Note: Be careful editing this code! It's been tuned for performance
1126
+ // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
1127
+ return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
1128
+ }
1129
+
1130
+ const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
1131
+ var native = {
1132
+ randomUUID
1133
+ };
1134
+
1135
+ function v4(options, buf, offset) {
1136
+ if (native.randomUUID && !buf && !options) {
1137
+ return native.randomUUID();
1138
+ }
1139
+
1140
+ options = options || {};
1141
+ const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
1142
+
1143
+ rnds[6] = rnds[6] & 0x0f | 0x40;
1144
+ rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
1145
+
1146
+ if (buf) {
1147
+ offset = offset || 0;
1148
+
1149
+ for (let i = 0; i < 16; ++i) {
1150
+ buf[offset + i] = rnds[i];
1151
+ }
1152
+
1153
+ return buf;
1154
+ }
1155
+
1156
+ return unsafeStringify(rnds);
1157
+ }
1158
+
1159
+ var MENU_ITEMS = {
1160
+ EDIT: "edit",
1161
+ DELETE: "delete"
1162
+ };
1163
+
1164
+ function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1165
+ function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1166
+ var getMenuItems = function getMenuItems(_ref) {
1167
+ var onEdit = _ref.onEdit,
1168
+ onDelete = _ref.onDelete;
1169
+ return [{
1170
+ key: MENU_ITEMS.EDIT,
1171
+ label: t$1("neetoWebhooks.buttons.edit"),
1172
+ onClick: onEdit
1173
+ }, {
1174
+ key: MENU_ITEMS.DELETE,
1175
+ label: t$1("neetoWebhooks.buttons.delete"),
1176
+ onClick: onDelete
1177
+ }];
1178
+ };
1179
+ var getValidationSchema = function getValidationSchema(webhooks) {
1180
+ return yup.object().shape({
1181
+ endpoint: yup.string().trim().matches(/^(https?):\/\//i, t$1("neetoWebhooks.errors.webhook.invalidUrlProtocol")).url(t$1("neetoWebhooks.errors.webhook.invalidUrl")).required(t$1("neetoWebhooks.errors.webhook.required")).test("Is endpoint unique", t$1("neetoWebhooks.errors.webhook.urlNotUnique"), function (endpoint, ctx) {
1182
+ return !pluck("endpoint", removeById(ctx.parent.id, webhooks)).includes(endpoint === null || endpoint === void 0 ? void 0 : endpoint.trim());
1183
+ }),
1184
+ events: yup.array().min(1, t$1("neetoWebhooks.errors.webhook.events.required")),
1185
+ secret: yup.string().trim().nullable()
1186
+ });
1187
+ };
1188
+ var buildPayload = function buildPayload(_ref2) {
1189
+ var _initialValues$events;
1190
+ var isEditing = _ref2.isEditing,
1191
+ values = _ref2.values,
1192
+ initialValues = _ref2.initialValues;
1193
+ var events = values.events.map(function (_ref3) {
1194
+ var identifier = _ref3.identifier;
1195
+ return {
1196
+ identifier: identifier
1197
+ };
1198
+ });
1199
+ if (!isEditing) return _objectSpread$1(_objectSpread$1({}, values), {}, {
1200
+ eventsAttributes: events
1201
+ });
1202
+ var deletable = ((_initialValues$events = initialValues.events) !== null && _initialValues$events !== void 0 ? _initialValues$events : []).filter(function (_ref4) {
1203
+ var identifier = _ref4.identifier;
1204
+ return !findBy({
1205
+ identifier: identifier
1206
+ }, values.events);
1207
+ }).map(assoc("_destroy", true));
1208
+ var creatable = values.events.filter(function (_ref5) {
1209
+ var identifier = _ref5.identifier;
1210
+ return !findBy({
1211
+ identifier: identifier
1212
+ }, initialValues.events);
1213
+ });
1214
+ return _objectSpread$1(_objectSpread$1({}, values), {}, {
1215
+ eventsAttributes: [].concat(_toConsumableArray(creatable), _toConsumableArray(deletable))
1216
+ });
1217
+ };
1218
+ var buildColumns = function buildColumns(_ref6) {
1219
+ var handleDelete = _ref6.handleDelete,
1220
+ handleEdit = _ref6.handleEdit,
1221
+ deliveriesPath = _ref6.deliveriesPath;
1222
+ return [{
1223
+ title: t$1("neetoWebhooks.common.endpoint"),
1224
+ key: "endpoint",
1225
+ dataIndex: "endpoint",
1226
+ width: 830,
1227
+ render: function render(endpoint, webhook) {
1228
+ return /*#__PURE__*/jsxs("div", {
1229
+ className: "flex items-center justify-between space-x-3",
1230
+ children: [/*#__PURE__*/jsx(Button, {
1231
+ style: "link",
1232
+ to: buildUrl(deliveriesPath, {
1233
+ webhookId: webhook.sid
1234
+ }),
1235
+ children: endpoint
1236
+ }), /*#__PURE__*/jsx(MoreDropdown, {
1237
+ dropdownProps: {
1238
+ strategy: "fixed"
1239
+ },
1240
+ menuItems: getMenuItems({
1241
+ onEdit: function onEdit() {
1242
+ return handleEdit(webhook.id);
1243
+ },
1244
+ onDelete: function onDelete() {
1245
+ return handleDelete(webhook.id);
1246
+ }
1247
+ })
1248
+ })]
1249
+ });
1250
+ }
1251
+ }, {
1252
+ title: t$1("neetoWebhooks.webhook.active"),
1253
+ key: "isActive",
1254
+ dataIndex: "isActive",
1255
+ render: function render(isActive) {
1256
+ return isActive ? t$1("neetoWebhooks.webhook.activeStatuses.yes") : t$1("neetoWebhooks.webhook.activeStatuses.no");
1257
+ },
1258
+ width: 100
1259
+ }, {
1260
+ title: t$1("neetoWebhooks.common.event", PLURAL),
1261
+ dataIndex: "events",
1262
+ key: "events",
1263
+ render: function render(events) {
1264
+ return pluck("label", events).sort().join(", ");
1265
+ },
1266
+ width: 400
1267
+ }];
1268
+ };
1269
+ var generateRandomSecret = function generateRandomSecret() {
1270
+ return v4().replace(/-/g, "");
1271
+ };
1272
+
1273
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
1274
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1275
+ var AddWebhookPane = function AddWebhookPane(_ref) {
1276
+ var editingWebhookId = _ref.editingWebhookId,
1277
+ entityId = _ref.entityId,
1278
+ entityType = _ref.entityType,
1279
+ isOpen = _ref.isOpen,
1280
+ onClose = _ref.onClose,
1281
+ onCreate = _ref.onCreate,
1282
+ webhooks = _ref.webhooks,
1283
+ webhookHelpLink = _ref.webhookHelpLink,
1284
+ secretsHelpLink = _ref.secretsHelpLink;
1285
+ var _useTranslation = useTranslation(),
1286
+ t = _useTranslation.t;
1287
+ var _useState = useState(false),
1288
+ _useState2 = _slicedToArray(_useState, 2),
1289
+ isSecretInputFieldVisible = _useState2[0],
1290
+ setIsSecretInputFieldVisible = _useState2[1];
1291
+ var _useCreateWebhook = useCreateWebhook({
1292
+ onSuccess: function onSuccess() {
1293
+ onClose();
1294
+ onCreate === null || onCreate === void 0 || onCreate();
1295
+ }
1296
+ }),
1297
+ createWebhook = _useCreateWebhook.mutate;
1298
+ var _useShowWebhook = useShowWebhook(editingWebhookId),
1299
+ _useShowWebhook$data = _useShowWebhook.data,
1300
+ _useShowWebhook$data2 = _useShowWebhook$data === void 0 ? {} : _useShowWebhook$data,
1301
+ _useShowWebhook$data3 = _useShowWebhook$data2.webhook,
1302
+ webhook = _useShowWebhook$data3 === void 0 ? {} : _useShowWebhook$data3;
1303
+ var _useUpdateWebhook = useUpdateWebhook(editingWebhookId, {
1304
+ onSuccess: onClose
1305
+ }),
1306
+ updateWebhook = _useUpdateWebhook.mutate;
1307
+ var endpointRef = useRef();
1308
+ var _useFetchEvents = useFetchEvents(),
1309
+ events = _useFetchEvents.data,
1310
+ isLoading = _useFetchEvents.isLoading;
1311
+ var initialValues = editingWebhookId ? webhook : {
1312
+ endpoint: "",
1313
+ events: events,
1314
+ secret: "",
1315
+ isActive: true
1316
+ };
1317
+ var handleSubmit = function handleSubmit(values) {
1318
+ var payload = buildPayload({
1319
+ isEditing: editingWebhookId,
1320
+ values: values,
1321
+ initialValues: initialValues
1322
+ });
1323
+ editingWebhookId ? updateWebhook({
1324
+ id: editingWebhookId,
1325
+ payload: payload,
1326
+ entityId: entityId
1327
+ }) : createWebhook(_objectSpread(_objectSpread({}, payload), {}, {
1328
+ entityId: entityId,
1329
+ entityType: entityType
1330
+ }));
1331
+ };
1332
+ var handleClick = function handleClick(setFieldValue) {
1333
+ var randomWebhookSecret = generateRandomSecret();
1334
+ setFieldValue("secret", randomWebhookSecret);
1335
+ setIsSecretInputFieldVisible(true);
1336
+ };
1337
+ var handleRegenerate = function handleRegenerate(setFieldValue) {
1338
+ var randomWebhookSecret = generateRandomSecret();
1339
+ setFieldValue("secret", randomWebhookSecret);
1340
+ };
1341
+ var handleDelete = function handleDelete(setFieldValue) {
1342
+ setFieldValue("secret", null);
1343
+ setIsSecretInputFieldVisible(false);
1344
+ };
1345
+ useEffect(function () {
1346
+ if (webhook !== null && webhook !== void 0 && webhook.secret) {
1347
+ setIsSecretInputFieldVisible(true);
1348
+ }
1349
+ }, [webhook]);
1350
+ return /*#__PURE__*/jsxs(Pane, {
1351
+ isOpen: isOpen,
1352
+ onClose: onClose,
1353
+ initialFocusRef: endpointRef,
1354
+ children: [/*#__PURE__*/jsxs(Pane.Header, {
1355
+ className: "flex items-center gap-x-2",
1356
+ children: [/*#__PURE__*/jsx(Typography, {
1357
+ "data-cy": "add-new-webhook-pane-header",
1358
+ style: "h2",
1359
+ weight: "semibold",
1360
+ children: editingWebhookId ? t("neetoWebhooks.webhook.edit") : t("neetoWebhooks.webhook.add")
1361
+ }), /*#__PURE__*/jsx(HelpPopover, {
1362
+ description: t("neetoWebhooks.webhook.helpDescription"),
1363
+ helpLinkProps: {
1364
+ href: webhookHelpLink
1365
+ },
1366
+ title: t("neetoWebhooks.webhook.title")
1367
+ })]
1368
+ }), /*#__PURE__*/jsx(Form, {
1369
+ formikProps: {
1370
+ enableReinitialize: true,
1371
+ validationSchema: getValidationSchema(webhooks),
1372
+ initialValues: initialValues,
1373
+ onSubmit: function onSubmit(values) {
1374
+ return handleSubmit(getValidationSchema().cast(values));
1375
+ }
1376
+ },
1377
+ children: function children(_ref2) {
1378
+ var setFieldValue = _ref2.setFieldValue;
1379
+ return isLoading ? /*#__PURE__*/jsx("div", {
1380
+ className: "flex items-center justify-center",
1381
+ children: /*#__PURE__*/jsx(Spinner, {})
1382
+ }) : /*#__PURE__*/jsxs(Fragment, {
1383
+ children: [/*#__PURE__*/jsx(Pane.Body, {
1384
+ children: /*#__PURE__*/jsxs("div", {
1385
+ className: "w-full space-y-4",
1386
+ children: [/*#__PURE__*/jsx(Textarea, {
1387
+ required: true,
1388
+ "data-cy": "endpoint-input-field",
1389
+ label: t("neetoWebhooks.webhook.endpoint"),
1390
+ name: "endpoint",
1391
+ placeholder: t("neetoWebhooks.webhook.endpointPlaceholder"),
1392
+ ref: endpointRef,
1393
+ rows: 1
1394
+ }), !isLoading && /*#__PURE__*/jsx(Select, {
1395
+ isMulti: true,
1396
+ required: true,
1397
+ getOptionLabel: prop("label"),
1398
+ getOptionValue: prop("identifier"),
1399
+ label: t("neetoWebhooks.common.event", PLURAL),
1400
+ name: "events",
1401
+ options: events,
1402
+ placeholder: t("neetoWebhooks.webhook.eventPlaceholder")
1403
+ }), isSecretInputFieldVisible && /*#__PURE__*/jsxs("div", {
1404
+ className: "flex items-center justify-between space-x-3",
1405
+ children: [/*#__PURE__*/jsx(Input, {
1406
+ "data-cy": "secret-key-input-field",
1407
+ name: "secret",
1408
+ label: /*#__PURE__*/jsxs("span", {
1409
+ className: "flex items-center gap-x-2",
1410
+ children: [t("neetoWebhooks.webhook.secret"), /*#__PURE__*/jsx(HelpPopover, {
1411
+ helpLinkProps: {
1412
+ href: secretsHelpLink
1413
+ },
1414
+ description: t("neetoWebhooks.webhook.secretkeyHelpDescription"),
1415
+ title: t("neetoWebhooks.webhook.secretkeyHelpTitle")
1416
+ })]
1417
+ }),
1418
+ placeholder: t("neetoWebhooks.webhook.secretPlaceholder")
1419
+ }), /*#__PURE__*/jsx("div", {
1420
+ className: "mt-6",
1421
+ children: /*#__PURE__*/jsx(MoreDropdown, {
1422
+ menuItems: [{
1423
+ key: "regenerate-secret",
1424
+ label: t("neetoWebhooks.buttons.regenerate"),
1425
+ "data-cy": "regenerate-secret",
1426
+ onClick: function onClick() {
1427
+ return handleRegenerate(setFieldValue);
1428
+ }
1429
+ }, {
1430
+ key: "delete-secret",
1431
+ label: t("neetoWebhooks.buttons.delete"),
1432
+ "data-cy": "delete-secret",
1433
+ onClick: function onClick() {
1434
+ return handleDelete(setFieldValue);
1435
+ }
1436
+ }]
1437
+ })
1438
+ })]
1439
+ }), /*#__PURE__*/jsx(Switch, {
1440
+ label: t("neetoWebhooks.webhook.active"),
1441
+ name: "isActive"
1442
+ }), !isSecretInputFieldVisible && /*#__PURE__*/jsx(Button, {
1443
+ "data-cy": "add-secret-key",
1444
+ icon: Plus,
1445
+ label: t("neetoWebhooks.buttons.addSecretKey"),
1446
+ style: "text",
1447
+ onClick: function onClick() {
1448
+ return handleClick(setFieldValue);
1449
+ }
1450
+ })]
1451
+ })
1452
+ }), /*#__PURE__*/jsx(Pane.Footer, {
1453
+ children: /*#__PURE__*/jsx(ActionBlock, {
1454
+ cancelButtonProps: {
1455
+ onClick: onClose
1456
+ }
1457
+ })
1458
+ })]
1459
+ });
1460
+ }
1461
+ })]
1462
+ });
1463
+ };
1464
+
1465
+ var Header = withT(function (_ref) {
1466
+ var t = _ref.t,
1467
+ breadcrumbs = _ref.breadcrumbs,
1468
+ title = _ref.title,
1469
+ setIsAddWebhookPaneOpen = _ref.setIsAddWebhookPaneOpen,
1470
+ headerSize = _ref.headerSize,
1471
+ webhookHelpLink = _ref.webhookHelpLink;
1472
+ return /*#__PURE__*/jsxs(Fragment, {
1473
+ children: [/*#__PURE__*/jsx(Header$2, {
1474
+ breadcrumbs: breadcrumbs,
1475
+ size: headerSize,
1476
+ actionBlock: /*#__PURE__*/jsx(Button, {
1477
+ "data-cy": "add-new-webhook-button",
1478
+ label: t("neetoWebhooks.webhook.add"),
1479
+ onClick: function onClick() {
1480
+ return setIsAddWebhookPaneOpen(true);
1481
+ }
1482
+ }),
1483
+ title: title || /*#__PURE__*/jsxs("div", {
1484
+ className: "flex items-center gap-x-2",
1485
+ children: [t("neetoWebhooks.webhook.title"), /*#__PURE__*/jsx(HelpPopover, {
1486
+ description: t("neetoWebhooks.webhook.helpDescription"),
1487
+ helpLinkProps: {
1488
+ href: webhookHelpLink
1489
+ },
1490
+ title: t("neetoWebhooks.webhook.title")
1491
+ })]
1492
+ })
1493
+ }), /*#__PURE__*/jsx(Typography, {
1494
+ className: "mb-3",
1495
+ "data-cy": "webhook-description-header",
1496
+ style: "h5",
1497
+ weight: "normal",
1498
+ children: t("neetoWebhooks.webhook.description")
1499
+ })]
1500
+ });
1501
+ });
1502
+ var Header$1 = /*#__PURE__*/React.memo(Header);
1503
+
1504
+ var Webhooks = function Webhooks(_ref) {
1505
+ var deliveriesPath = _ref.deliveriesPath,
1506
+ entityType = _ref.entityType,
1507
+ breadcrumbs = _ref.breadcrumbs,
1508
+ title = _ref.title,
1509
+ entityId = _ref.entityId,
1510
+ onCreate = _ref.onCreate,
1511
+ onDelete = _ref.onDelete,
1512
+ headerSize = _ref.headerSize,
1513
+ _ref$containerClassNa = _ref.containerClassName,
1514
+ containerClassName = _ref$containerClassNa === void 0 ? "" : _ref$containerClassNa,
1515
+ webhookHelpLink = _ref.webhookHelpLink,
1516
+ secretsHelpLink = _ref.secretsHelpLink;
1517
+ var _useState = useState(null),
1518
+ _useState2 = _slicedToArray(_useState, 2),
1519
+ editingWebhookId = _useState2[0],
1520
+ setEditingWebhookId = _useState2[1];
1521
+ var _useState3 = useState(null),
1522
+ _useState4 = _slicedToArray(_useState3, 2),
1523
+ deletingWebhookId = _useState4[0],
1524
+ setDeletingWebhookId = _useState4[1];
1525
+ var _useState5 = useState(false),
1526
+ _useState6 = _slicedToArray(_useState5, 2),
1527
+ isAddWebhookPaneOpen = _useState6[0],
1528
+ setIsAddWebhookPaneOpen = _useState6[1];
1529
+ var _useState7 = useState(false),
1530
+ _useState8 = _slicedToArray(_useState7, 2),
1531
+ isDeleteAlertOpen = _useState8[0],
1532
+ setIsDeleteAlertOpen = _useState8[1];
1533
+ var _useTranslation = useTranslation(),
1534
+ t = _useTranslation.t;
1535
+ var _useQueryParams = useQueryParams(),
1536
+ _useQueryParams$page = _useQueryParams.page,
1537
+ page = _useQueryParams$page === void 0 ? DEFAULT_PAGE_INDEX : _useQueryParams$page;
1538
+ var _useFetchWebhooks = useFetchWebhooks({
1539
+ entityId: entityId,
1540
+ page: page,
1541
+ pageSize: DEFAULT_PAGE_SIZE
1542
+ }),
1543
+ isLoading = _useFetchWebhooks.isLoading,
1544
+ isFetching = _useFetchWebhooks.isFetching,
1545
+ _useFetchWebhooks$dat = _useFetchWebhooks.data,
1546
+ _useFetchWebhooks$dat2 = _useFetchWebhooks$dat === void 0 ? {} : _useFetchWebhooks$dat,
1547
+ _useFetchWebhooks$dat3 = _useFetchWebhooks$dat2.webhooks,
1548
+ webhooks = _useFetchWebhooks$dat3 === void 0 ? [] : _useFetchWebhooks$dat3,
1549
+ _useFetchWebhooks$dat4 = _useFetchWebhooks$dat2.totalCount,
1550
+ totalCount = _useFetchWebhooks$dat4 === void 0 ? 0 : _useFetchWebhooks$dat4;
1551
+ var _useDestroyWebhook = useDestroyWebhook({
1552
+ onSuccess: function onSuccess() {
1553
+ setIsDeleteAlertOpen(false);
1554
+ onDelete === null || onDelete === void 0 || onDelete();
1555
+ }
1556
+ }),
1557
+ isDeleting = _useDestroyWebhook.isPending,
1558
+ destroyWebhook = _useDestroyWebhook.mutate;
1559
+ var handlePaneClose = function handlePaneClose() {
1560
+ setEditingWebhookId(null);
1561
+ setIsAddWebhookPaneOpen(false);
1562
+ };
1563
+ var handleEdit = useCallback(function (id) {
1564
+ setEditingWebhookId(id);
1565
+ setIsAddWebhookPaneOpen(true);
1566
+ }, []);
1567
+ var handleDelete = useCallback(function (id) {
1568
+ setDeletingWebhookId(id);
1569
+ setIsDeleteAlertOpen(true);
1570
+ }, []);
1571
+ if (isLoading) {
1572
+ return /*#__PURE__*/jsx(PageLoader, {});
1573
+ }
1574
+ return /*#__PURE__*/jsxs(Container, {
1575
+ className: containerClassName,
1576
+ children: [/*#__PURE__*/jsx(Header$1, {
1577
+ breadcrumbs: breadcrumbs,
1578
+ headerSize: headerSize,
1579
+ setIsAddWebhookPaneOpen: setIsAddWebhookPaneOpen,
1580
+ title: title,
1581
+ webhookHelpLink: webhookHelpLink
1582
+ }), isNotEmpty(webhooks) ? /*#__PURE__*/jsx(TableWrapper, {
1583
+ hasPagination: totalCount > DEFAULT_PAGE_SIZE,
1584
+ children: /*#__PURE__*/jsx(Table, {
1585
+ totalCount: totalCount,
1586
+ fixedHeight: true,
1587
+ currentPageNumber: page,
1588
+ defaultPageSize: DEFAULT_PAGE_SIZE,
1589
+ loading: isFetching,
1590
+ rowData: webhooks,
1591
+ columnData: buildColumns({
1592
+ handleDelete: handleDelete,
1593
+ handleEdit: handleEdit,
1594
+ deliveriesPath: deliveriesPath
1595
+ })
1596
+ })
1597
+ }) : /*#__PURE__*/jsx("div", {
1598
+ className: "flex h-full w-full items-center justify-center",
1599
+ children: /*#__PURE__*/jsx(NoData, {
1600
+ title: t("neetoWebhooks.webhook.empty"),
1601
+ helpText: /*#__PURE__*/jsx(Button, {
1602
+ href: webhookHelpLink,
1603
+ label: t("neetoWebhooks.webhook.emptyHelpText"),
1604
+ rel: "noreferrer",
1605
+ style: "link",
1606
+ target: "_blank"
1607
+ }),
1608
+ primaryButtonProps: {
1609
+ label: t("neetoWebhooks.webhook.add"),
1610
+ onClick: function onClick() {
1611
+ return setIsAddWebhookPaneOpen(true);
1612
+ }
1613
+ }
1614
+ })
1615
+ }), /*#__PURE__*/jsx(AddWebhookPane, {
1616
+ editingWebhookId: editingWebhookId,
1617
+ entityId: entityId,
1618
+ entityType: entityType,
1619
+ onCreate: onCreate,
1620
+ secretsHelpLink: secretsHelpLink,
1621
+ webhookHelpLink: webhookHelpLink,
1622
+ webhooks: webhooks,
1623
+ isOpen: isAddWebhookPaneOpen,
1624
+ onClose: handlePaneClose
1625
+ }), /*#__PURE__*/jsx(Alert, {
1626
+ isOpen: isDeleteAlertOpen,
1627
+ isSubmitting: isDeleting,
1628
+ submitButtonLabel: t("neetoWebhooks.buttons.delete"),
1629
+ message: t("neetoWebhooks.alert.delete.message", {
1630
+ entity: t("neetoWebhooks.entity.webhook")
1631
+ }),
1632
+ title: t("neetoWebhooks.alert.delete.title", {
1633
+ entity: t("neetoWebhooks.entity.webhook")
1634
+ }),
1635
+ onClose: function onClose() {
1636
+ return setIsDeleteAlertOpen(false);
1637
+ },
1638
+ onSubmit: function onSubmit() {
1639
+ return destroyWebhook(deletingWebhookId, {
1640
+ entityId: entityId
1641
+ });
1642
+ }
1643
+ })]
1644
+ });
1645
+ };
1646
+ var Webhooks$1 = withReactQuery(Webhooks);
1647
+
1648
+ var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
1649
+
1650
+ var css = ".neeto-molecules-header .neeto-molecules-header__breadcrumbs-wrap{flex-wrap:wrap}\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImFwcC9qYXZhc2NyaXB0L3NyYy9zdHlsZXNoZWV0cy9tYWluLnNjc3MiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0Usa0VBQ0UsY0FBSiIsInNvdXJjZXNDb250ZW50IjpbIi5uZWV0by1tb2xlY3VsZXMtaGVhZGVyIHtcbiAgLm5lZXRvLW1vbGVjdWxlcy1oZWFkZXJfX2JyZWFkY3J1bWJzLXdyYXAge1xuICAgIGZsZXgtd3JhcDogd3JhcDtcbiAgfVxufVxuIl19 */";
1651
+ n(css,{});
1652
+
1653
+ var NeetoWebhooks = function NeetoWebhooks(_ref) {
1654
+ var entityType = _ref.entityType,
1655
+ entityId = _ref.entityId,
1656
+ _ref$breadcrumbs = _ref.breadcrumbs,
1657
+ breadcrumbs = _ref$breadcrumbs === void 0 ? [] : _ref$breadcrumbs,
1658
+ title = _ref.title,
1659
+ onCreate = _ref.onCreate,
1660
+ onDelete = _ref.onDelete,
1661
+ headerSize = _ref.headerSize,
1662
+ _ref$helpLinkUrls = _ref.helpLinkUrls,
1663
+ helpLinkUrls = _ref$helpLinkUrls === void 0 ? {} : _ref$helpLinkUrls,
1664
+ containerClassName = _ref.containerClassName;
1665
+ var _useRouteMatch = useRouteMatch(),
1666
+ webhooksPath = _useRouteMatch.path,
1667
+ webhooksUrl = _useRouteMatch.url;
1668
+ var deliveriesPath = getDeliveriesPath(webhooksUrl);
1669
+ var deliveryDetailsPath = getDeliveryDetailsPath(deliveriesPath);
1670
+ var helpLinks = mergeRight(HELP_LINK_URLS, helpLinkUrls);
1671
+ return /*#__PURE__*/jsxs(Switch$1, {
1672
+ children: [/*#__PURE__*/jsx(Route, {
1673
+ exact: true,
1674
+ path: webhooksPath,
1675
+ component: function component() {
1676
+ return /*#__PURE__*/jsx(Webhooks$1, {
1677
+ breadcrumbs: breadcrumbs,
1678
+ containerClassName: containerClassName,
1679
+ deliveriesPath: deliveriesPath,
1680
+ entityId: entityId,
1681
+ entityType: entityType,
1682
+ headerSize: headerSize,
1683
+ onCreate: onCreate,
1684
+ onDelete: onDelete,
1685
+ title: title,
1686
+ secretsHelpLink: helpLinks.secrets,
1687
+ webhookHelpLink: helpLinks.webhook
1688
+ });
1689
+ }
1690
+ }), /*#__PURE__*/jsx(Route, {
1691
+ exact: true,
1692
+ path: deliveryDetailsPath,
1693
+ render: function render() {
1694
+ return /*#__PURE__*/jsx(Deliveries$1, {
1695
+ breadcrumbs: breadcrumbs,
1696
+ webhooksUrl: webhooksUrl,
1697
+ helpLink: helpLinks.deliveries
1698
+ });
1699
+ }
1700
+ }), /*#__PURE__*/jsx(Route, {
1701
+ path: deliveriesPath,
1702
+ render: function render() {
1703
+ return /*#__PURE__*/jsx(Deliveries$1, {
1704
+ breadcrumbs: breadcrumbs,
1705
+ webhooksUrl: webhooksUrl,
1706
+ helpLink: helpLinks.deliveries
1707
+ });
1708
+ }
1709
+ })]
1710
+ });
1711
+ };
1712
+
1713
+ export { NeetoWebhooks as default };
1714
+ //# sourceMappingURL=NeetoWebhooks.js.map