synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
76 lines (75 loc) • 2.33 kB
JavaScript
import { jsx as p } from "react/jsx-runtime";
import { SynapseErrorBoundary as u } from "../../components/error/ErrorBanner.js";
import { KeyFactory as d } from "../../synapse-queries/KeyFactory.js";
import { SynapseClient as l } from "@sage-bionetworks/synapse-client/SynapseClient";
import { createContext as C, useContext as m, useMemo as t } from "react";
import { getEndpoint as f, BackendDestinationEnum as h } from "../functions/getEndpoint.js";
const x = {
accessToken: void 0,
isAuthenticated: !1,
isInExperimentalMode: !1,
utcTime: !1,
withErrorBoundary: !1,
keyFactory: new d(void 0),
downloadCartPageUrl: "/DownloadCart",
peopleSearchPageUrl: "/PeopleSearch:",
appId: void 0,
synapseClient: new l()
}, o = C(x);
function g(n) {
const { children: r, synapseContext: e } = n, a = t(
() => new d(e?.accessToken),
[e?.accessToken]
), s = f(h.REPO_ENDPOINT), i = t(() => {
if (e?.synapseClient)
return e?.synapseClient;
const y = {
accessToken: e?.accessToken,
basePath: s
};
return new l(y);
}, [e?.synapseClient, e?.accessToken, s]), c = t(
() => ({
accessToken: e?.accessToken,
isAuthenticated: e?.isAuthenticated ?? !1,
isInExperimentalMode: e?.isInExperimentalMode ?? !1,
utcTime: e?.utcTime ?? !1,
withErrorBoundary: e?.withErrorBoundary ?? !1,
downloadCartPageUrl: e?.downloadCartPageUrl ?? "/DownloadCart",
peopleSearchPageUrl: e?.peopleSearchPageUrl ?? "/PeopleSearch:",
keyFactory: e?.keyFactory ?? a,
appId: e?.appId,
synapseClient: i
}),
[
e?.accessToken,
e?.isAuthenticated,
e?.downloadCartPageUrl,
e?.peopleSearchPageUrl,
e?.isInExperimentalMode,
e?.keyFactory,
e?.utcTime,
e?.withErrorBoundary,
e?.appId,
a,
i
]
);
return /* @__PURE__ */ p(o.Provider, { value: c, children: c?.withErrorBoundary ? /* @__PURE__ */ p(u, { children: r }) : r });
}
const v = o.Consumer;
function I() {
const n = m(o);
if (n === void 0)
throw new Error(
"useSynapseContext must be used within a SynapseContextProvider"
);
return n;
}
export {
o as SynapseContext,
v as SynapseContextConsumer,
g as SynapseContextProvider,
I as useSynapseContext
};
//# sourceMappingURL=SynapseContext.js.map