@bigbinary/neeto-api-keys-frontend 2.2.8 → 2.3.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.
package/README.md CHANGED
@@ -128,6 +128,7 @@ for easily finding specific API keys.
128
128
  - `headerProps`: Props for configuring the header section of the component.
129
129
  - `titleHelpPopoverProps`: Props for configuring the help popover in the title
130
130
  section.
131
+ - `zapierIntegrableType` : If the host app has Zapier integration, the table will display Zapier keys only if the integrable type is "Organization." This prop **is required** if the integrable type is not "Organization" and is scoped to another entity.
131
132
 
132
133
  ##### Usage
133
134
 
@@ -3,7 +3,10 @@
3
3
  "common": {
4
4
  "apiKey_one": "API key",
5
5
  "apiKey_other": "API keys",
6
- "never": "Never"
6
+ "never": "Never",
7
+ "general": "General",
8
+ "zapier": "Zapier",
9
+ "type": "Type"
7
10
  },
8
11
  "headers": {
9
12
  "createApiKey": "Add new API key",
@@ -18,7 +21,8 @@
18
21
  "deleteApiKey": "Delete API key?"
19
22
  },
20
23
  "descriptions": {
21
- "deleteApiKey": "You are permanently deleting the API key named <strong>{{name}}</strong>. This cannot be undone."
24
+ "deleteApiKey": "You are permanently deleting the API key named <strong>{{name}}</strong>. This cannot be undone.",
25
+ "deleteZapierApiKey": "You are permanently deleting the API Key <strong>{{name}}</strong>. All associated Zaps with this API Key will be turned off. This can't be undone."
22
26
  }
23
27
  },
24
28
  "buttons": {
@@ -48,7 +52,8 @@
48
52
  "token": "API key",
49
53
  "expiresAt": "Expires at",
50
54
  "createdAt": "Created at",
51
- "status": "Status"
55
+ "status": "Status",
56
+ "type": "Type"
52
57
  }
53
58
  },
54
59
  "fields": {
package/dist/ApiKeys.js CHANGED
@@ -2,7 +2,7 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
3
  import { useState, useEffect, useRef } from 'react';
4
4
  import { t } from 'i18next';
5
- import { isNotEmpty, isPresent, isNotPresent } from '@bigbinary/neeto-cist';
5
+ import { isNotEmpty, isPresent, humanize, isNotPresent } from '@bigbinary/neeto-cist';
6
6
  import { DEFAULT_PAGE_INDEX, DEFAULT_PAGE_SIZE, PLURAL } from '@bigbinary/neeto-commons-frontend/constants';
7
7
  import { useMutationWithInvalidation, withT, withTitle, useQueryParams, useDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
8
8
  import Header from '@bigbinary/neeto-molecules/Header';
@@ -15,11 +15,14 @@ import { getQueryParams, buildUrl, dateFormat, dayjs as dayjs$1 } from '@bigbina
15
15
  import { globalProps as globalProps$1 } from '@bigbinary/neeto-commons-frontend/initializers';
16
16
  import { useQuery } from '@tanstack/react-query';
17
17
  import axios from 'axios';
18
+ import dayjs from 'dayjs';
19
+ import * as yup from 'yup';
18
20
  import HelpPopover from '@bigbinary/neeto-molecules/HelpPopover';
19
21
  import Pane from '@bigbinary/neetoui/Pane';
20
22
  import Typography from '@bigbinary/neetoui/Typography';
21
23
  import NeetoUIForm from '@bigbinary/neetoui/formik/Form';
22
24
  import Input from '@bigbinary/neetoui/formik/Input';
25
+ import Radio from '@bigbinary/neetoui/formik/Radio';
23
26
  import Checkbox from '@bigbinary/neetoui/formik/Checkbox';
24
27
  import ActionBlock from '@bigbinary/neetoui/formik/ActionBlock';
25
28
  import { Field } from 'formik';
@@ -27,8 +30,6 @@ import NeetoUIDatePicker from '@bigbinary/neetoui/DatePicker';
27
30
  import CopyToClipboardButton from '@bigbinary/neeto-molecules/CopyToClipboardButton';
28
31
  import MoreDropdown from '@bigbinary/neeto-molecules/MoreDropdown';
29
32
  import Tag from '@bigbinary/neetoui/Tag';
30
- import dayjs from 'dayjs';
31
- import * as yup from 'yup';
32
33
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
33
34
  import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
34
35
  import TableWrapper from '@bigbinary/neeto-molecules/TableWrapper';
@@ -107,8 +108,12 @@ var update = function update(_ref) {
107
108
  apiKey: payload
108
109
  });
109
110
  };
110
- var destroy = function destroy(id) {
111
- return axios["delete"]("".concat(API_KEYS_BASE_URL, "/").concat(id));
111
+ var destroy = function destroy(_ref2) {
112
+ var id = _ref2.id,
113
+ params = _ref2.params;
114
+ return axios["delete"]("".concat(API_KEYS_BASE_URL, "/").concat(id), {
115
+ params: params
116
+ });
112
117
  };
113
118
  var apiKeysApi = {
114
119
  fetch: fetch,
@@ -160,10 +165,15 @@ var useDeleteApiKey = function useDeleteApiKey(onSuccess) {
160
165
  });
161
166
  };
162
167
 
168
+ var API_KEY_TYPES = {
169
+ GENERAL: "general",
170
+ ZAPIER: "zapier"
171
+ };
163
172
  var INITIAL_VALUES = {
164
173
  expiresAt: null,
165
174
  label: "",
166
- hasNoExpiry: true
175
+ hasNoExpiry: true,
176
+ type: API_KEY_TYPES.GENERAL
167
177
  };
168
178
  var NEXT_DAY = dayjs().add(1, "day").startOf("day");
169
179
  var VALIDATION_SCHEMA = yup.object({
@@ -194,10 +204,12 @@ var formatExpiry = function formatExpiry(date) {
194
204
  };
195
205
  var getMenuItems = function getMenuItems(_ref) {
196
206
  var onEdit = _ref.onEdit,
197
- onDelete = _ref.onDelete;
207
+ onDelete = _ref.onDelete,
208
+ isEditVisible = _ref.isEditVisible;
198
209
  return [{
199
210
  key: MENU_ITEMS.EDIT,
200
211
  label: t("neetoApiKeys.buttons.edit"),
212
+ isVisible: isEditVisible,
201
213
  "data-cy": "api-key-edit-button",
202
214
  onClick: onEdit
203
215
  }, {
@@ -209,16 +221,18 @@ var getMenuItems = function getMenuItems(_ref) {
209
221
  };
210
222
  var buildColumnData = function buildColumnData(_ref2) {
211
223
  var handleDelete = _ref2.handleDelete,
212
- handleEdit = _ref2.handleEdit;
213
- return [{
224
+ handleEdit = _ref2.handleEdit,
225
+ isZapierAvailable = _ref2.isZapierAvailable;
226
+ var columns = [{
214
227
  title: t("neetoApiKeys.table.headers.label"),
215
228
  key: "label",
216
229
  dataIndex: "label",
217
- width: 400,
230
+ width: 200,
218
231
  render: function render(label, apiKey) {
219
232
  return /*#__PURE__*/jsxs("div", {
220
233
  className: "flex items-center justify-between space-x-3",
221
234
  children: [/*#__PURE__*/jsx(Typography, {
235
+ "data-cy": "api-keys-label-field",
222
236
  style: "body2",
223
237
  children: label
224
238
  }), /*#__PURE__*/jsx(MoreDropdown, {
@@ -231,7 +245,8 @@ var buildColumnData = function buildColumnData(_ref2) {
231
245
  },
232
246
  onDelete: function onDelete() {
233
247
  return handleDelete(apiKey);
234
- }
248
+ },
249
+ isEditVisible: apiKey.type === API_KEY_TYPES.GENERAL
235
250
  })
236
251
  })]
237
252
  });
@@ -240,11 +255,12 @@ var buildColumnData = function buildColumnData(_ref2) {
240
255
  title: t("neetoApiKeys.table.headers.token"),
241
256
  key: "token",
242
257
  dataIndex: "token",
243
- width: 400,
258
+ width: 300,
244
259
  render: function render(token) {
245
260
  return /*#__PURE__*/jsxs("div", {
246
261
  className: "flex items-center justify-between gap-x-3",
247
262
  children: [/*#__PURE__*/jsx(Typography, {
263
+ "data-cy": "api-keys-token-field",
248
264
  style: "body2",
249
265
  children: partlyHideToken(token)
250
266
  }), /*#__PURE__*/jsx(CopyToClipboardButton, {
@@ -271,11 +287,14 @@ var buildColumnData = function buildColumnData(_ref2) {
271
287
  title: t("neetoApiKeys.table.headers.expiresAt"),
272
288
  key: "expiresAt",
273
289
  dataIndex: "expiresAt",
274
- width: 200,
290
+ width: 150,
275
291
  render: function render(expiresAt) {
276
- return isPresent(expiresAt) ? formatExpiry(expiresAt) : /*#__PURE__*/jsx(Typography, {
277
- style: "body2",
278
- children: t("neetoApiKeys.common.never")
292
+ return /*#__PURE__*/jsx("span", {
293
+ "data-cy": "api-keys-expires-at-field",
294
+ children: isPresent(expiresAt) ? formatExpiry(expiresAt) : /*#__PURE__*/jsx(Typography, {
295
+ style: "body2",
296
+ children: t("neetoApiKeys.common.never")
297
+ })
279
298
  });
280
299
  }
281
300
  }, {
@@ -284,12 +303,30 @@ var buildColumnData = function buildColumnData(_ref2) {
284
303
  dataIndex: "createdAt",
285
304
  width: 200,
286
305
  render: function render(createdAt) {
287
- return isPresent(createdAt) ? dateFormat.dateTime(createdAt) : /*#__PURE__*/jsx(Typography, {
288
- style: "body2",
289
- children: t("neetoApiKeys.common.never")
306
+ return /*#__PURE__*/jsx("span", {
307
+ "data-cy": "api-keys-created-at-field",
308
+ children: isPresent(createdAt) ? dateFormat.dateTime(createdAt) : /*#__PURE__*/jsx(Typography, {
309
+ style: "body2",
310
+ children: t("neetoApiKeys.common.never")
311
+ })
290
312
  });
291
313
  }
292
314
  }];
315
+ if (isZapierAvailable) {
316
+ columns.splice(2, 0, {
317
+ title: t("neetoApiKeys.table.headers.type"),
318
+ key: "type",
319
+ dataIndex: "type",
320
+ width: 144,
321
+ render: function render(type) {
322
+ return /*#__PURE__*/jsx(Typography, {
323
+ style: "body2",
324
+ children: humanize(type)
325
+ });
326
+ }
327
+ });
328
+ }
329
+ return columns;
293
330
  };
294
331
  var getStartOfTime = function getStartOfTime(time, unit) {
295
332
  return dayjs$1(time).startOf(unit);
@@ -339,7 +376,11 @@ var Form = withT(function (_ref) {
339
376
  isSubmitting = _ref.isSubmitting,
340
377
  onClose = _ref.onClose,
341
378
  onSubmit = _ref.onSubmit,
342
- initialFocusRef = _ref.initialFocusRef;
379
+ initialFocusRef = _ref.initialFocusRef,
380
+ _ref$isEdit = _ref.isEdit,
381
+ isEdit = _ref$isEdit === void 0 ? false : _ref$isEdit,
382
+ _ref$isZapierAvailabl = _ref.isZapierAvailable,
383
+ isZapierAvailable = _ref$isZapierAvailabl === void 0 ? false : _ref$isZapierAvailabl;
343
384
  return /*#__PURE__*/jsx(NeetoUIForm, {
344
385
  formikProps: {
345
386
  validationSchema: VALIDATION_SCHEMA,
@@ -351,7 +392,8 @@ var Form = withT(function (_ref) {
351
392
  _ref2$values = _ref2.values,
352
393
  _ref2$values2 = _ref2$values === void 0 ? {} : _ref2$values,
353
394
  hasNoExpiry = _ref2$values2.hasNoExpiry,
354
- expiresAt = _ref2$values2.expiresAt;
395
+ expiresAt = _ref2$values2.expiresAt,
396
+ type = _ref2$values2.type;
355
397
  return /*#__PURE__*/jsxs(Fragment, {
356
398
  children: [/*#__PURE__*/jsx(Pane.Body, {
357
399
  children: /*#__PURE__*/jsxs("div", {
@@ -363,23 +405,37 @@ var Form = withT(function (_ref) {
363
405
  placeholder: t("neetoApiKeys.placeholders.label"),
364
406
  ref: initialFocusRef
365
407
  }), /*#__PURE__*/jsxs("div", {
366
- className: "space-y-2",
367
- children: [!hasNoExpiry && /*#__PURE__*/jsx(DatePicker, {
368
- defaultValue: expiresAt,
369
- disabledDate: function disabledDate(date) {
370
- return date < NEXT_DAY;
371
- },
372
- label: t("neetoApiKeys.fields.expiryDate"),
373
- name: "expiresAt",
374
- placeholder: t("neetoApiKeys.placeholders.selectExpiryDate")
375
- }), /*#__PURE__*/jsx(Checkbox, {
376
- checked: hasNoExpiry,
377
- label: t("neetoApiKeys.fields.neverExpire"),
378
- name: "hasNoExpiry",
379
- onChange: function onChange() {
380
- setFieldValue("expiresAt", null);
381
- setFieldValue("hasNoExpiry", !hasNoExpiry);
382
- }
408
+ className: "space-y-4",
409
+ children: [!isEdit && isZapierAvailable && /*#__PURE__*/jsxs(Radio, {
410
+ label: t("neetoApiKeys.common.type"),
411
+ name: "type",
412
+ children: [/*#__PURE__*/jsx(Radio.Item, {
413
+ label: t("neetoApiKeys.common.general"),
414
+ name: "type",
415
+ value: API_KEY_TYPES.GENERAL
416
+ }), /*#__PURE__*/jsx(Radio.Item, {
417
+ label: t("neetoApiKeys.common.zapier"),
418
+ name: "type",
419
+ value: API_KEY_TYPES.ZAPIER
420
+ })]
421
+ }), type === API_KEY_TYPES.GENERAL && /*#__PURE__*/jsxs(Fragment, {
422
+ children: [!hasNoExpiry && /*#__PURE__*/jsx(DatePicker, {
423
+ defaultValue: expiresAt,
424
+ disabledDate: function disabledDate(date) {
425
+ return date < NEXT_DAY;
426
+ },
427
+ label: t("neetoApiKeys.fields.expiryDate"),
428
+ name: "expiresAt",
429
+ placeholder: t("neetoApiKeys.placeholders.selectExpiryDate")
430
+ }), /*#__PURE__*/jsx(Checkbox, {
431
+ checked: hasNoExpiry,
432
+ label: t("neetoApiKeys.fields.neverExpire"),
433
+ name: "hasNoExpiry",
434
+ onChange: function onChange() {
435
+ setFieldValue("expiresAt", null);
436
+ setFieldValue("hasNoExpiry", !hasNoExpiry);
437
+ }
438
+ })]
383
439
  })]
384
440
  })]
385
441
  })
@@ -398,7 +454,9 @@ var Form = withT(function (_ref) {
398
454
 
399
455
  var Create = function Create(_ref) {
400
456
  var onClose = _ref.onClose,
401
- isOpen = _ref.isOpen;
457
+ isOpen = _ref.isOpen,
458
+ _ref$isZapierAvailabl = _ref.isZapierAvailable,
459
+ isZapierAvailable = _ref$isZapierAvailabl === void 0 ? false : _ref$isZapierAvailabl;
402
460
  var initialFocusRef = useRef(null);
403
461
  var _useCreateApiKey = useCreateApiKey(onClose),
404
462
  createApiKey = _useCreateApiKey.mutate,
@@ -423,6 +481,7 @@ var Create = function Create(_ref) {
423
481
  })
424
482
  }), /*#__PURE__*/jsx(Form, {
425
483
  initialFocusRef: initialFocusRef,
484
+ isZapierAvailable: isZapierAvailable,
426
485
  onClose: onClose,
427
486
  isSubmitting: isCreating,
428
487
  onSubmit: createApiKey
@@ -470,6 +529,7 @@ var Update = function Update(_ref) {
470
529
  initialFocusRef: initialFocusRef,
471
530
  initialValues: initialValues,
472
531
  onClose: onClose,
532
+ isEdit: true,
473
533
  isSubmitting: isUpdating,
474
534
  onSubmit: handleUpdate
475
535
  })]
@@ -488,7 +548,8 @@ var Table = function Table(_ref) {
488
548
  data = _ref.data,
489
549
  isLoading = _ref.isLoading,
490
550
  isFetching = _ref.isFetching,
491
- handlePageChange = _ref.handlePageChange;
551
+ handlePageChange = _ref.handlePageChange,
552
+ isZapierAvailable = _ref.isZapierAvailable;
492
553
  var _useTranslation = useTranslation(),
493
554
  t = _useTranslation.t;
494
555
  if (isLoading) return /*#__PURE__*/jsx(PageLoader, {});
@@ -522,15 +583,16 @@ var Table = function Table(_ref) {
522
583
  children: /*#__PURE__*/jsx(NeetoUITable, {
523
584
  handlePageChange: handlePageChange,
524
585
  fixedHeight: true,
525
- columnData: buildColumnData({
526
- handleDelete: handleDelete,
527
- handleEdit: handleEdit
528
- }),
529
586
  currentPageNumber: currentPage,
530
587
  defaultPageSize: DEFAULT_PAGE_SIZE,
531
588
  loading: isFetching,
532
589
  rowData: data === null || data === void 0 ? void 0 : data.apiKeys,
533
- totalCount: data === null || data === void 0 ? void 0 : data.totalCount
590
+ totalCount: data === null || data === void 0 ? void 0 : data.totalCount,
591
+ columnData: buildColumnData({
592
+ handleDelete: handleDelete,
593
+ handleEdit: handleEdit,
594
+ isZapierAvailable: isZapierAvailable
595
+ })
534
596
  })
535
597
  });
536
598
  };
@@ -540,7 +602,9 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
540
602
  var ApiKeys = function ApiKeys(_ref) {
541
603
  var noDataProps = _ref.noDataProps,
542
604
  headerProps = _ref.headerProps,
543
- titleHelpPopoverProps = _ref.titleHelpPopoverProps;
605
+ titleHelpPopoverProps = _ref.titleHelpPopoverProps,
606
+ _ref$zapierIntegrable = _ref.zapierIntegrableType,
607
+ zapierIntegrableType = _ref$zapierIntegrable === void 0 ? "Organization" : _ref$zapierIntegrable;
544
608
  var _useState = useState({}),
545
609
  _useState2 = _slicedToArray(_useState, 2),
546
610
  apiKeyToBeDeleted = _useState2[0],
@@ -576,7 +640,9 @@ var ApiKeys = function ApiKeys(_ref) {
576
640
  pageSize: DEFAULT_PAGE_SIZE
577
641
  };
578
642
  var _useFetchApiKeys = useFetchApiKeys({
579
- params: queryParams
643
+ params: _objectSpread(_objectSpread({}, queryParams), {}, {
644
+ zapierIntegrableType: zapierIntegrableType
645
+ })
580
646
  }),
581
647
  data = _useFetchApiKeys.data,
582
648
  isLoading = _useFetchApiKeys.isLoading,
@@ -586,11 +652,15 @@ var ApiKeys = function ApiKeys(_ref) {
586
652
  if (!data) return;
587
653
  onFetchSuccess(data);
588
654
  }, [data]);
655
+ var _ref2 = data || {},
656
+ _ref2$isZapierAvailab = _ref2.isZapierAvailable,
657
+ isZapierAvailable = _ref2$isZapierAvailab === void 0 ? false : _ref2$isZapierAvailab;
589
658
  return /*#__PURE__*/jsxs("div", {
590
659
  className: "flex h-full w-full flex-col",
591
660
  children: [/*#__PURE__*/jsx(Header, _objectSpread({
592
661
  title: t("neetoApiKeys.common.apiKey", PLURAL),
593
662
  actionBlock: /*#__PURE__*/jsx(Button, {
663
+ "data-cy": "add-api-key-button",
594
664
  label: t("neetoApiKeys.buttons.addApiKey"),
595
665
  onClick: function onClick() {
596
666
  return setIsCreatePaneOpen(true);
@@ -612,6 +682,7 @@ var ApiKeys = function ApiKeys(_ref) {
612
682
  handlePageChange: handlePageChange,
613
683
  isFetching: isFetching,
614
684
  isLoading: isLoading,
685
+ isZapierAvailable: isZapierAvailable,
615
686
  noDataProps: noDataProps,
616
687
  setIsCreatePaneOpen: setIsCreatePaneOpen,
617
688
  handleDelete: setApiKeyToBeDeleted,
@@ -625,18 +696,24 @@ var ApiKeys = function ApiKeys(_ref) {
625
696
  components: {
626
697
  bold: /*#__PURE__*/jsx("strong", {})
627
698
  },
628
- i18nKey: "neetoApiKeys.alert.descriptions.deleteApiKey",
629
699
  values: {
630
700
  name: apiKeyToBeDeleted.label
631
- }
701
+ },
702
+ i18nKey: apiKeyToBeDeleted.type === API_KEY_TYPES.ZAPIER ? "neetoApiKeys.alert.descriptions.deleteZapierApiKey" : "neetoApiKeys.alert.descriptions.deleteApiKey"
632
703
  }),
633
704
  onClose: function onClose() {
634
705
  return setApiKeyToBeDeleted({});
635
706
  },
636
707
  onSubmit: function onSubmit() {
637
- return deleteApiKey(apiKeyToBeDeleted.id);
708
+ return deleteApiKey({
709
+ id: apiKeyToBeDeleted.id,
710
+ params: {
711
+ type: apiKeyToBeDeleted.type
712
+ }
713
+ });
638
714
  }
639
715
  }), /*#__PURE__*/jsx(Create, {
716
+ isZapierAvailable: isZapierAvailable,
640
717
  isOpen: isCreatePaneOpen,
641
718
  onClose: function onClose() {
642
719
  return setIsCreatePaneOpen(false);