chayns-api 1.0.1 → 1.0.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.
Files changed (211) hide show
  1. package/dist/cjs/calls/dialogs/alert.js +0 -2
  2. package/dist/cjs/calls/dialogs/chaynsDialog.js +2 -8
  3. package/dist/cjs/calls/dialogs/close.js +0 -2
  4. package/dist/cjs/calls/dialogs/communication.js +1 -16
  5. package/dist/cjs/calls/dialogs/confirm.js +0 -4
  6. package/dist/cjs/calls/dialogs/date.js +36 -53
  7. package/dist/cjs/calls/dialogs/dropUpAlert.js +0 -3
  8. package/dist/cjs/calls/dialogs/fileSelect.js +0 -10
  9. package/dist/cjs/calls/dialogs/iFrame.js +0 -8
  10. package/dist/cjs/calls/dialogs/index.js +0 -27
  11. package/dist/cjs/calls/dialogs/input.js +0 -6
  12. package/dist/cjs/calls/dialogs/mediaSelect.js +0 -7
  13. package/dist/cjs/calls/dialogs/open.js +0 -2
  14. package/dist/cjs/calls/dialogs/select.js +0 -9
  15. package/dist/cjs/calls/dialogs/signature.js +0 -5
  16. package/dist/cjs/calls/dialogs/toast.js +0 -3
  17. package/dist/cjs/calls/dialogs/utils/callback.js +0 -2
  18. package/dist/cjs/calls/dialogs/utils/environment.js +10 -0
  19. package/dist/cjs/calls/dialogs/utils/is.js +0 -4
  20. package/dist/cjs/calls/getUserInfo.js +0 -11
  21. package/dist/cjs/calls/index.js +3 -155
  22. package/dist/cjs/calls/sendMessage.js +0 -26
  23. package/dist/cjs/calls/visibilityChangeListener.js +1 -12
  24. package/dist/cjs/components/ChaynsContext.js +2 -4
  25. package/dist/cjs/components/ChaynsProvider.js +6 -28
  26. package/dist/cjs/components/WaitUntil.js +0 -5
  27. package/dist/cjs/components/withCompatMode.js +1 -16
  28. package/dist/cjs/helper/apiListenerHelper.js +0 -9
  29. package/dist/cjs/hooks/geoLocationListener.js +2 -11
  30. package/dist/cjs/hooks/index.js +6 -16
  31. package/dist/cjs/hooks/scrollListener.js +4 -23
  32. package/dist/cjs/hooks/useAccessToken.js +0 -5
  33. package/dist/cjs/hooks/useCurrentPage.js +0 -4
  34. package/dist/cjs/hooks/useCustomData.js +0 -4
  35. package/dist/cjs/hooks/useDevice.js +0 -4
  36. package/dist/cjs/hooks/useEnvironment.js +0 -4
  37. package/dist/cjs/hooks/useFunctions.js +0 -4
  38. package/dist/cjs/hooks/useIsAdminMode.js +0 -5
  39. package/dist/cjs/hooks/useLanguage.js +0 -4
  40. package/dist/cjs/hooks/usePages.js +22 -14
  41. package/dist/cjs/hooks/useParameters.js +0 -4
  42. package/dist/cjs/hooks/useSite.js +0 -4
  43. package/dist/cjs/hooks/useUser.js +0 -5
  44. package/dist/cjs/hooks/useValues.js +0 -4
  45. package/dist/cjs/hooks/windowMetricsListener.js +2 -12
  46. package/dist/cjs/host/ChaynsHost.js +0 -10
  47. package/dist/cjs/host/iframe/HostIframe.js +23 -30
  48. package/dist/cjs/host/iframe/utils/useUpdateData.js +0 -3
  49. package/dist/cjs/host/module/ModuleHost.js +3 -13
  50. package/dist/cjs/host/{HostIframe.js → module/PagemakerFrame.js} +23 -75
  51. package/dist/cjs/host/module/utils/loadComponent.js +1 -18
  52. package/dist/cjs/host/module/utils/useDynamicScript.js +0 -18
  53. package/dist/cjs/index.js +0 -19
  54. package/dist/cjs/types/IChaynsReact.js +27 -48
  55. package/dist/cjs/util/appCall.js +1 -4
  56. package/dist/cjs/util/deviceHelper.js +4 -21
  57. package/dist/cjs/util/heightHelper.js +0 -9
  58. package/dist/cjs/util/postIframeForm.js +0 -5
  59. package/dist/cjs/wrapper/AppWrapper.js +318 -159
  60. package/dist/cjs/wrapper/FrameWrapper.js +215 -248
  61. package/dist/cjs/wrapper/ModuleFederationWrapper.js +2 -27
  62. package/dist/cjs/wrapper/SsrWrapper.js +0 -8
  63. package/dist/esm/calls/dialogs/alert.js +4 -4
  64. package/dist/esm/calls/dialogs/chaynsDialog.js +7 -11
  65. package/dist/esm/calls/dialogs/communication.js +15 -26
  66. package/dist/esm/calls/dialogs/confirm.js +5 -8
  67. package/dist/esm/calls/dialogs/date.js +85 -94
  68. package/dist/esm/calls/dialogs/dropUpAlert.js +1 -1
  69. package/dist/esm/calls/dialogs/fileSelect.js +23 -62
  70. package/dist/esm/calls/dialogs/iFrame.js +7 -10
  71. package/dist/esm/calls/dialogs/input.js +2 -5
  72. package/dist/esm/calls/dialogs/mediaSelect.js +18 -55
  73. package/dist/esm/calls/dialogs/open.js +2 -2
  74. package/dist/esm/calls/dialogs/select.js +5 -9
  75. package/dist/esm/calls/dialogs/signature.js +0 -2
  76. package/dist/esm/calls/dialogs/toast.js +6 -11
  77. package/dist/esm/calls/dialogs/utils/callback.js +3 -5
  78. package/dist/esm/calls/dialogs/utils/environment.js +3 -0
  79. package/dist/esm/calls/dialogs/utils/is.js +1 -3
  80. package/dist/esm/calls/getUserInfo.js +32 -92
  81. package/dist/esm/calls/index.js +124 -276
  82. package/dist/esm/calls/sendMessage.js +91 -221
  83. package/dist/esm/calls/visibilityChangeListener.js +10 -15
  84. package/dist/esm/components/ChaynsContext.js +3 -3
  85. package/dist/esm/components/ChaynsProvider.js +45 -86
  86. package/dist/esm/components/WaitUntil.js +21 -86
  87. package/dist/esm/components/withCompatMode.js +35 -77
  88. package/dist/esm/helper/apiListenerHelper.js +10 -15
  89. package/dist/esm/hooks/geoLocationListener.js +20 -46
  90. package/dist/esm/hooks/index.js +1 -1
  91. package/dist/esm/hooks/scrollListener.js +50 -86
  92. package/dist/esm/hooks/useAccessToken.js +6 -28
  93. package/dist/esm/hooks/useCurrentPage.js +2 -6
  94. package/dist/esm/hooks/useCustomData.js +2 -6
  95. package/dist/esm/hooks/useDevice.js +1 -6
  96. package/dist/esm/hooks/useEnvironment.js +1 -6
  97. package/dist/esm/hooks/useFunctions.js +2 -5
  98. package/dist/esm/hooks/useIsAdminMode.js +2 -6
  99. package/dist/esm/hooks/useLanguage.js +1 -6
  100. package/dist/esm/hooks/usePages.js +34 -27
  101. package/dist/esm/hooks/useParameters.js +1 -6
  102. package/dist/esm/hooks/useSite.js +1 -6
  103. package/dist/esm/hooks/useUser.js +1 -7
  104. package/dist/esm/hooks/useValues.js +2 -5
  105. package/dist/esm/hooks/windowMetricsListener.js +18 -44
  106. package/dist/esm/host/ChaynsHost.js +22 -29
  107. package/dist/esm/host/iframe/HostIframe.js +86 -142
  108. package/dist/esm/host/iframe/utils/useUpdateData.js +4 -6
  109. package/dist/esm/host/module/ModuleHost.js +42 -49
  110. package/dist/esm/host/module/PagemakerFrame.js +97 -0
  111. package/dist/esm/host/module/utils/loadComponent.js +47 -85
  112. package/dist/esm/host/module/utils/useDynamicScript.js +27 -74
  113. package/dist/esm/types/IChaynsReact.js +37 -61
  114. package/dist/esm/util/appCall.js +2 -4
  115. package/dist/esm/util/deviceHelper.js +12 -36
  116. package/dist/esm/util/heightHelper.js +10 -13
  117. package/dist/esm/util/postIframeForm.js +25 -57
  118. package/dist/esm/wrapper/AppWrapper.js +380 -781
  119. package/dist/esm/wrapper/FrameWrapper.js +258 -1509
  120. package/dist/esm/wrapper/ModuleFederationWrapper.js +47 -284
  121. package/dist/esm/wrapper/SsrWrapper.js +19 -65
  122. package/dist/types/calls/dialogs/confirm.d.ts +1 -1
  123. package/dist/types/calls/dialogs/date.d.ts +4 -4
  124. package/dist/types/calls/dialogs/dropUpAlert.d.ts +1 -1
  125. package/dist/types/calls/dialogs/fileSelect.d.ts +1 -1
  126. package/dist/types/calls/dialogs/iFrame.d.ts +1 -1
  127. package/dist/types/calls/dialogs/input.d.ts +1 -1
  128. package/dist/types/calls/dialogs/mediaSelect.d.ts +1 -1
  129. package/dist/types/calls/dialogs/signature.d.ts +1 -1
  130. package/dist/types/calls/dialogs/utils/environment.d.ts +3 -0
  131. package/dist/types/calls/index.d.ts +0 -6
  132. package/dist/types/components/ChaynsProvider.d.ts +1 -1
  133. package/dist/types/components/WaitUntil.d.ts +1 -1
  134. package/dist/types/components/withCompatMode.d.ts +1 -1
  135. package/dist/types/hooks/index.d.ts +1 -1
  136. package/dist/types/hooks/useAccessToken.d.ts +1 -1
  137. package/dist/types/hooks/usePages.d.ts +4 -0
  138. package/dist/types/host/ChaynsHost.d.ts +1 -1
  139. package/dist/types/host/iframe/HostIframe.d.ts +1 -1
  140. package/dist/types/host/module/ModuleHost.d.ts +2 -2
  141. package/dist/types/host/{HostIframe.d.ts → module/PagemakerFrame.d.ts} +7 -5
  142. package/dist/types/types/IChaynsReact.d.ts +55 -24
  143. package/dist/types/util/deviceHelper.d.ts +2 -2
  144. package/dist/types/wrapper/AppWrapper.d.ts +6 -4
  145. package/package.json +1 -1
  146. package/dist/cjs/bootstrap.js +0 -11
  147. package/dist/cjs/calls/abstractApiListener.js +0 -40
  148. package/dist/cjs/calls/apiEventListener.js +0 -40
  149. package/dist/cjs/calls/setVisibilityChangeListener.js +0 -1
  150. package/dist/cjs/calls/windowMetricsListener.js +0 -18
  151. package/dist/cjs/components/App.js +0 -32
  152. package/dist/cjs/components/App.spec.js +0 -16
  153. package/dist/cjs/components/Button.js +0 -32
  154. package/dist/cjs/components/ChaynsProviderExposed.js +0 -16
  155. package/dist/cjs/components/TestProvider.js +0 -236
  156. package/dist/cjs/components/Title.js +0 -162
  157. package/dist/cjs/functions/addApiListener.js +0 -37
  158. package/dist/cjs/functions/addGeoLocationListener.js +0 -26
  159. package/dist/cjs/functions/addScrollListener.js +0 -26
  160. package/dist/cjs/functions/addWindowMetricsListener.js +0 -37
  161. package/dist/cjs/helper/cssLoader.js +0 -28
  162. package/dist/cjs/hooks/addGeoLocationListener.js +0 -26
  163. package/dist/cjs/hooks/addScrollListener.js +0 -26
  164. package/dist/cjs/hooks/addWindowMetricsListener.js +0 -37
  165. package/dist/cjs/hooks/geoLocation.js +0 -48
  166. package/dist/cjs/hooks/useAddGeoLocationListener.js +0 -26
  167. package/dist/cjs/hooks/useAddScrollListener.js +0 -48
  168. package/dist/cjs/hooks/useAddWindowMetricsListener.js +0 -45
  169. package/dist/cjs/hooks/useAdddScrollListener.js +0 -26
  170. package/dist/cjs/hooks/windowMetrics.js +0 -45
  171. package/dist/cjs/host/ModuleHost.js +0 -11
  172. package/dist/cjs/host/module/utils.js +0 -25
  173. package/dist/cjs/index.example.js +0 -7
  174. package/dist/cjs/index2.js +0 -64
  175. package/dist/cjs/types/DynamicImport.d.js +0 -5
  176. package/dist/cjs/types/chayns-components.d.js +0 -1
  177. package/dist/cjs/types/chayns-logger.d.js +0 -1
  178. package/dist/cjs/types/chayns.d.js +0 -1
  179. package/dist/cjs/types/tobit-websocket-service-client.d.js +0 -1
  180. package/dist/cjs/types/toolkit-types.d.js +0 -1
  181. package/dist/cjs/util/useFunctionsContext.js +0 -16
  182. package/dist/cjs/util/useIsAdminMode.js +0 -18
  183. package/dist/cjs/util/useUser.js +0 -16
  184. package/dist/esm/bootstrap.js +0 -4
  185. package/dist/esm/components/App.js +0 -35
  186. package/dist/esm/components/App.spec.js +0 -9
  187. package/dist/esm/components/Button.js +0 -34
  188. package/dist/esm/components/ChaynsProviderExposed.js +0 -3
  189. package/dist/esm/components/TestProvider.js +0 -308
  190. package/dist/esm/components/Title.js +0 -210
  191. package/dist/esm/helper/cssLoader.js +0 -21
  192. package/dist/esm/hooks/useAddGeoLocationListener.js +0 -18
  193. package/dist/esm/hooks/useAddScrollListener.js +0 -18
  194. package/dist/esm/hooks/useAddWindowMetricsListener.js +0 -18
  195. package/dist/esm/host/HostIframe.js +0 -153
  196. package/dist/esm/index.example.js +0 -1
  197. package/dist/esm/index2.js +0 -5
  198. package/dist/esm/types/DynamicImport.d.js +0 -1
  199. package/dist/esm/types/chayns-components.d.js +0 -0
  200. package/dist/esm/types/chayns-logger.d.js +0 -0
  201. package/dist/esm/types/chayns.d.js +0 -0
  202. package/dist/esm/types/tobit-websocket-service-client.d.js +0 -0
  203. package/dist/esm/types/toolkit-types.d.js +0 -0
  204. package/dist/esm/util/useIsAdminMode.js +0 -9
  205. package/dist/esm/util/useUser.js +0 -7
  206. package/dist/types/bootstrap.d.ts +0 -1
  207. package/dist/types/components/App.d.ts +0 -5
  208. package/dist/types/components/Button.d.ts +0 -8
  209. package/dist/types/components/ChaynsProviderExposed.d.ts +0 -13
  210. package/dist/types/components/Title.d.ts +0 -3
  211. package/dist/types/index.example.d.ts +0 -0
@@ -1,59 +1,22 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
2
-
3
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
4
-
5
1
  import { buttonText, buttonType, dialogAction } from './chaynsDialog';
6
2
  import { open } from './open';
7
3
  import { getAccessToken, getUser, login } from "../index";
8
- export function mediaSelect() {
9
- return _mediaSelect.apply(this, arguments);
10
- }
11
-
12
- function _mediaSelect() {
13
- _mediaSelect = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
14
- var dialog,
15
- user,
16
- _args = arguments;
17
- return regeneratorRuntime.wrap(function _callee$(_context) {
18
- while (1) {
19
- switch (_context.prev = _context.next) {
20
- case 0:
21
- dialog = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
22
-
23
- if (!dialog.buttons || !Array.isArray(dialog.buttons)) {
24
- dialog.buttons = [{
25
- 'text': buttonText.OK,
26
- 'buttonType': buttonType.POSITIVE
27
- }, {
28
- 'text': buttonText.CANCEL,
29
- 'buttonType': buttonType.NEGATIVE
30
- }];
31
- }
32
-
33
- dialog.callType = dialogAction.MEDIA_SELECT;
34
- user = getUser();
35
-
36
- if (user) {
37
- _context.next = 6;
38
- break;
39
- }
40
-
41
- return _context.abrupt("return", login());
42
-
43
- case 6:
44
- _context.next = 8;
45
- return getAccessToken();
46
-
47
- case 8:
48
- dialog.chaynsToken = _context.sent.accessToken;
49
- return _context.abrupt("return", open(dialog));
50
-
51
- case 10:
52
- case "end":
53
- return _context.stop();
54
- }
55
- }
56
- }, _callee);
57
- }));
58
- return _mediaSelect.apply(this, arguments);
4
+ export async function mediaSelect() {
5
+ let dialog = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
6
+ if (!dialog.buttons || !Array.isArray(dialog.buttons)) {
7
+ dialog.buttons = [{
8
+ 'text': buttonText.OK,
9
+ 'buttonType': buttonType.POSITIVE
10
+ }, {
11
+ 'text': buttonText.CANCEL,
12
+ 'buttonType': buttonType.NEGATIVE
13
+ }];
14
+ }
15
+ dialog.callType = dialogAction.MEDIA_SELECT;
16
+ const user = getUser();
17
+ if (!user) {
18
+ return login();
19
+ }
20
+ dialog.chaynsToken = (await getAccessToken()).accessToken;
21
+ return open(dialog);
59
22
  }
@@ -1,12 +1,12 @@
1
1
  import { invokeDialogCall } from "../index";
2
2
  export function open(json) {
3
- return new Promise(function (resolve, reject) {
3
+ return new Promise((resolve, reject) => {
4
4
  invokeDialogCall({
5
5
  action: 184,
6
6
  value: {
7
7
  'dialogContent': json
8
8
  }
9
- }, function (e) {
9
+ }, e => {
10
10
  resolve(e);
11
11
  });
12
12
  });
@@ -2,10 +2,9 @@ import { buttonText, buttonType, dialogAction } from './chaynsDialog';
2
2
  import { open } from './open';
3
3
  import { isPresent } from "./utils/is";
4
4
  export function select(config) {
5
- var list = [];
6
-
7
- for (var i = 0, l = config.list.length; i < l; i++) {
8
- var item = config.list[i];
5
+ const list = [];
6
+ for (let i = 0, l = config.list.length; i < l; i++) {
7
+ const item = config.list[i];
9
8
  list.push({
10
9
  name: item.name,
11
10
  'value': isPresent(item.value) ? item.value : item.name,
@@ -16,11 +15,9 @@ export function select(config) {
16
15
  'url': item.url
17
16
  });
18
17
  }
19
-
20
18
  if (config.list.length === 0) {
21
19
  return Promise.reject(new Error('Invalid Parameters'));
22
20
  }
23
-
24
21
  if (!config.buttons || !Array.isArray(config.buttons)) {
25
22
  config.buttons = [{
26
23
  'text': buttonText.OK,
@@ -30,7 +27,6 @@ export function select(config) {
30
27
  'buttonType': buttonType.CANCEL
31
28
  }];
32
29
  }
33
-
34
30
  return open({
35
31
  'callType': dialogAction.SELECT,
36
32
  'title': config.title || '',
@@ -42,10 +38,10 @@ export function select(config) {
42
38
  'type': config.type,
43
39
  'preventCloseOnClick': !!config.preventCloseOnClick,
44
40
  'selectAllButton': config.selectAllButton,
45
- list: list
41
+ list
46
42
  });
47
43
  }
48
- export var selectType = {
44
+ export const selectType = {
49
45
  'DEFAULT': 0,
50
46
  'ICON': 1
51
47
  };
@@ -2,7 +2,6 @@ import { buttonText, buttonType, dialogAction } from './chaynsDialog';
2
2
  import { open } from './open';
3
3
  export function signature(dialog) {
4
4
  if (!dialog) dialog = {};
5
-
6
5
  if (!dialog.buttons || !Array.isArray(dialog.buttons)) {
7
6
  dialog.buttons = [];
8
7
  dialog.buttons.push({
@@ -14,7 +13,6 @@ export function signature(dialog) {
14
13
  'buttonType': buttonType.NEGATIVE
15
14
  });
16
15
  }
17
-
18
16
  dialog.callType = dialogAction.SIGNATURE;
19
17
  return open(dialog);
20
18
  }
@@ -1,18 +1,13 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
1
  import { getCallbackName } from "./utils/callback";
8
2
  import { invokeDialogCall } from "../index";
9
3
  export function toast() {
10
- var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11
- var callbackName = 'toastCallback';
4
+ let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
5
+ const callbackName = 'toastCallback';
12
6
  return invokeDialogCall({
13
7
  action: 276,
14
- value: _objectSpread({
15
- 'callback': getCallbackName(callbackName)
16
- }, config)
8
+ value: {
9
+ 'callback': getCallbackName(callbackName),
10
+ ...config
11
+ }
17
12
  });
18
13
  }
@@ -1,9 +1,7 @@
1
1
  export function getCallbackName(fnName) {
2
- var framePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
3
-
2
+ let framePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
4
3
  if (framePrefix !== '') {
5
- return "window._chaynsCallbacks.".concat(framePrefix, ".").concat(fnName);
4
+ return `window._chaynsCallbacks.${framePrefix}.${fnName}`;
6
5
  }
7
-
8
- return "window._chaynsCallbacks.".concat(fnName);
6
+ return `window._chaynsCallbacks.${fnName}`;
9
7
  }
@@ -0,0 +1,3 @@
1
+ export var environment = {
2
+ language: (navigator.languages && navigator.languages.length > 0 ? navigator.languages[0] : navigator.language).substring(0, 2)
3
+ };
@@ -1,7 +1,5 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
-
3
1
  export function isObject(value) {
4
- return value !== null && _typeof(value) === 'object';
2
+ return value !== null && typeof value === 'object';
5
3
  }
6
4
  export function isNumber(value) {
7
5
  return typeof value === 'number' && !isNaN(value);
@@ -1,93 +1,33 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
2
-
3
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
4
-
5
- var getUserInfo = /*#__PURE__*/function () {
6
- var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(api, value) {
7
- var _value$personId;
8
-
9
- var query, _yield$api$functions$, accessToken, res, data;
10
-
11
- return regeneratorRuntime.wrap(function _callee$(_context) {
12
- while (1) {
13
- switch (_context.prev = _context.next) {
14
- case 0:
15
- query = (_value$personId = value.personId) !== null && _value$personId !== void 0 ? _value$personId : value.userId;
16
-
17
- if (query) {
18
- _context.next = 3;
19
- break;
20
- }
21
-
22
- throw new Error('Invalid Parameters - You have to provide at least one of these Parameters: userId, personId');
23
-
24
- case 3:
25
- _context.next = 5;
26
- return api.functions.getAccessToken();
27
-
28
- case 5:
29
- _yield$api$functions$ = _context.sent;
30
- accessToken = _yield$api$functions$.accessToken;
31
-
32
- if (accessToken) {
33
- _context.next = 9;
34
- break;
35
- }
36
-
37
- throw new Error('get user info requires a user to be logged in');
38
-
39
- case 9:
40
- _context.next = 11;
41
- return fetch("https://relations.chayns.net/relations/user/findUser?searchString=".concat(query), {
42
- 'headers': {
43
- 'authorization': "bearer ".concat(accessToken)
44
- }
45
- });
46
-
47
- case 11:
48
- res = _context.sent;
49
-
50
- if (!res.ok) {
51
- _context.next = 19;
52
- break;
53
- }
54
-
55
- _context.next = 15;
56
- return res.json();
57
-
58
- case 15:
59
- data = _context.sent;
60
-
61
- if (!(data.length === 0)) {
62
- _context.next = 18;
63
- break;
64
- }
65
-
66
- return _context.abrupt("return", null);
67
-
68
- case 18:
69
- return _context.abrupt("return", {
70
- firstName: data[0].firstName,
71
- lastName: data[0].lastName,
72
- userId: data[0].userId,
73
- personId: data[0].personId,
74
- name: data[0].name
75
- });
76
-
77
- case 19:
78
- throw new Error("getUserInfo failed with status ".concat(res.status));
79
-
80
- case 20:
81
- case "end":
82
- return _context.stop();
83
- }
84
- }
85
- }, _callee);
86
- }));
87
-
88
- return function getUserInfo(_x, _x2) {
89
- return _ref.apply(this, arguments);
90
- };
91
- }();
92
-
1
+ const getUserInfo = async (api, value) => {
2
+ var _value$personId;
3
+ const query = (_value$personId = value.personId) !== null && _value$personId !== void 0 ? _value$personId : value.userId;
4
+ if (!query) {
5
+ throw new Error('Invalid Parameters - You have to provide at least one of these Parameters: userId, personId');
6
+ }
7
+ const {
8
+ accessToken
9
+ } = await api.functions.getAccessToken();
10
+ if (!accessToken) {
11
+ throw new Error('get user info requires a user to be logged in');
12
+ }
13
+ const res = await fetch(`https://relations.chayns.net/relations/user/findUser?searchString=${query}`, {
14
+ 'headers': {
15
+ 'authorization': `bearer ${accessToken}`
16
+ }
17
+ });
18
+ if (res.ok) {
19
+ const data = await res.json();
20
+ if (data.length === 0) {
21
+ return null;
22
+ }
23
+ return {
24
+ firstName: data[0].firstName,
25
+ lastName: data[0].lastName,
26
+ userId: data[0].userId,
27
+ personId: data[0].personId,
28
+ name: data[0].name
29
+ };
30
+ }
31
+ throw new Error(`getUserInfo failed with status ${res.status}`);
32
+ };
93
33
  export default getUserInfo;