@vasanthcambium/marketplace-auth 0.1.0 → 0.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.
- package/dist/react/SessionGate.d.ts +13 -0
- package/dist/react/SessionGate.d.ts.map +1 -0
- package/dist/react/SessionGate.js +67 -0
- package/dist/react/SessionGate.js.map +1 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface SessionGateProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
/** Custom fallback rendered when the user is not authenticated. */
|
|
5
|
+
fallback?: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Renders children only when a valid session exists.
|
|
9
|
+
* Shows a loading screen while the session check is in flight.
|
|
10
|
+
* Shows an auth screen (or custom fallback) when unauthenticated.
|
|
11
|
+
*/
|
|
12
|
+
export declare function SessionGate({ children, fallback }: SessionGateProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
//# sourceMappingURL=SessionGate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionGate.d.ts","sourceRoot":"","sources":["../../src/react/SessionGate.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,SAAS,CAAC;IACpB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,gBAAgB,2CAUnE"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useSession } from './useSession.js';
|
|
3
|
+
import { BridgeHttpError, SessionExpiredError } from '../shared/errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* Renders children only when a valid session exists.
|
|
6
|
+
* Shows a loading screen while the session check is in flight.
|
|
7
|
+
* Shows an auth screen (or custom fallback) when unauthenticated.
|
|
8
|
+
*/
|
|
9
|
+
export function SessionGate({ children, fallback }) {
|
|
10
|
+
const { session, isReady, error } = useSession();
|
|
11
|
+
if (!isReady)
|
|
12
|
+
return _jsx(Screen, { children: _jsx("p", { style: styles.muted, children: "Loading\u2026" }) });
|
|
13
|
+
if (session)
|
|
14
|
+
return _jsx(_Fragment, { children: children });
|
|
15
|
+
if (fallback)
|
|
16
|
+
return _jsx(_Fragment, { children: fallback });
|
|
17
|
+
return _jsx(AuthScreen, { error: error });
|
|
18
|
+
}
|
|
19
|
+
function AuthScreen({ error }) {
|
|
20
|
+
const isDev = import.meta.env.DEV;
|
|
21
|
+
if (error instanceof SessionExpiredError) {
|
|
22
|
+
return (_jsxs(Screen, { children: [_jsx("h1", { style: styles.heading, children: "Session Expired" }), _jsx("p", { style: styles.body, children: "Your session has expired. Please re-launch this app from cnMaestro." })] }));
|
|
23
|
+
}
|
|
24
|
+
if (isDev) {
|
|
25
|
+
const status = error instanceof BridgeHttpError ? error.status : null;
|
|
26
|
+
return (_jsxs(Screen, { children: [_jsx("div", { style: styles.devBadge, children: "DEV MODE" }), _jsx("h1", { style: styles.heading, children: "NBI credentials not configured" }), _jsx("p", { style: styles.body, children: status === 502
|
|
27
|
+
? 'The dev proxy could not authenticate — credentials are missing or wrong.'
|
|
28
|
+
: `Could not reach the API${status ? ` (HTTP ${status})` : ''}.` }), _jsxs("ol", { style: styles.list, children: [_jsxs("li", { children: ["Copy ", _jsx("code", { style: styles.code, children: ".env.development.example" }), " \u2192 ", _jsx("code", { style: styles.code, children: ".env.development" })] }), _jsxs("li", { children: ["Fill in ", _jsx("code", { style: styles.code, children: "NBI_CLIENT_ID" }), " and ", _jsx("code", { style: styles.code, children: "NBI_CLIENT_SECRET" }), " from your cnMaestro tenant (Settings \u2192 API Access)"] }), _jsx("li", { children: "Restart the dev server" })] })] }));
|
|
29
|
+
}
|
|
30
|
+
return (_jsxs(Screen, { children: [_jsx("h1", { style: styles.heading, children: "Not Authenticated" }), _jsx("p", { style: styles.body, children: "Please launch this app from the cnMaestro marketplace." })] }));
|
|
31
|
+
}
|
|
32
|
+
function Screen({ children }) {
|
|
33
|
+
return (_jsx("div", { style: styles.screen, children: _jsx("div", { style: styles.card, children: children }) }));
|
|
34
|
+
}
|
|
35
|
+
const styles = {
|
|
36
|
+
screen: {
|
|
37
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
38
|
+
height: '100vh', background: '#f4f6f9',
|
|
39
|
+
fontFamily: 'Arial, Helvetica, sans-serif',
|
|
40
|
+
},
|
|
41
|
+
card: {
|
|
42
|
+
background: '#ffffff', borderRadius: '8px',
|
|
43
|
+
boxShadow: '0 2px 12px rgba(0,0,0,0.10)',
|
|
44
|
+
padding: '2.5rem 3rem', maxWidth: '480px', width: '100%',
|
|
45
|
+
},
|
|
46
|
+
devBadge: {
|
|
47
|
+
display: 'inline-block', background: '#D9027D', color: '#fff',
|
|
48
|
+
borderRadius: '4px', padding: '0.15rem 0.5rem',
|
|
49
|
+
fontSize: '0.75rem', fontWeight: 700, letterSpacing: '0.06em',
|
|
50
|
+
marginBottom: '0.75rem',
|
|
51
|
+
},
|
|
52
|
+
heading: {
|
|
53
|
+
margin: '0 0 0.75rem', color: '#003A70', fontSize: '1.4rem',
|
|
54
|
+
},
|
|
55
|
+
body: {
|
|
56
|
+
margin: '0 0 1rem', color: '#374151', lineHeight: 1.5,
|
|
57
|
+
},
|
|
58
|
+
muted: { color: '#6b7280' },
|
|
59
|
+
list: {
|
|
60
|
+
margin: '0', paddingLeft: '1.25rem', color: '#374151', lineHeight: 2,
|
|
61
|
+
},
|
|
62
|
+
code: {
|
|
63
|
+
background: '#f4f6f9', borderRadius: '3px',
|
|
64
|
+
padding: '0.1rem 0.35rem', fontSize: '0.875em', fontFamily: 'monospace',
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=SessionGate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionGate.js","sourceRoot":"","sources":["../../src/react/SessionGate.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAQ3E;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAoB;IAClE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,UAAU,EAAE,CAAC;IAEjD,IAAI,CAAC,OAAO;QAAE,OAAO,KAAC,MAAM,cAAC,YAAG,KAAK,EAAE,MAAM,CAAC,KAAK,8BAAc,GAAS,CAAC;IAE3E,IAAI,OAAO;QAAE,OAAO,4BAAG,QAAQ,GAAI,CAAC;IAEpC,IAAI,QAAQ;QAAE,OAAO,4BAAG,QAAQ,GAAI,CAAC;IAErC,OAAO,KAAC,UAAU,IAAC,KAAK,EAAE,KAAK,GAAI,CAAC;AACtC,CAAC;AAED,SAAS,UAAU,CAAC,EAAE,KAAK,EAA2B;IACpD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAElC,IAAI,KAAK,YAAY,mBAAmB,EAAE,CAAC;QACzC,OAAO,CACL,MAAC,MAAM,eACL,aAAI,KAAK,EAAE,MAAM,CAAC,OAAO,gCAAsB,EAC/C,YAAG,KAAK,EAAE,MAAM,CAAC,IAAI,oFAAyE,IACvF,CACV,CAAC;IACJ,CAAC;IAED,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,MAAM,GAAG,KAAK,YAAY,eAAe,C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,UAAU,EAAE,8BAA8B;KACpB;IACxB,IAAI,EAAE;QACJ,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK;QAC1C,SAAS,EAAE,6BAA6B;QACxC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM;KAClC;IACxB,QAAQ,EAAE;QACR,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM;QAC7D,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,gBAAgB;QAC9C,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,EAAE,QAAQ;QAC7D,YAAY,EAAE,SAAS;KACD;IACxB,OAAO,EAAE;QACP,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ;KACrC;IACxB,IAAI,EAAE;QACJ,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG;KAC/B;IACxB,KAAK,EAAE,EAAE,KAAK,EAAE,SAAS,EAAyB;IAClD,IAAI,EAAE;QACJ,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;KAC9C;IACxB,IAAI,EAAE;QACJ,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK;QAC1C,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW;KACjD;CACqB,CAAC"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export { useSession } from './useSession.js';
|
|
|
8
8
|
export { useNBI } from './useNBI.js';
|
|
9
9
|
export { useNBIMutation } from './useNBIMutation.js';
|
|
10
10
|
export { useAccount, useUser } from './useAccount.js';
|
|
11
|
+
export { SessionGate } from './SessionGate.js';
|
|
11
12
|
export type { AppProviderProps } from './AppProvider.js';
|
|
13
|
+
export type { SessionGateProps } from './SessionGate.js';
|
|
12
14
|
export { BridgeHttpError, SessionExpiredError } from '../shared/errors.js';
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/react/index.js
CHANGED
|
@@ -8,5 +8,6 @@ export { useSession } from './useSession.js';
|
|
|
8
8
|
export { useNBI } from './useNBI.js';
|
|
9
9
|
export { useNBIMutation } from './useNBIMutation.js';
|
|
10
10
|
export { useAccount, useUser } from './useAccount.js';
|
|
11
|
+
export { SessionGate } from './SessionGate.js';
|
|
11
12
|
export { BridgeHttpError, SessionExpiredError } from '../shared/errors.js';
|
|
12
13
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/package.json
CHANGED