@nibssplc/cams-sdk-react 0.0.1-beta.16 → 0.0.1-beta.17

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.
@@ -1,6 +1,13 @@
1
- import React from 'react';
2
- export interface CAMSProviderProps {
3
- children: React.ReactNode;
1
+ import { ReactNode } from 'react';
2
+ import { CAMSConfig } from '@nibssplc/cams-sdk';
3
+ import { UseCAMSAuthReturn, UseCAMSAuthOptions } from '../hooks/useCAMSAuth';
4
+ interface CAMSContextValue extends UseCAMSAuthReturn {
5
+ defaultConfig?: Partial<CAMSConfig>;
4
6
  }
5
- export declare function CAMSProvider({ children }: CAMSProviderProps): import("react/jsx-runtime").JSX.Element;
6
- export declare function useCAMSContext(): any;
7
+ export interface CAMSProviderProps extends UseCAMSAuthOptions {
8
+ children: ReactNode;
9
+ defaultConfig?: Partial<CAMSConfig>;
10
+ }
11
+ export declare function CAMSProvider({ children, defaultConfig, ...authOptions }: CAMSProviderProps): import("react/jsx-runtime").JSX.Element;
12
+ export declare function useCAMSContext(): CAMSContextValue;
13
+ export {};
package/dist/index.cjs.js CHANGED
@@ -39,6 +39,29 @@ PERFORMANCE OF THIS SOFTWARE.
39
39
  /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
40
40
 
41
41
 
42
+ var __assign = function() {
43
+ __assign = Object.assign || function __assign(t) {
44
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
45
+ s = arguments[i];
46
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
47
+ }
48
+ return t;
49
+ };
50
+ return __assign.apply(this, arguments);
51
+ };
52
+
53
+ function __rest(s, e) {
54
+ var t = {};
55
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
56
+ t[p] = s[p];
57
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
58
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
59
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
60
+ t[p[i]] = s[p[i]];
61
+ }
62
+ return t;
63
+ }
64
+
42
65
  function __awaiter(thisArg, _arguments, P, generator) {
43
66
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
44
67
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -18183,20 +18206,30 @@ if (process.env.NODE_ENV === 'production') {
18183
18206
 
18184
18207
  var jsxRuntimeExports = jsxRuntime.exports;
18185
18208
 
18209
+ var CAMSContext = React__default.createContext(null);
18186
18210
  function CAMSProvider(_a) {
18187
- var children = _a.children;
18188
- if (typeof window === 'undefined') {
18211
+ var children = _a.children, defaultConfig = _a.defaultConfig, authOptions = __rest(_a, ["children", "defaultConfig"]);
18212
+ var _b = React__default.useState(false), mounted = _b[0], setMounted = _b[1];
18213
+ React__default.useEffect(function () {
18214
+ setMounted(true);
18215
+ }, []);
18216
+ if (!mounted) {
18189
18217
  return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
18190
18218
  }
18191
- var ClientProvider = require('./CAMSProvider.client').CAMSProvider;
18192
- return jsxRuntimeExports.jsx(ClientProvider, { children: children });
18219
+ return jsxRuntimeExports.jsx(CAMSProviderInner, __assign({ defaultConfig: defaultConfig }, authOptions, { children: children }));
18220
+ }
18221
+ function CAMSProviderInner(_a) {
18222
+ var children = _a.children, defaultConfig = _a.defaultConfig, authOptions = __rest(_a, ["children", "defaultConfig"]);
18223
+ var auth = useCAMSAuth(authOptions);
18224
+ var value = React__default.useMemo(function () { return (__assign(__assign({}, auth), { defaultConfig: defaultConfig })); }, [auth, defaultConfig]);
18225
+ return (jsxRuntimeExports.jsx(CAMSContext.Provider, { value: value, children: children }));
18193
18226
  }
18194
18227
  function useCAMSContext() {
18195
- if (typeof window === 'undefined') {
18196
- throw new Error('useCAMSContext can only be used on the client side');
18228
+ var context = React__default.useContext(CAMSContext);
18229
+ if (!context) {
18230
+ throw new Error('useCAMSContext must be used within a CAMSProvider');
18197
18231
  }
18198
- var useClientContext = require('./CAMSProvider.client').useCAMSContext;
18199
- return useClientContext();
18232
+ return context;
18200
18233
  }
18201
18234
 
18202
18235
  function ProtectedRoute(_a) {