chayns-api 1.0.0 → 1.0.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.
Files changed (205) hide show
  1. package/dist/cjs/bootstrap.js +11 -0
  2. package/dist/cjs/calls/abstractApiListener.js +40 -0
  3. package/dist/cjs/calls/apiEventListener.js +40 -0
  4. package/dist/cjs/calls/dialogs/alert.js +2 -0
  5. package/dist/cjs/calls/dialogs/chaynsDialog.js +8 -2
  6. package/dist/cjs/calls/dialogs/close.js +2 -0
  7. package/dist/cjs/calls/dialogs/communication.js +16 -1
  8. package/dist/cjs/calls/dialogs/confirm.js +4 -0
  9. package/dist/cjs/calls/dialogs/date.js +53 -36
  10. package/dist/cjs/calls/dialogs/dropUpAlert.js +3 -0
  11. package/dist/cjs/calls/dialogs/fileSelect.js +10 -0
  12. package/dist/cjs/calls/dialogs/iFrame.js +8 -0
  13. package/dist/cjs/calls/dialogs/index.js +27 -0
  14. package/dist/cjs/calls/dialogs/input.js +6 -0
  15. package/dist/cjs/calls/dialogs/mediaSelect.js +7 -0
  16. package/dist/cjs/calls/dialogs/open.js +2 -0
  17. package/dist/cjs/calls/dialogs/select.js +9 -0
  18. package/dist/cjs/calls/dialogs/signature.js +5 -0
  19. package/dist/cjs/calls/dialogs/toast.js +3 -0
  20. package/dist/cjs/calls/dialogs/utils/callback.js +2 -0
  21. package/dist/cjs/calls/dialogs/utils/is.js +4 -0
  22. package/dist/cjs/calls/getUserInfo.js +11 -0
  23. package/dist/cjs/calls/index.js +155 -3
  24. package/dist/cjs/calls/sendMessage.js +26 -0
  25. package/dist/cjs/calls/setVisibilityChangeListener.js +1 -0
  26. package/dist/cjs/calls/visibilityChangeListener.js +12 -1
  27. package/dist/cjs/calls/windowMetricsListener.js +18 -0
  28. package/dist/cjs/components/App.js +32 -0
  29. package/dist/cjs/components/App.spec.js +16 -0
  30. package/dist/cjs/components/Button.js +32 -0
  31. package/dist/cjs/components/ChaynsContext.js +4 -2
  32. package/dist/cjs/components/ChaynsProvider.js +28 -6
  33. package/dist/cjs/components/ChaynsProviderExposed.js +16 -0
  34. package/dist/cjs/components/TestProvider.js +236 -0
  35. package/dist/cjs/components/Title.js +162 -0
  36. package/dist/cjs/components/WaitUntil.js +5 -0
  37. package/dist/cjs/components/withCompatMode.js +16 -1
  38. package/dist/cjs/functions/addApiListener.js +37 -0
  39. package/dist/cjs/functions/addGeoLocationListener.js +26 -0
  40. package/dist/cjs/functions/addScrollListener.js +26 -0
  41. package/dist/cjs/functions/addWindowMetricsListener.js +37 -0
  42. package/dist/cjs/helper/apiListenerHelper.js +9 -0
  43. package/dist/cjs/helper/cssLoader.js +28 -0
  44. package/dist/cjs/hooks/addGeoLocationListener.js +26 -0
  45. package/dist/cjs/hooks/addScrollListener.js +26 -0
  46. package/dist/cjs/hooks/addWindowMetricsListener.js +37 -0
  47. package/dist/cjs/hooks/geoLocation.js +48 -0
  48. package/dist/cjs/hooks/geoLocationListener.js +11 -2
  49. package/dist/cjs/hooks/index.js +16 -0
  50. package/dist/cjs/hooks/scrollListener.js +23 -4
  51. package/dist/cjs/hooks/useAccessToken.js +5 -0
  52. package/dist/cjs/hooks/useAddGeoLocationListener.js +26 -0
  53. package/dist/cjs/hooks/useAddScrollListener.js +48 -0
  54. package/dist/cjs/hooks/useAddWindowMetricsListener.js +45 -0
  55. package/dist/cjs/hooks/useAdddScrollListener.js +26 -0
  56. package/dist/cjs/hooks/useCurrentPage.js +4 -0
  57. package/dist/cjs/hooks/useCustomData.js +4 -0
  58. package/dist/cjs/hooks/useDevice.js +4 -0
  59. package/dist/cjs/hooks/useEnvironment.js +4 -0
  60. package/dist/cjs/hooks/useFunctions.js +4 -0
  61. package/dist/cjs/hooks/useIsAdminMode.js +5 -0
  62. package/dist/cjs/hooks/useLanguage.js +4 -0
  63. package/dist/cjs/hooks/usePages.js +12 -0
  64. package/dist/cjs/hooks/useParameters.js +4 -0
  65. package/dist/cjs/hooks/useSite.js +4 -0
  66. package/dist/cjs/hooks/useUser.js +4 -0
  67. package/dist/cjs/hooks/useValues.js +4 -0
  68. package/dist/cjs/hooks/windowMetrics.js +45 -0
  69. package/dist/cjs/hooks/windowMetricsListener.js +12 -2
  70. package/dist/cjs/host/ChaynsHost.js +12 -0
  71. package/dist/cjs/host/{module/PagemakerFrame.js → HostIframe.js} +75 -23
  72. package/dist/cjs/host/ModuleHost.js +11 -0
  73. package/dist/cjs/host/iframe/HostIframe.js +30 -23
  74. package/dist/cjs/host/iframe/utils/useUpdateData.js +3 -0
  75. package/dist/cjs/host/module/ModuleHost.js +13 -3
  76. package/dist/cjs/host/module/utils/loadComponent.js +18 -1
  77. package/dist/cjs/host/module/utils/useDynamicScript.js +18 -0
  78. package/dist/cjs/host/module/utils.js +25 -0
  79. package/dist/cjs/index.example.js +7 -0
  80. package/dist/cjs/index.js +19 -0
  81. package/dist/cjs/index2.js +64 -0
  82. package/dist/cjs/types/DynamicImport.d.js +5 -0
  83. package/dist/cjs/types/IChaynsReact.js +47 -0
  84. package/dist/cjs/types/chayns-components.d.js +1 -0
  85. package/dist/cjs/types/chayns-logger.d.js +1 -0
  86. package/dist/cjs/types/chayns.d.js +1 -0
  87. package/dist/cjs/types/tobit-websocket-service-client.d.js +1 -0
  88. package/dist/cjs/types/toolkit-types.d.js +1 -0
  89. package/dist/cjs/util/appCall.js +4 -1
  90. package/dist/cjs/util/deviceHelper.js +17 -2
  91. package/dist/cjs/util/heightHelper.js +9 -0
  92. package/dist/cjs/util/postIframeForm.js +5 -0
  93. package/dist/cjs/util/useFunctionsContext.js +16 -0
  94. package/dist/cjs/util/useIsAdminMode.js +18 -0
  95. package/dist/cjs/util/useUser.js +16 -0
  96. package/dist/cjs/wrapper/AppWrapper.js +144 -119
  97. package/dist/cjs/wrapper/FrameWrapper.js +248 -215
  98. package/dist/cjs/wrapper/ModuleFederationWrapper.js +27 -2
  99. package/dist/cjs/wrapper/SsrWrapper.js +8 -0
  100. package/dist/esm/bootstrap.js +4 -0
  101. package/dist/esm/calls/dialogs/alert.js +4 -4
  102. package/dist/esm/calls/dialogs/chaynsDialog.js +11 -7
  103. package/dist/esm/calls/dialogs/communication.js +26 -15
  104. package/dist/esm/calls/dialogs/confirm.js +8 -5
  105. package/dist/esm/calls/dialogs/date.js +94 -85
  106. package/dist/esm/calls/dialogs/dropUpAlert.js +1 -1
  107. package/dist/esm/calls/dialogs/fileSelect.js +62 -23
  108. package/dist/esm/calls/dialogs/iFrame.js +10 -7
  109. package/dist/esm/calls/dialogs/input.js +5 -2
  110. package/dist/esm/calls/dialogs/mediaSelect.js +55 -18
  111. package/dist/esm/calls/dialogs/open.js +2 -2
  112. package/dist/esm/calls/dialogs/select.js +9 -5
  113. package/dist/esm/calls/dialogs/signature.js +2 -0
  114. package/dist/esm/calls/dialogs/toast.js +11 -6
  115. package/dist/esm/calls/dialogs/utils/callback.js +5 -3
  116. package/dist/esm/calls/dialogs/utils/is.js +3 -1
  117. package/dist/esm/calls/getUserInfo.js +92 -32
  118. package/dist/esm/calls/index.js +276 -124
  119. package/dist/esm/calls/sendMessage.js +221 -91
  120. package/dist/esm/calls/visibilityChangeListener.js +15 -10
  121. package/dist/esm/components/App.js +35 -0
  122. package/dist/esm/components/App.spec.js +9 -0
  123. package/dist/esm/components/Button.js +34 -0
  124. package/dist/esm/components/ChaynsContext.js +3 -3
  125. package/dist/esm/components/ChaynsProvider.js +86 -45
  126. package/dist/esm/components/ChaynsProviderExposed.js +3 -0
  127. package/dist/esm/components/TestProvider.js +308 -0
  128. package/dist/esm/components/Title.js +210 -0
  129. package/dist/esm/components/WaitUntil.js +86 -21
  130. package/dist/esm/components/withCompatMode.js +77 -35
  131. package/dist/esm/helper/apiListenerHelper.js +15 -10
  132. package/dist/esm/helper/cssLoader.js +21 -0
  133. package/dist/esm/hooks/geoLocationListener.js +46 -20
  134. package/dist/esm/hooks/scrollListener.js +86 -50
  135. package/dist/esm/hooks/useAccessToken.js +28 -6
  136. package/dist/esm/hooks/useAddGeoLocationListener.js +18 -0
  137. package/dist/esm/hooks/useAddScrollListener.js +18 -0
  138. package/dist/esm/hooks/useAddWindowMetricsListener.js +18 -0
  139. package/dist/esm/hooks/useCurrentPage.js +6 -2
  140. package/dist/esm/hooks/useCustomData.js +6 -2
  141. package/dist/esm/hooks/useDevice.js +6 -1
  142. package/dist/esm/hooks/useEnvironment.js +6 -1
  143. package/dist/esm/hooks/useFunctions.js +5 -2
  144. package/dist/esm/hooks/useIsAdminMode.js +6 -2
  145. package/dist/esm/hooks/useLanguage.js +6 -1
  146. package/dist/esm/hooks/usePages.js +27 -14
  147. package/dist/esm/hooks/useParameters.js +6 -1
  148. package/dist/esm/hooks/useSite.js +6 -1
  149. package/dist/esm/hooks/useUser.js +6 -1
  150. package/dist/esm/hooks/useValues.js +5 -2
  151. package/dist/esm/hooks/windowMetricsListener.js +44 -18
  152. package/dist/esm/host/ChaynsHost.js +30 -21
  153. package/dist/esm/host/HostIframe.js +153 -0
  154. package/dist/esm/host/iframe/HostIframe.js +142 -86
  155. package/dist/esm/host/iframe/utils/useUpdateData.js +6 -4
  156. package/dist/esm/host/module/ModuleHost.js +49 -42
  157. package/dist/esm/host/module/utils/loadComponent.js +85 -47
  158. package/dist/esm/host/module/utils/useDynamicScript.js +74 -27
  159. package/dist/esm/index.example.js +1 -0
  160. package/dist/esm/index2.js +5 -0
  161. package/dist/esm/types/DynamicImport.d.js +1 -0
  162. package/dist/esm/types/IChaynsReact.js +61 -14
  163. package/dist/esm/types/chayns-components.d.js +0 -0
  164. package/dist/esm/types/chayns-logger.d.js +0 -0
  165. package/dist/esm/types/chayns.d.js +0 -0
  166. package/dist/esm/types/tobit-websocket-service-client.d.js +0 -0
  167. package/dist/esm/types/toolkit-types.d.js +0 -0
  168. package/dist/esm/util/appCall.js +4 -2
  169. package/dist/esm/util/deviceHelper.js +33 -11
  170. package/dist/esm/util/heightHelper.js +13 -10
  171. package/dist/esm/util/postIframeForm.js +57 -25
  172. package/dist/esm/util/useIsAdminMode.js +9 -0
  173. package/dist/esm/util/useUser.js +7 -0
  174. package/dist/esm/wrapper/AppWrapper.js +762 -179
  175. package/dist/esm/wrapper/FrameWrapper.js +1509 -258
  176. package/dist/esm/wrapper/ModuleFederationWrapper.js +284 -47
  177. package/dist/esm/wrapper/SsrWrapper.js +65 -19
  178. package/dist/types/bootstrap.d.ts +1 -0
  179. package/dist/types/calls/dialogs/confirm.d.ts +1 -1
  180. package/dist/types/calls/dialogs/date.d.ts +4 -4
  181. package/dist/types/calls/dialogs/dropUpAlert.d.ts +1 -1
  182. package/dist/types/calls/dialogs/fileSelect.d.ts +1 -1
  183. package/dist/types/calls/dialogs/iFrame.d.ts +1 -1
  184. package/dist/types/calls/dialogs/input.d.ts +1 -1
  185. package/dist/types/calls/dialogs/mediaSelect.d.ts +1 -1
  186. package/dist/types/calls/dialogs/signature.d.ts +1 -1
  187. package/dist/types/components/App.d.ts +5 -0
  188. package/dist/types/components/Button.d.ts +8 -0
  189. package/dist/types/components/ChaynsProvider.d.ts +1 -1
  190. package/dist/types/components/ChaynsProviderExposed.d.ts +13 -0
  191. package/dist/types/components/Title.d.ts +3 -0
  192. package/dist/types/components/WaitUntil.d.ts +1 -1
  193. package/dist/types/components/withCompatMode.d.ts +1 -1
  194. package/dist/types/hooks/useAccessToken.d.ts +1 -1
  195. package/dist/types/host/ChaynsHost.d.ts +2 -1
  196. package/dist/types/host/{module/PagemakerFrame.d.ts → HostIframe.d.ts} +5 -7
  197. package/dist/types/host/iframe/HostIframe.d.ts +1 -1
  198. package/dist/types/host/module/ModuleHost.d.ts +2 -2
  199. package/dist/types/index.example.d.ts +0 -0
  200. package/dist/types/types/IChaynsReact.d.ts +14 -14
  201. package/package.json +1 -1
  202. package/dist/cjs/calls/dialogs/utils/environment.js +0 -10
  203. package/dist/esm/calls/dialogs/utils/environment.js +0 -3
  204. package/dist/esm/host/module/PagemakerFrame.js +0 -97
  205. package/dist/types/calls/dialogs/utils/environment.d.ts +0 -3
@@ -1,22 +1,59 @@
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
+
1
5
  import { buttonText, buttonType, dialogAction } from './chaynsDialog';
2
6
  import { open } from './open';
3
7
  import { getAccessToken, getUser, login } from "../index";
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);
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);
22
59
  }
@@ -1,12 +1,12 @@
1
1
  import { invokeDialogCall } from "../index";
2
2
  export function open(json) {
3
- return new Promise((resolve, reject) => {
3
+ return new Promise(function (resolve, reject) {
4
4
  invokeDialogCall({
5
5
  action: 184,
6
6
  value: {
7
7
  'dialogContent': json
8
8
  }
9
- }, e => {
9
+ }, function (e) {
10
10
  resolve(e);
11
11
  });
12
12
  });
@@ -2,9 +2,10 @@ 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
- const list = [];
6
- for (let i = 0, l = config.list.length; i < l; i++) {
7
- const item = config.list[i];
5
+ var list = [];
6
+
7
+ for (var i = 0, l = config.list.length; i < l; i++) {
8
+ var item = config.list[i];
8
9
  list.push({
9
10
  name: item.name,
10
11
  'value': isPresent(item.value) ? item.value : item.name,
@@ -15,9 +16,11 @@ export function select(config) {
15
16
  'url': item.url
16
17
  });
17
18
  }
19
+
18
20
  if (config.list.length === 0) {
19
21
  return Promise.reject(new Error('Invalid Parameters'));
20
22
  }
23
+
21
24
  if (!config.buttons || !Array.isArray(config.buttons)) {
22
25
  config.buttons = [{
23
26
  'text': buttonText.OK,
@@ -27,6 +30,7 @@ export function select(config) {
27
30
  'buttonType': buttonType.CANCEL
28
31
  }];
29
32
  }
33
+
30
34
  return open({
31
35
  'callType': dialogAction.SELECT,
32
36
  'title': config.title || '',
@@ -38,10 +42,10 @@ export function select(config) {
38
42
  'type': config.type,
39
43
  'preventCloseOnClick': !!config.preventCloseOnClick,
40
44
  'selectAllButton': config.selectAllButton,
41
- list
45
+ list: list
42
46
  });
43
47
  }
44
- export const selectType = {
48
+ export var selectType = {
45
49
  'DEFAULT': 0,
46
50
  'ICON': 1
47
51
  };
@@ -2,6 +2,7 @@ import { buttonText, buttonType, dialogAction } from './chaynsDialog';
2
2
  import { open } from './open';
3
3
  export function signature(dialog) {
4
4
  if (!dialog) dialog = {};
5
+
5
6
  if (!dialog.buttons || !Array.isArray(dialog.buttons)) {
6
7
  dialog.buttons = [];
7
8
  dialog.buttons.push({
@@ -13,6 +14,7 @@ export function signature(dialog) {
13
14
  'buttonType': buttonType.NEGATIVE
14
15
  });
15
16
  }
17
+
16
18
  dialog.callType = dialogAction.SIGNATURE;
17
19
  return open(dialog);
18
20
  }
@@ -1,13 +1,18 @@
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
+
1
7
  import { getCallbackName } from "./utils/callback";
2
8
  import { invokeDialogCall } from "../index";
3
9
  export function toast() {
4
- let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
5
- const callbackName = 'toastCallback';
10
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11
+ var callbackName = 'toastCallback';
6
12
  return invokeDialogCall({
7
13
  action: 276,
8
- value: {
9
- 'callback': getCallbackName(callbackName),
10
- ...config
11
- }
14
+ value: _objectSpread({
15
+ 'callback': getCallbackName(callbackName)
16
+ }, config)
12
17
  });
13
18
  }
@@ -1,7 +1,9 @@
1
1
  export function getCallbackName(fnName) {
2
- let framePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
2
+ var framePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
3
+
3
4
  if (framePrefix !== '') {
4
- return `window._chaynsCallbacks.${framePrefix}.${fnName}`;
5
+ return "window._chaynsCallbacks.".concat(framePrefix, ".").concat(fnName);
5
6
  }
6
- return `window._chaynsCallbacks.${fnName}`;
7
+
8
+ return "window._chaynsCallbacks.".concat(fnName);
7
9
  }
@@ -1,5 +1,7 @@
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
+
1
3
  export function isObject(value) {
2
- return value !== null && typeof value === 'object';
4
+ return value !== null && _typeof(value) === 'object';
3
5
  }
4
6
  export function isNumber(value) {
5
7
  return typeof value === 'number' && !isNaN(value);
@@ -1,33 +1,93 @@
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
- };
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
+
33
93
  export default getUserInfo;