@ethisyscore/extension-runtime 1.30.0 → 1.31.0
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/plugin/index.cjs +42 -0
- package/dist/plugin/index.cjs.map +1 -1
- package/dist/plugin/index.d.cts +44 -1
- package/dist/plugin/index.d.ts +44 -1
- package/dist/plugin/index.js +41 -1
- package/dist/plugin/index.js.map +1 -1
- package/package.json +1 -1
package/dist/plugin/index.cjs
CHANGED
|
@@ -757,6 +757,46 @@ function useFrontendSessionToken(transport) {
|
|
|
757
757
|
return { token, isLoading, error };
|
|
758
758
|
}
|
|
759
759
|
|
|
760
|
+
// src/plugin/decodeJwtPayload.ts
|
|
761
|
+
function decodeJwtPayload(token) {
|
|
762
|
+
if (token === null || token === "") {
|
|
763
|
+
return {};
|
|
764
|
+
}
|
|
765
|
+
const segments = token.split(".");
|
|
766
|
+
if (segments.length < 3) {
|
|
767
|
+
return {};
|
|
768
|
+
}
|
|
769
|
+
const payloadSegment = segments[1];
|
|
770
|
+
try {
|
|
771
|
+
const base64 = payloadSegment.replace(/-/g, "+").replace(/_/g, "/");
|
|
772
|
+
const padded = base64 + "===".slice(0, (4 - base64.length % 4) % 4);
|
|
773
|
+
const json = atob(padded);
|
|
774
|
+
const parsed = JSON.parse(json);
|
|
775
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
776
|
+
return {};
|
|
777
|
+
}
|
|
778
|
+
return parsed;
|
|
779
|
+
} catch {
|
|
780
|
+
return {};
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
function useAuth(transport) {
|
|
784
|
+
const { token, isLoading, error } = useFrontendSessionToken(transport);
|
|
785
|
+
const { currentUserId, permissionSet } = react.useMemo(() => {
|
|
786
|
+
const claims = decodeJwtPayload(token);
|
|
787
|
+
const userId = (typeof claims["user_id"] === "string" && claims["user_id"] !== "" ? claims["user_id"] : null) ?? (typeof claims["sub"] === "string" && claims["sub"] !== "" ? claims["sub"] : null);
|
|
788
|
+
const permissionsRaw = typeof claims["permissions"] === "string" ? claims["permissions"] : "";
|
|
789
|
+
const set = permissionsRaw.length > 0 ? new Set(permissionsRaw.split(" ").filter((s) => s.length > 0)) : /* @__PURE__ */ new Set();
|
|
790
|
+
return { currentUserId: userId, permissionSet: set };
|
|
791
|
+
}, [token]);
|
|
792
|
+
return {
|
|
793
|
+
currentUserId,
|
|
794
|
+
hasPermission: (shortCode) => permissionSet.has(shortCode),
|
|
795
|
+
isLoading,
|
|
796
|
+
error
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
|
|
760
800
|
exports.BridgeClientContext = BridgeClientContext;
|
|
761
801
|
exports.ClientPushContext = ClientPushContext;
|
|
762
802
|
exports.ExtensionRuntimeProvider = ExtensionRuntimeProvider;
|
|
@@ -765,9 +805,11 @@ exports.PluginRealtimeContext = PluginRealtimeContext;
|
|
|
765
805
|
exports.createPortBridgeClient = createPortBridgeClient;
|
|
766
806
|
exports.createPortMcpTransport = createPortMcpTransport;
|
|
767
807
|
exports.createRemoteRoot = createRemoteRoot;
|
|
808
|
+
exports.decodeJwtPayload = decodeJwtPayload;
|
|
768
809
|
exports.defineDeclarativePlugin = defineDeclarativePlugin;
|
|
769
810
|
exports.defineEthisysPlugin = defineEthisysPlugin;
|
|
770
811
|
exports.unwrapItems = unwrapItems;
|
|
812
|
+
exports.useAuth = useAuth;
|
|
771
813
|
exports.useBridgeClient = useBridgeClient;
|
|
772
814
|
exports.useBridgeLocale = useBridgeLocale;
|
|
773
815
|
exports.useBridgeTheme = useBridgeTheme;
|