@vasanthcambium/marketplace-auth 0.1.0 → 0.1.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.
@@ -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":"AACA,OAAO,KAAK,EAAE,SAAS,EAA4B,MAAM,OAAO,CAAC;AAIjE,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,108 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { useSession } from './useSession.js';
4
+ import { SessionExpiredError } from '../shared/errors.js';
5
+ /**
6
+ * Renders children only when a valid session exists.
7
+ * Shows a loading screen while the session check is in flight.
8
+ * Shows an auth screen (or custom fallback) when unauthenticated.
9
+ */
10
+ export function SessionGate({ children, fallback }) {
11
+ const { session, isReady, error } = useSession();
12
+ if (!isReady)
13
+ return _jsx(Screen, { children: _jsx("p", { style: styles.muted, children: "Loading\u2026" }) });
14
+ if (session)
15
+ return _jsx(_Fragment, { children: children });
16
+ if (fallback)
17
+ return _jsx(_Fragment, { children: fallback });
18
+ return _jsx(AuthScreen, { error: error });
19
+ }
20
+ function AuthScreen({ error }) {
21
+ const isDev = import.meta.env.DEV;
22
+ if (error instanceof SessionExpiredError) {
23
+ 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." })] }));
24
+ }
25
+ if (isDev)
26
+ return _jsx(DevLoginForm, {});
27
+ 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." })] }));
28
+ }
29
+ function DevLoginForm() {
30
+ const [clientId, setClientId] = useState('');
31
+ const [clientSecret, setClientSecret] = useState('');
32
+ const [busy, setBusy] = useState(false);
33
+ const [err, setErr] = useState(null);
34
+ async function handleSubmit(e) {
35
+ e.preventDefault();
36
+ setBusy(true);
37
+ setErr(null);
38
+ try {
39
+ const res = await fetch('/api/__dev-auth__', {
40
+ method: 'POST',
41
+ headers: { 'content-type': 'application/json' },
42
+ body: JSON.stringify({ clientId, clientSecret }),
43
+ });
44
+ if (!res.ok) {
45
+ const j = await res.json().catch(() => ({}));
46
+ setErr(j.error ?? `Server error (${res.status})`);
47
+ setBusy(false);
48
+ return;
49
+ }
50
+ window.location.reload();
51
+ }
52
+ catch (ex) {
53
+ setErr(String(ex));
54
+ setBusy(false);
55
+ }
56
+ }
57
+ return (_jsxs(Screen, { children: [_jsx("div", { style: styles.devBadge, children: "DEV MODE" }), _jsx("h1", { style: styles.heading, children: "Connect to cnMaestro" }), _jsx("p", { style: styles.body, children: "Enter your NBI API credentials to start the local dev session." }), _jsxs("form", { onSubmit: handleSubmit, style: styles.form, children: [_jsxs("label", { style: styles.label, children: ["Client ID", _jsx("input", { style: styles.input, type: "text", value: clientId, onChange: (e) => setClientId(e.target.value), placeholder: "your-client-id", required: true, autoFocus: true })] }), _jsxs("label", { style: styles.label, children: ["Client Secret", _jsx("input", { style: styles.input, type: "password", value: clientSecret, onChange: (e) => setClientSecret(e.target.value), placeholder: "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022", autoComplete: "off", required: true })] }), err && _jsx("p", { style: styles.formError, children: err }), _jsx("button", { type: "submit", style: styles.button, disabled: busy, children: busy ? 'Connecting…' : 'Connect' })] })] }));
58
+ }
59
+ function Screen({ children }) {
60
+ return (_jsx("div", { style: styles.screen, children: _jsx("div", { style: styles.card, children: children }) }));
61
+ }
62
+ const styles = {
63
+ screen: {
64
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
65
+ height: '100vh', background: '#f4f6f9',
66
+ fontFamily: 'Arial, Helvetica, sans-serif',
67
+ },
68
+ card: {
69
+ background: '#ffffff', borderRadius: '8px',
70
+ boxShadow: '0 2px 12px rgba(0,0,0,0.10)',
71
+ padding: '2.5rem 3rem', maxWidth: '480px', width: '100%',
72
+ },
73
+ devBadge: {
74
+ display: 'inline-block', background: '#D9027D', color: '#fff',
75
+ borderRadius: '4px', padding: '0.15rem 0.5rem',
76
+ fontSize: '0.75rem', fontWeight: 700, letterSpacing: '0.06em',
77
+ marginBottom: '0.75rem',
78
+ },
79
+ heading: {
80
+ margin: '0 0 0.75rem', color: '#003A70', fontSize: '1.4rem',
81
+ },
82
+ body: {
83
+ margin: '0 0 1.5rem', color: '#374151', lineHeight: 1.5,
84
+ },
85
+ muted: { color: '#6b7280' },
86
+ form: {
87
+ display: 'flex', flexDirection: 'column', gap: '1rem',
88
+ },
89
+ label: {
90
+ display: 'flex', flexDirection: 'column', gap: '0.35rem',
91
+ fontSize: '0.875rem', fontWeight: 600, color: '#374151',
92
+ },
93
+ input: {
94
+ border: '1px solid #d2d6dc', borderRadius: '6px',
95
+ padding: '0.5rem 0.75rem', fontSize: '0.9rem',
96
+ fontFamily: 'inherit', outline: 'none',
97
+ },
98
+ button: {
99
+ background: '#003A70', color: '#ffffff', border: 0,
100
+ borderRadius: '6px', padding: '0.6rem 1.25rem',
101
+ fontSize: '0.95rem', fontFamily: 'inherit',
102
+ cursor: 'pointer', fontWeight: 600, marginTop: '0.25rem',
103
+ },
104
+ formError: {
105
+ margin: 0, color: '#D9027D', fontSize: '0.875rem',
106
+ },
107
+ };
108
+ //# sourceMappingURL=SessionGate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionGate.js","sourceRoot":"","sources":["../../src/react/SessionGate.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAQ1D;;;;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,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,EAAE,MAAM;KACrC;IAClB,KAAK,EAAE;QACL,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS;QACxD,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS;KACvC;IAClB,KAAK,EAAE;QACL,MAAM,EAAE,mBAAmB,EAAE,YAAY,EAAE,KAAK;QAChD,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ;QAC7C,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM;KACtB;IAClB,MAAM,EAAE;QACN,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;QAClD,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,gBAAgB;QAC9C,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS;QAC1C,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS;KACxC;IAClB,SAAS,EAAE;QACT,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU;KACjC;CACqB,CAAC"}
@@ -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;AAEtD,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,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"}
@@ -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
@@ -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;AAGtD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vasanthcambium/marketplace-auth",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Frontend auth + NBI client for MarketApps Platform apps. Browser fetch wrapper and React hooks.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {