teraprox-core-sdk 0.2.0 → 0.3.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/chunk-N7KKTEAH.mjs +190 -0
- package/dist/dev.d.mts +39 -0
- package/dist/dev.d.ts +39 -0
- package/dist/dev.js +470 -0
- package/dist/dev.mjs +442 -0
- package/dist/federation-BANKXvQ5.d.mts +254 -0
- package/dist/federation-BANKXvQ5.d.ts +254 -0
- package/dist/federation.d.mts +3 -0
- package/dist/federation.d.ts +3 -0
- package/dist/federation.js +230 -0
- package/dist/federation.mjs +12 -0
- package/dist/index.d.mts +115 -56
- package/dist/index.d.ts +115 -56
- package/dist/index.js +542 -38
- package/dist/index.mjs +341 -40
- package/package.json +18 -3
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// src/context/CoreServiceContext.ts
|
|
2
|
+
import { createContext } from "react";
|
|
3
|
+
var CoreServiceContext = createContext(null);
|
|
4
|
+
|
|
5
|
+
// src/federation/FederatedBridge.tsx
|
|
6
|
+
import { useEffect } from "react";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
function FederatedBridge({ coreService, children }) {
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (typeof window === "undefined") return;
|
|
11
|
+
window.__TERAPROX_HOSTED_BY_CORE__ = true;
|
|
12
|
+
return () => {
|
|
13
|
+
;
|
|
14
|
+
window.__TERAPROX_HOSTED_BY_CORE__ = false;
|
|
15
|
+
};
|
|
16
|
+
}, []);
|
|
17
|
+
return /* @__PURE__ */ jsx(CoreServiceContext.Provider, { value: coreService, children });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/federation/createReducersBundle.ts
|
|
21
|
+
function createReducersBundle(config) {
|
|
22
|
+
const { reducers, contextMap, defaults = [] } = config;
|
|
23
|
+
const allKeys = Object.keys(reducers);
|
|
24
|
+
const getReducerKeysByContext = (context) => {
|
|
25
|
+
const contextKeys = contextMap[context];
|
|
26
|
+
if (!contextKeys) return allKeys;
|
|
27
|
+
return [.../* @__PURE__ */ new Set([...defaults, ...contextKeys])];
|
|
28
|
+
};
|
|
29
|
+
const getReducersForKeys = async (keys = []) => {
|
|
30
|
+
const uniqueKeys = [...new Set(keys)].filter((key) => !!reducers[key]);
|
|
31
|
+
const loaded = await Promise.all(
|
|
32
|
+
uniqueKeys.map(async (key) => {
|
|
33
|
+
const module = await reducers[key]();
|
|
34
|
+
return [key, module.default || module];
|
|
35
|
+
})
|
|
36
|
+
);
|
|
37
|
+
return Object.fromEntries(loaded);
|
|
38
|
+
};
|
|
39
|
+
const getReducersForModule = async ({
|
|
40
|
+
context
|
|
41
|
+
} = {}) => {
|
|
42
|
+
const keys = getReducerKeysByContext(context || "");
|
|
43
|
+
return getReducersForKeys(keys);
|
|
44
|
+
};
|
|
45
|
+
const loadAllReducers = () => getReducersForKeys(allKeys);
|
|
46
|
+
return {
|
|
47
|
+
getReducerKeysByContext,
|
|
48
|
+
getReducersForKeys,
|
|
49
|
+
getReducersForModule,
|
|
50
|
+
loadAllReducers,
|
|
51
|
+
baseReducers: {}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/federation/StandaloneProvider.tsx
|
|
56
|
+
import { useMemo, useCallback, useState, useEffect as useEffect2, useRef } from "react";
|
|
57
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
58
|
+
function StandaloneProvider({ createController, addToast, firebaseConfig, tenant, children }) {
|
|
59
|
+
const [subscriptions] = useState([]);
|
|
60
|
+
const subscriptionsRef = useRef(subscriptions);
|
|
61
|
+
subscriptionsRef.current = subscriptions;
|
|
62
|
+
const toast = useMemo(
|
|
63
|
+
() => ({
|
|
64
|
+
success: (msg, opts) => addToast(msg, { appearance: "success", autoDismiss: true, ...opts }),
|
|
65
|
+
warning: (msg, opts) => addToast(msg, { appearance: "warning", autoDismiss: true, ...opts }),
|
|
66
|
+
error: (msg, opts) => addToast(msg, { appearance: "error", autoDismiss: true, ...opts }),
|
|
67
|
+
info: (msg, opts) => addToast(msg, { appearance: "info", autoDismiss: true, ...opts })
|
|
68
|
+
}),
|
|
69
|
+
[addToast]
|
|
70
|
+
);
|
|
71
|
+
const subscribe = useCallback(
|
|
72
|
+
(mo) => {
|
|
73
|
+
subscriptions.push(mo);
|
|
74
|
+
},
|
|
75
|
+
[subscriptions]
|
|
76
|
+
);
|
|
77
|
+
const unsubscribe = useCallback(
|
|
78
|
+
(mo) => {
|
|
79
|
+
const idx = subscriptions.findIndex(
|
|
80
|
+
(s) => s.context === mo.context && s.location === mo.location
|
|
81
|
+
);
|
|
82
|
+
if (idx >= 0) subscriptions.splice(idx, 1);
|
|
83
|
+
},
|
|
84
|
+
[subscriptions]
|
|
85
|
+
);
|
|
86
|
+
useEffect2(() => {
|
|
87
|
+
if (!firebaseConfig || !tenant || Object.keys(firebaseConfig).length === 0) return;
|
|
88
|
+
let cleanup;
|
|
89
|
+
(async () => {
|
|
90
|
+
try {
|
|
91
|
+
const { initializeApp, getApps } = await import("firebase/app");
|
|
92
|
+
const { getDatabase, ref, onChildAdded, off } = await import("firebase/database");
|
|
93
|
+
if (!getApps().length) {
|
|
94
|
+
initializeApp(firebaseConfig);
|
|
95
|
+
}
|
|
96
|
+
const db = getDatabase();
|
|
97
|
+
const moRef = ref(db, `${tenant}/matchingObjects`);
|
|
98
|
+
const unsub = onChildAdded(moRef, (snapshot) => {
|
|
99
|
+
const data = snapshot.val();
|
|
100
|
+
if (!data) return;
|
|
101
|
+
const items = Array.isArray(data) ? data : [data];
|
|
102
|
+
for (const mo of items) {
|
|
103
|
+
if (typeof mo !== "object") continue;
|
|
104
|
+
const subs = subscriptionsRef.current || [];
|
|
105
|
+
for (const sub of subs) {
|
|
106
|
+
const sameContext = sub.context === mo.context;
|
|
107
|
+
const sameLocation = sub.location === mo.location || sub.location === "*" || mo.location === "*" || !sub.location || !mo.location;
|
|
108
|
+
if (sameContext && sameLocation && sub.refresher) {
|
|
109
|
+
try {
|
|
110
|
+
sub.refresher(mo.payload, () => {
|
|
111
|
+
});
|
|
112
|
+
} catch (e) {
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
cleanup = () => {
|
|
119
|
+
off(moRef, "child_added", unsub);
|
|
120
|
+
};
|
|
121
|
+
} catch (err) {
|
|
122
|
+
console.warn("[StandaloneProvider] Firebase RTDB listener failed \u2014 continuing without real-time:", err);
|
|
123
|
+
}
|
|
124
|
+
})();
|
|
125
|
+
return () => {
|
|
126
|
+
cleanup == null ? void 0 : cleanup();
|
|
127
|
+
};
|
|
128
|
+
}, [firebaseConfig, tenant]);
|
|
129
|
+
const value = useMemo(
|
|
130
|
+
() => ({
|
|
131
|
+
createController,
|
|
132
|
+
toast,
|
|
133
|
+
subscribe,
|
|
134
|
+
unsubscribe,
|
|
135
|
+
subscribeEvent: () => {
|
|
136
|
+
},
|
|
137
|
+
unsubscribeEvent: () => {
|
|
138
|
+
},
|
|
139
|
+
handleLogout: () => {
|
|
140
|
+
},
|
|
141
|
+
hostedByCore: false
|
|
142
|
+
}),
|
|
143
|
+
[createController, toast, subscribe, unsubscribe]
|
|
144
|
+
);
|
|
145
|
+
return /* @__PURE__ */ jsx2(CoreServiceContext.Provider, { value, children });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/federation/DevAutoLogin.tsx
|
|
149
|
+
import { useEffect as useEffect3 } from "react";
|
|
150
|
+
import { useDispatch, useSelector } from "react-redux";
|
|
151
|
+
import { Fragment, jsx as jsx3 } from "react/jsx-runtime";
|
|
152
|
+
var DEFAULT_DEV_USER = {
|
|
153
|
+
firstName: "Dev",
|
|
154
|
+
lastName: "User",
|
|
155
|
+
token: "dev-standalone-token",
|
|
156
|
+
email: "dev@teraprox.local",
|
|
157
|
+
id: "dev-user-id",
|
|
158
|
+
role: "admin",
|
|
159
|
+
user: "devuser",
|
|
160
|
+
userName: "devuser",
|
|
161
|
+
setor: "Desenvolvimento",
|
|
162
|
+
userSetor: { setorId: "dev-setor-id" },
|
|
163
|
+
companyName: "Dev Company",
|
|
164
|
+
companyId: "dev-company-id",
|
|
165
|
+
filters: []
|
|
166
|
+
};
|
|
167
|
+
function DevAutoLogin({ actions, devUser, children }) {
|
|
168
|
+
const dispatch = useDispatch();
|
|
169
|
+
const token = useSelector((state) => {
|
|
170
|
+
var _a;
|
|
171
|
+
return (_a = state.global) == null ? void 0 : _a.token;
|
|
172
|
+
});
|
|
173
|
+
const hostedByCore = typeof window !== "undefined" && window.__TERAPROX_HOSTED_BY_CORE__ === true;
|
|
174
|
+
useEffect3(() => {
|
|
175
|
+
if (process.env.NODE_ENV === "development" && !hostedByCore && !token) {
|
|
176
|
+
const user = { ...DEFAULT_DEV_USER, ...devUser };
|
|
177
|
+
dispatch(actions.setCompany(user.companyId));
|
|
178
|
+
dispatch(actions.logIn(user));
|
|
179
|
+
}
|
|
180
|
+
}, [dispatch, hostedByCore, token, actions, devUser]);
|
|
181
|
+
return /* @__PURE__ */ jsx3(Fragment, { children });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export {
|
|
185
|
+
CoreServiceContext,
|
|
186
|
+
FederatedBridge,
|
|
187
|
+
createReducersBundle,
|
|
188
|
+
StandaloneProvider,
|
|
189
|
+
DevAutoLogin
|
|
190
|
+
};
|
package/dist/dev.d.mts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface DevRoute {
|
|
4
|
+
/** Display label for the route */
|
|
5
|
+
label: string;
|
|
6
|
+
/** Route path (e.g., "/ordensDeServico") */
|
|
7
|
+
path: string;
|
|
8
|
+
/** Category for grouping (e.g., "Operação", "Cadastros") */
|
|
9
|
+
category?: string;
|
|
10
|
+
}
|
|
11
|
+
interface DevShellProps {
|
|
12
|
+
appName: string;
|
|
13
|
+
routes: DevRoute[];
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare function DevShell({ appName, routes, children }: DevShellProps): react_jsx_runtime.JSX.Element;
|
|
18
|
+
|
|
19
|
+
interface RouteConfigEntry {
|
|
20
|
+
configuration?: {
|
|
21
|
+
path?: string;
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
};
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
interface ServiceRouteConfig {
|
|
27
|
+
service?: string;
|
|
28
|
+
routes?: RouteConfigEntry[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Extracts DevRoute[] from the standard routesConfig format used by SGM/SGP.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* import { routesConfig } from '../models/routesConfig'
|
|
35
|
+
* const devRoutes = extractDevRoutes(routesConfig)
|
|
36
|
+
*/
|
|
37
|
+
declare function extractDevRoutes(routesConfig: ServiceRouteConfig[]): DevRoute[];
|
|
38
|
+
|
|
39
|
+
export { type DevRoute, DevShell, type DevShellProps, extractDevRoutes };
|
package/dist/dev.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface DevRoute {
|
|
4
|
+
/** Display label for the route */
|
|
5
|
+
label: string;
|
|
6
|
+
/** Route path (e.g., "/ordensDeServico") */
|
|
7
|
+
path: string;
|
|
8
|
+
/** Category for grouping (e.g., "Operação", "Cadastros") */
|
|
9
|
+
category?: string;
|
|
10
|
+
}
|
|
11
|
+
interface DevShellProps {
|
|
12
|
+
appName: string;
|
|
13
|
+
routes: DevRoute[];
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare function DevShell({ appName, routes, children }: DevShellProps): react_jsx_runtime.JSX.Element;
|
|
18
|
+
|
|
19
|
+
interface RouteConfigEntry {
|
|
20
|
+
configuration?: {
|
|
21
|
+
path?: string;
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
};
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
interface ServiceRouteConfig {
|
|
27
|
+
service?: string;
|
|
28
|
+
routes?: RouteConfigEntry[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Extracts DevRoute[] from the standard routesConfig format used by SGM/SGP.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* import { routesConfig } from '../models/routesConfig'
|
|
35
|
+
* const devRoutes = extractDevRoutes(routesConfig)
|
|
36
|
+
*/
|
|
37
|
+
declare function extractDevRoutes(routesConfig: ServiceRouteConfig[]): DevRoute[];
|
|
38
|
+
|
|
39
|
+
export { type DevRoute, DevShell, type DevShellProps, extractDevRoutes };
|