@ldo/solid-react 1.0.0-alpha.1 → 1.0.0-alpha.3
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/README.md +10 -10
- package/dist/SolidAuthContext.js.map +1 -1
- package/dist/UnauthenticatedSolidLdoProvider.js +1 -2
- package/dist/UnauthenticatedSolidLdoProvider.js.map +1 -1
- package/dist/createBrowserSolidReactMethods.d.ts +11 -0
- package/dist/createBrowserSolidReactMethods.js +79 -0
- package/dist/createBrowserSolidReactMethods.js.map +1 -0
- package/dist/defaultIntance.d.ts +5 -0
- package/dist/defaultIntance.js +10 -0
- package/dist/defaultIntance.js.map +1 -0
- package/dist/index.d.ts +2 -9
- package/dist/index.js +2 -11
- package/dist/index.js.map +1 -1
- package/dist/useRootContainerFor.d.ts +4 -0
- package/dist/useRootContainerFor.js +25 -0
- package/dist/useRootContainerFor.js.map +1 -0
- package/package.json +14 -13
- package/src/SolidAuthContext.ts +3 -0
- package/src/UnauthenticatedSolidLdoProvider.tsx +4 -2
- package/src/createBrowserSolidReactMethods.tsx +132 -0
- package/src/defaultIntance.ts +19 -0
- package/src/index.ts +2 -12
- package/src/useRootContainerFor.ts +46 -0
- package/src/BrowserSolidLdoProvider.tsx +0 -97
- package/src/SolidLdoProvider.tsx +0 -55
- package/src/useLdoMethods.ts +0 -84
- package/src/useMatchObject.ts +0 -21
- package/src/useMatchSubject.ts +0 -21
- package/src/useResource.ts +0 -114
- package/src/useRootContainer.ts +0 -31
- package/src/useSubject.ts +0 -30
- package/src/useSubscribeToResource.ts +0 -52
- package/src/util/TrackingProxyContext.ts +0 -61
- package/src/util/TrackingSetProxy.ts +0 -56
- package/src/util/TrackingSubjectProxy.ts +0 -43
- package/src/util/useTrackingProxy.ts +0 -55
package/README.md
CHANGED
|
@@ -115,18 +115,18 @@ export default App;
|
|
|
115
115
|
|
|
116
116
|
Providers
|
|
117
117
|
|
|
118
|
-
- [BrowserSolidLdoProvider](https://ldo.js.org/latest/api/
|
|
119
|
-
- [SolidLdoProvider](https://ldo.js.org/latest/api/
|
|
118
|
+
- [BrowserSolidLdoProvider](https://ldo.js.org/latest/api/react/BrowserSolidLdoProvider/)
|
|
119
|
+
- [SolidLdoProvider](https://ldo.js.org/latest/api/react/SolidLdoProvider/)
|
|
120
120
|
|
|
121
121
|
Hooks
|
|
122
|
-
- [useLdo](https://ldo.js.org/latest/api/
|
|
123
|
-
- [useResource](https://ldo.js.org/latest/api/
|
|
124
|
-
- [useRootContainer](https://ldo.js.org/latest/api/
|
|
125
|
-
- [useSolidAuth](https://ldo.js.org/latest/api/
|
|
126
|
-
- [useSubject](https://ldo.js.org/latest/api/
|
|
127
|
-
- [useMatchSubject](https://ldo.js.org/latest/api/
|
|
128
|
-
- [useMatchObject](https://ldo.js.org/latest/api/
|
|
129
|
-
- [useSubscribeToResource](https://ldo.js.org/latest/api/
|
|
122
|
+
- [useLdo](https://ldo.js.org/latest/api/react/useLdo/)
|
|
123
|
+
- [useResource](https://ldo.js.org/latest/api/react/useResource/)
|
|
124
|
+
- [useRootContainer](https://ldo.js.org/latest/api/react/useRootContainer/)
|
|
125
|
+
- [useSolidAuth](https://ldo.js.org/latest/api/react/useSolidAuth/)
|
|
126
|
+
- [useSubject](https://ldo.js.org/latest/api/react/useSubject/)
|
|
127
|
+
- [useMatchSubject](https://ldo.js.org/latest/api/react/useMatchSubject/)
|
|
128
|
+
- [useMatchObject](https://ldo.js.org/latest/api/react/useMatchSubject/)
|
|
129
|
+
- [useSubscribeToResource](https://ldo.js.org/latest/api/react/useMatchSubject/)
|
|
130
130
|
|
|
131
131
|
## Sponsorship
|
|
132
132
|
This project was made possible by a grant from NGI Zero Entrust via nlnet. Learn more on the [NLnet project page](https://nlnet.nl/project/SolidUsableApps/).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolidAuthContext.js","sourceRoot":"","sources":["../src/SolidAuthContext.ts"],"names":[],"mappings":";;;AAIA,iCAAkD;
|
|
1
|
+
{"version":3,"file":"SolidAuthContext.js","sourceRoot":"","sources":["../src/SolidAuthContext.ts"],"names":[],"mappings":";;;AAIA,iCAAkD;AAoBrC,QAAA,gBAAgB,GAAG,IAAA,qBAAa,EAAqB,SAAS,CAAC,CAAC;AAE7E,SAAgB,YAAY;IAC1B,OAAO,IAAA,kBAAU,EAAC,wBAAgB,CAAC,CAAC;AACtC,CAAC;AAFD,oCAEC"}
|
|
@@ -8,7 +8,6 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
8
8
|
const react_1 = require("react");
|
|
9
9
|
const SolidAuthContext_1 = require("./SolidAuthContext");
|
|
10
10
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
11
|
-
const SolidLdoProvider_1 = require("./SolidLdoProvider");
|
|
12
11
|
const DUMMY_SESSION = {
|
|
13
12
|
isLoggedIn: false,
|
|
14
13
|
webId: undefined,
|
|
@@ -35,7 +34,7 @@ const UnauthenticatedSolidLdoProvider = ({ children }) => {
|
|
|
35
34
|
ranInitialAuthCheck: true,
|
|
36
35
|
fetch: cross_fetch_1.default,
|
|
37
36
|
}), [login, logout, signUp]);
|
|
38
|
-
return ((0, jsx_runtime_1.jsx)(SolidAuthContext_1.SolidAuthContext.Provider, { value: solidAuthFunctions, children:
|
|
37
|
+
return ((0, jsx_runtime_1.jsx)(SolidAuthContext_1.SolidAuthContext.Provider, { value: solidAuthFunctions, children: children }));
|
|
39
38
|
};
|
|
40
39
|
exports.UnauthenticatedSolidLdoProvider = UnauthenticatedSolidLdoProvider;
|
|
41
40
|
//# sourceMappingURL=UnauthenticatedSolidLdoProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnauthenticatedSolidLdoProvider.js","sourceRoot":"","sources":["../src/UnauthenticatedSolidLdoProvider.tsx"],"names":[],"mappings":";;;;;;;AACA,iCAAoD;AAGpD,yDAAsD;AACtD,8DAAuC;
|
|
1
|
+
{"version":3,"file":"UnauthenticatedSolidLdo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CAAC,CAAC;AA7CW,QAAA,+BAA+B,mCA6C1C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useSolidAuth } from "./SolidAuthContext";
|
|
3
|
+
import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected";
|
|
4
|
+
import type { SolidConnectedPlugin } from "@ldo/connected-solid";
|
|
5
|
+
export declare function createBrowserSolidReactMethods(dataset: ConnectedLdoDataset<(SolidConnectedPlugin | ConnectedPlugin)[]>): {
|
|
6
|
+
BrowserSolidLdoProvider: React.FunctionComponent<{
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
}>;
|
|
9
|
+
useSolidAuth: typeof useSolidAuth;
|
|
10
|
+
useRootContainerFor: (uri?: import("@ldo/connected-solid").SolidContainerUri | import("@ldo/connected-solid").SolidLeafUri | undefined, options?: import("@ldo/react").UseResourceOptions<"solid"> | undefined) => import("@ldo/connected-solid").SolidContainer | undefined;
|
|
11
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBrowserSolidReactMethods = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const SolidAuthContext_1 = require("./SolidAuthContext");
|
|
7
|
+
const solid_client_authn_browser_1 = require("@inrupt/solid-client-authn-browser");
|
|
8
|
+
const useRootContainerFor_1 = require("./useRootContainerFor");
|
|
9
|
+
const react_2 = require("@ldo/react");
|
|
10
|
+
const PRE_REDIRECT_URI = "PRE_REDIRECT_URI";
|
|
11
|
+
function createBrowserSolidReactMethods(dataset) {
|
|
12
|
+
dataset.setContext("solid", { fetch: solid_client_authn_browser_1.fetch });
|
|
13
|
+
const BrowserSolidLdoProvider = ({ children, }) => {
|
|
14
|
+
const [session, setSession] = (0, react_1.useState)((0, solid_client_authn_browser_1.getDefaultSession)().info);
|
|
15
|
+
const [ranInitialAuthCheck, setRanInitialAuthCheck] = (0, react_1.useState)(false);
|
|
16
|
+
const runInitialAuthCheck = (0, react_1.useCallback)(async () => {
|
|
17
|
+
if (!window.localStorage.getItem(PRE_REDIRECT_URI)) {
|
|
18
|
+
window.localStorage.setItem(PRE_REDIRECT_URI, window.location.href);
|
|
19
|
+
}
|
|
20
|
+
await (0, solid_client_authn_browser_1.handleIncomingRedirect)({
|
|
21
|
+
restorePreviousSession: true,
|
|
22
|
+
});
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
setSession({ ...(0, solid_client_authn_browser_1.getDefaultSession)().info });
|
|
25
|
+
window.history.replaceState({}, "", window.localStorage.getItem(PRE_REDIRECT_URI));
|
|
26
|
+
window.localStorage.removeItem(PRE_REDIRECT_URI);
|
|
27
|
+
setRanInitialAuthCheck(true);
|
|
28
|
+
}, 0);
|
|
29
|
+
}, []);
|
|
30
|
+
const login = (0, react_1.useCallback)(async (issuer, options) => {
|
|
31
|
+
const cleanUrl = new URL(window.location.href);
|
|
32
|
+
cleanUrl.hash = "";
|
|
33
|
+
cleanUrl.search = "";
|
|
34
|
+
const fullOptions = {
|
|
35
|
+
redirectUrl: cleanUrl.toString(),
|
|
36
|
+
clientName: "Solid App",
|
|
37
|
+
oidcIssuer: issuer,
|
|
38
|
+
...options,
|
|
39
|
+
};
|
|
40
|
+
window.localStorage.setItem(PRE_REDIRECT_URI, window.location.href);
|
|
41
|
+
await (0, solid_client_authn_browser_1.login)(fullOptions);
|
|
42
|
+
setSession({ ...(0, solid_client_authn_browser_1.getDefaultSession)().info });
|
|
43
|
+
}, []);
|
|
44
|
+
const logout = (0, react_1.useCallback)(async () => {
|
|
45
|
+
await (0, solid_client_authn_browser_1.logout)();
|
|
46
|
+
setSession({ ...(0, solid_client_authn_browser_1.getDefaultSession)().info });
|
|
47
|
+
}, []);
|
|
48
|
+
const signUp = (0, react_1.useCallback)(async (issuer, options) => {
|
|
49
|
+
return login(issuer, { ...options, prompt: "create" });
|
|
50
|
+
}, [login]);
|
|
51
|
+
(0, react_1.useEffect)(() => {
|
|
52
|
+
runInitialAuthCheck();
|
|
53
|
+
}, []);
|
|
54
|
+
const solidAuthFunctions = (0, react_1.useMemo)(() => ({
|
|
55
|
+
runInitialAuthCheck,
|
|
56
|
+
login,
|
|
57
|
+
logout,
|
|
58
|
+
signUp,
|
|
59
|
+
session,
|
|
60
|
+
ranInitialAuthCheck,
|
|
61
|
+
fetch: solid_client_authn_browser_1.fetch,
|
|
62
|
+
}), [
|
|
63
|
+
login,
|
|
64
|
+
logout,
|
|
65
|
+
ranInitialAuthCheck,
|
|
66
|
+
runInitialAuthCheck,
|
|
67
|
+
session,
|
|
68
|
+
signUp,
|
|
69
|
+
]);
|
|
70
|
+
return ((0, jsx_runtime_1.jsx)(SolidAuthContext_1.SolidAuthContext.Provider, { value: solidAuthFunctions, children: children }));
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
BrowserSolidLdoProvider,
|
|
74
|
+
useSolidAuth: SolidAuthContext_1.useSolidAuth,
|
|
75
|
+
useRootContainerFor: (0, useRootContainerFor_1.createUseRootContainerFor)(dataset, (0, react_2.createUseResource)(dataset)),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.createBrowserSolidReactMethods = createBrowserSolidReactMethods;
|
|
79
|
+
//# sourceMappingURL=createBrowserSolidReactMethods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBrowserSolidReactMethods.js","sourceRoot":"","sources":["../src/createBrowserSolidReactMethods.tsx"],"names":[],"mappings":";;;;AAAA,iCAAyE;AAGzE,yDAAoE;AACpE,mFAM4C;AAG5C,+DAAkE;AAClE,sCAA+C;AAE/C,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAO5C,SAAgB,8BAA8B,CAC5C,OAAwE;IAExE,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,kCAAY,EAAE,CAAC,CAAC;I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mBAAmB;YACnB,OAAO;YACP,MAAM;SACP,CACF,CAAC;QAEF,OAAO,CACL,uBAAC,mCAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,kBAAkB,YACjD,QAAQ,GACiB,CAC7B,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,uBAAuB;QACvB,YAAY,EAAE,+BAAY;QAC1B,mBAAmB,EAAE,IAAA,+CAAyB,EAC5C,OAAsD,EACtD,IAAA,yBAAiB,EAAC,OAAiD,CAAC,CACrE;KACF,CAAC;AACJ,CAAC;AA5GD,wEA4GC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const dataset: import("packages/connected/dist").ConnectedLdoDataset<import("@ldo/connected-solid").SolidConnectedPlugin[]>, useLdo: () => import("@ldo/react").UseLdoMethods<import("@ldo/connected-solid").SolidConnectedPlugin[]>, useMatchObject: <Type extends import("packages/ldo/dist/util").LdoBase>(shapeType: import("packages/ldo/dist").ShapeType<Type>, subject?: string | import("packages/rdf-utils/dist").SubjectNode | null | undefined, predicate?: string | import("packages/rdf-utils/dist").PredicateNode | null | undefined, graph?: string | import("packages/rdf-utils/dist").GraphNode | null | undefined) => import("packages/jsonld-dataset-proxy/dist").LdSet<Type>, useMatchSubject: <Type_1 extends import("packages/ldo/dist/util").LdoBase>(shapeType: import("packages/ldo/dist").ShapeType<Type_1>, predicate?: string | import("packages/rdf-utils/dist").PredicateNode | null | undefined, object?: string | import("packages/rdf-utils/dist").ObjectNode | null | undefined, graph?: string | import("packages/rdf-utils/dist").GraphNode | null | undefined) => import("packages/jsonld-dataset-proxy/dist").LdSet<Type_1>, useResource: import("@ldo/react").useResourceType<import("@ldo/connected-solid").SolidConnectedPlugin[]>, useSubject: import("@ldo/react").useSubjectType, useSubscribeToResource: (...uris: string[]) => void;
|
|
3
|
+
export declare const BrowserSolidLdoProvider: import("react").FunctionComponent<{
|
|
4
|
+
children?: import("react").ReactNode;
|
|
5
|
+
}>, useSolidAuth: typeof import("./SolidAuthContext").useSolidAuth, useRootContainerFor: (uri?: import("@ldo/connected-solid").SolidContainerUri | import("@ldo/connected-solid").SolidLeafUri | undefined, options?: import("@ldo/react").UseResourceOptions<"solid"> | undefined) => import("@ldo/connected-solid").SolidContainer | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useRootContainerFor = exports.useSolidAuth = exports.BrowserSolidLdoProvider = exports.useSubscribeToResource = exports.useSubject = exports.useResource = exports.useMatchSubject = exports.useMatchObject = exports.useLdo = exports.dataset = void 0;
|
|
5
|
+
const connected_solid_1 = require("@ldo/connected-solid");
|
|
6
|
+
const react_1 = require("@ldo/react");
|
|
7
|
+
const createBrowserSolidReactMethods_1 = require("./createBrowserSolidReactMethods");
|
|
8
|
+
_a = (0, react_1.createLdoReactMethods)([connected_solid_1.solidConnectedPlugin]), exports.dataset = _a.dataset, exports.useLdo = _a.useLdo, exports.useMatchObject = _a.useMatchObject, exports.useMatchSubject = _a.useMatchSubject, exports.useResource = _a.useResource, exports.useSubject = _a.useSubject, exports.useSubscribeToResource = _a.useSubscribeToResource;
|
|
9
|
+
_b = (0, createBrowserSolidReactMethods_1.createBrowserSolidReactMethods)(exports.dataset), exports.BrowserSolidLdoProvider = _b.BrowserSolidLdoProvider, exports.useSolidAuth = _b.useSolidAuth, exports.useRootContainerFor = _b.useRootContainerFor;
|
|
10
|
+
//# sourceMappingURL=defaultIntance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultIntance.js","sourceRoot":"","sources":["../src/defaultIntance.ts"],"names":[],"mappings":";;;;AAAA,0DAA4D;AAC5D,sCAAmD;AACnD,qFAAkF;AAKrE,KAQT,IAAA,6BAAqB,EAAC,CAAC,sCAAoB,CAAC,CAAC,EAP/C,eAAO,eACP,cAAM,cACN,sBAAc,sBACd,uBAAe,uBACf,mBAAW,mBACX,kBAAU,kBACV,8BAAsB,6BAC0B;AAErC,KACX,IAAA,+DAA8B,EAAC,eAAO,CAAC,EAD1B,+BAAuB,+BAAE,oBAAY,oBAAE,2BAAmB,0BAC/B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./SolidAuthContext";
|
|
4
|
-
export { useLdo } from "./SolidLdoProvider";
|
|
5
|
-
export * from "./useResource";
|
|
6
|
-
export * from "./useSubject";
|
|
7
|
-
export * from "./useMatchSubject";
|
|
8
|
-
export * from "./useMatchObject";
|
|
9
|
-
export * from "./useRootContainer";
|
|
1
|
+
export * from "./createBrowserSolidReactMethods";
|
|
2
|
+
export * from "./defaultIntance";
|
package/dist/index.js
CHANGED
|
@@ -14,15 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./UnauthenticatedSolidLdoProvider"), exports);
|
|
20
|
-
__exportStar(require("./SolidAuthContext"), exports);
|
|
21
|
-
var SolidLdoProvider_1 = require("./SolidLdoProvider");
|
|
22
|
-
Object.defineProperty(exports, "useLdo", { enumerable: true, get: function () { return SolidLdoProvider_1.useLdo; } });
|
|
23
|
-
__exportStar(require("./useResource"), exports);
|
|
24
|
-
__exportStar(require("./useSubject"), exports);
|
|
25
|
-
__exportStar(require("./useMatchSubject"), exports);
|
|
26
|
-
__exportStar(require("./useMatchObject"), exports);
|
|
27
|
-
__exportStar(require("./useRootContainer"), exports);
|
|
17
|
+
__exportStar(require("./createBrowserSolidReactMethods"), exports);
|
|
18
|
+
__exportStar(require("./defaultIntance"), exports);
|
|
28
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mEAAiD;AACjD,mDAAiC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected";
|
|
2
|
+
import type { SolidConnectedPlugin, SolidContainer, SolidContainerUri, SolidLeafUri } from "@ldo/connected-solid";
|
|
3
|
+
import type { UseResourceOptions, createUseResource } from "@ldo/react";
|
|
4
|
+
export declare function createUseRootContainerFor(dataset: ConnectedLdoDataset<SolidConnectedPlugin[]>, useResource: ReturnType<typeof createUseResource<ConnectedPlugin[]>>): (uri?: SolidContainerUri | SolidLeafUri, options?: UseResourceOptions<"solid">) => SolidContainer | undefined;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createUseRootContainerFor = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
function createUseRootContainerFor(dataset, useResource) {
|
|
6
|
+
return function useRootContainerFor(uri, options) {
|
|
7
|
+
const [rootContainerUri, setRootContainerUri] = (0, react_1.useState)(undefined);
|
|
8
|
+
(0, react_1.useEffect)(() => {
|
|
9
|
+
if (uri) {
|
|
10
|
+
const givenResource = dataset.getResource(uri);
|
|
11
|
+
givenResource.getRootContainer().then((result) => {
|
|
12
|
+
if (!result.isError) {
|
|
13
|
+
setRootContainerUri(result.uri);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
setRootContainerUri(undefined);
|
|
19
|
+
}
|
|
20
|
+
}, [uri]);
|
|
21
|
+
return useResource(rootContainerUri, options);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.createUseRootContainerFor = createUseRootContainerFor;
|
|
25
|
+
//# sourceMappingURL=useRootContainerFor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRootContainerFor.js","sourceRoot":"","sources":["../src/useRootContainerFor.ts"],"names":[],"mappings":";;;AAAA,iCAA4C;AAe5C,SAAgB,yBAAyB,CACvC,OAAoD,EACpD,WAAoE;IAKpE,OAAO,SAAS,mBAAmB,CACjC,GAAsC,EACtC,OAAqC;QAErC,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,IAAA,gBAAQ,EAEtD,SAAS,CAAC,CAAC;QAEb,IAAA,iBAAS,EAAC,GAAG,EAAE;YACb,IAAI,GAAG,EAAE,CAAC;gBACR,MAAM,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;gBAC/C,aAAa,CAAC,gBAAgB,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;oBAC/C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;wBACpB,mBAAmB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;oBAClC,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,mBAAmB,CAAC,SAAS,CAAC,CAAC;YACjC,CAAC;QACH,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAEV,OAAO,WAAW,CAAC,gBAAgB,EAAE,OAAO,CAA+B,CAAC;IAC9E,CAAC,CAAC;AACJ,CAAC;AA9BD,8DA8BC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldo/solid-react",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.3",
|
|
4
4
|
"description": "A React library for LDO and Solid",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc --project tsconfig.build.json",
|
|
8
|
-
"watch": "tsc --watch",
|
|
8
|
+
"watch": "tsc --project tsconfig.build.json --watch",
|
|
9
9
|
"test": "npm run test:integration",
|
|
10
10
|
"test:watch": "jest --watch",
|
|
11
11
|
"prepublishOnly": "npm run test && npm run build",
|
|
@@ -26,22 +26,23 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/o-development/ldobjects/tree/main/packages/solid-react#readme",
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@
|
|
29
|
+
"@babel/core": "^7.26.10",
|
|
30
|
+
"@babel/preset-env": "^7.26.9",
|
|
31
|
+
"@inrupt/jest-jsdom-polyfills": "^3.2.6",
|
|
32
|
+
"@ldo/rdf-utils": "^1.0.0-alpha.3",
|
|
30
33
|
"@rdfjs/types": "^1.0.1",
|
|
31
34
|
"@testing-library/react": "^14.1.2",
|
|
32
|
-
"
|
|
33
|
-
"jest-environment-jsdom": "^
|
|
35
|
+
"babel-jest": "^29.7.0",
|
|
36
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
34
37
|
"start-server-and-test": "^2.0.3",
|
|
35
|
-
"ts-jest": "^
|
|
36
|
-
"ts-node": "^10.9.2"
|
|
38
|
+
"ts-jest": "^29.3.0",
|
|
39
|
+
"ts-node": "^10.9.2",
|
|
40
|
+
"whatwg-fetch": "^3.6.20"
|
|
37
41
|
},
|
|
38
42
|
"dependencies": {
|
|
39
43
|
"@inrupt/solid-client-authn-browser": "^2.0.0",
|
|
40
|
-
"@ldo/
|
|
41
|
-
"@ldo/
|
|
42
|
-
"@ldo/ldo": "^1.0.0-alpha.1",
|
|
43
|
-
"@ldo/solid": "^1.0.0-alpha.1",
|
|
44
|
-
"@ldo/subscribable-dataset": "^1.0.0-alpha.1",
|
|
44
|
+
"@ldo/connected": "^1.0.0-alpha.3",
|
|
45
|
+
"@ldo/connected-solid": "^1.0.0-alpha.3",
|
|
45
46
|
"@rdfjs/data-model": "^1.2.0",
|
|
46
47
|
"cross-fetch": "^3.1.6"
|
|
47
48
|
},
|
|
@@ -52,5 +53,5 @@
|
|
|
52
53
|
"publishConfig": {
|
|
53
54
|
"access": "public"
|
|
54
55
|
},
|
|
55
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "e1995e01e769d2ba37e419c661171606e1941c3c"
|
|
56
57
|
}
|
package/src/SolidAuthContext.ts
CHANGED
|
@@ -7,6 +7,9 @@ import { createContext, useContext } from "react";
|
|
|
7
7
|
export type SessionInfo = ISessionInfo;
|
|
8
8
|
export type LoginOptions = ILoginInputOptions;
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Functions for authenticating with Solid
|
|
12
|
+
*/
|
|
10
13
|
export interface SolidAuthFunctions {
|
|
11
14
|
login: (issuer: string, loginOptions?: LoginOptions) => Promise<void>;
|
|
12
15
|
logout: () => Promise<void>;
|
|
@@ -4,7 +4,6 @@ import type { FunctionComponent, PropsWithChildren } from "react";
|
|
|
4
4
|
import type { LoginOptions, SessionInfo } from "./SolidAuthContext";
|
|
5
5
|
import { SolidAuthContext } from "./SolidAuthContext";
|
|
6
6
|
import libraryFetch from "cross-fetch";
|
|
7
|
-
import { SolidLdoProvider } from "./SolidLdoProvider";
|
|
8
7
|
|
|
9
8
|
const DUMMY_SESSION: SessionInfo = {
|
|
10
9
|
isLoggedIn: false,
|
|
@@ -14,6 +13,9 @@ const DUMMY_SESSION: SessionInfo = {
|
|
|
14
13
|
expirationDate: undefined,
|
|
15
14
|
};
|
|
16
15
|
|
|
16
|
+
/**
|
|
17
|
+
* A provider for interacting with Solid Pods without authenticating
|
|
18
|
+
*/
|
|
17
19
|
export const UnauthenticatedSolidLdoProvider: FunctionComponent<
|
|
18
20
|
PropsWithChildren
|
|
19
21
|
> = ({ children }) => {
|
|
@@ -56,7 +58,7 @@ export const UnauthenticatedSolidLdoProvider: FunctionComponent<
|
|
|
56
58
|
|
|
57
59
|
return (
|
|
58
60
|
<SolidAuthContext.Provider value={solidAuthFunctions}>
|
|
59
|
-
|
|
61
|
+
{children}
|
|
60
62
|
</SolidAuthContext.Provider>
|
|
61
63
|
);
|
|
62
64
|
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
|
+
import type { FunctionComponent, PropsWithChildren } from "react";
|
|
3
|
+
import type { LoginOptions, SessionInfo } from "./SolidAuthContext";
|
|
4
|
+
import { SolidAuthContext, useSolidAuth } from "./SolidAuthContext";
|
|
5
|
+
import {
|
|
6
|
+
getDefaultSession,
|
|
7
|
+
handleIncomingRedirect,
|
|
8
|
+
login as libraryLogin,
|
|
9
|
+
logout as libraryLogout,
|
|
10
|
+
fetch as libraryFetch,
|
|
11
|
+
} from "@inrupt/solid-client-authn-browser";
|
|
12
|
+
import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected";
|
|
13
|
+
import type { SolidConnectedPlugin } from "@ldo/connected-solid";
|
|
14
|
+
import { createUseRootContainerFor } from "./useRootContainerFor";
|
|
15
|
+
import { createUseResource } from "@ldo/react";
|
|
16
|
+
|
|
17
|
+
const PRE_REDIRECT_URI = "PRE_REDIRECT_URI";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates special react methods specific to the Solid
|
|
21
|
+
* @param dataset the connectedLdoDataset with a SolidConnectedPlugin
|
|
22
|
+
* @returns { BrowserSolidLdoProvider, useSolidAuth, useRootContainerFor }
|
|
23
|
+
*/
|
|
24
|
+
export function createBrowserSolidReactMethods(
|
|
25
|
+
dataset: ConnectedLdoDataset<(SolidConnectedPlugin | ConnectedPlugin)[]>,
|
|
26
|
+
) {
|
|
27
|
+
dataset.setContext("solid", { fetch: libraryFetch });
|
|
28
|
+
|
|
29
|
+
const BrowserSolidLdoProvider: FunctionComponent<PropsWithChildren> = ({
|
|
30
|
+
children,
|
|
31
|
+
}) => {
|
|
32
|
+
const [session, setSession] = useState<SessionInfo>(
|
|
33
|
+
getDefaultSession().info,
|
|
34
|
+
);
|
|
35
|
+
const [ranInitialAuthCheck, setRanInitialAuthCheck] = useState(false);
|
|
36
|
+
|
|
37
|
+
const runInitialAuthCheck = useCallback(async () => {
|
|
38
|
+
if (!window.localStorage.getItem(PRE_REDIRECT_URI)) {
|
|
39
|
+
window.localStorage.setItem(PRE_REDIRECT_URI, window.location.href);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
await handleIncomingRedirect({
|
|
43
|
+
restorePreviousSession: true,
|
|
44
|
+
});
|
|
45
|
+
// Set timout to ensure this happens after the redirect
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
setSession({ ...getDefaultSession().info });
|
|
48
|
+
window.history.replaceState(
|
|
49
|
+
{},
|
|
50
|
+
"",
|
|
51
|
+
window.localStorage.getItem(PRE_REDIRECT_URI),
|
|
52
|
+
);
|
|
53
|
+
window.localStorage.removeItem(PRE_REDIRECT_URI);
|
|
54
|
+
|
|
55
|
+
setRanInitialAuthCheck(true);
|
|
56
|
+
}, 0);
|
|
57
|
+
}, []);
|
|
58
|
+
|
|
59
|
+
const login = useCallback(
|
|
60
|
+
async (issuer: string, options?: LoginOptions) => {
|
|
61
|
+
const cleanUrl = new URL(window.location.href);
|
|
62
|
+
cleanUrl.hash = "";
|
|
63
|
+
cleanUrl.search = "";
|
|
64
|
+
const fullOptions = {
|
|
65
|
+
redirectUrl: cleanUrl.toString(),
|
|
66
|
+
clientName: "Solid App",
|
|
67
|
+
oidcIssuer: issuer,
|
|
68
|
+
...options,
|
|
69
|
+
};
|
|
70
|
+
window.localStorage.setItem(PRE_REDIRECT_URI, window.location.href);
|
|
71
|
+
await libraryLogin(fullOptions);
|
|
72
|
+
setSession({ ...getDefaultSession().info });
|
|
73
|
+
},
|
|
74
|
+
[],
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const logout = useCallback(async () => {
|
|
78
|
+
await libraryLogout();
|
|
79
|
+
setSession({ ...getDefaultSession().info });
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
const signUp = useCallback(
|
|
83
|
+
async (issuer: string, options?: LoginOptions) => {
|
|
84
|
+
// The typings on @inrupt/solid-client-authn-core have not yet been updated
|
|
85
|
+
// TODO: remove this ts-ignore when they are updated.
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
return login(issuer, { ...options, prompt: "create" });
|
|
89
|
+
},
|
|
90
|
+
[login],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
runInitialAuthCheck();
|
|
95
|
+
}, []);
|
|
96
|
+
|
|
97
|
+
const solidAuthFunctions = useMemo(
|
|
98
|
+
() => ({
|
|
99
|
+
runInitialAuthCheck,
|
|
100
|
+
login,
|
|
101
|
+
logout,
|
|
102
|
+
signUp,
|
|
103
|
+
session,
|
|
104
|
+
ranInitialAuthCheck,
|
|
105
|
+
fetch: libraryFetch,
|
|
106
|
+
}),
|
|
107
|
+
[
|
|
108
|
+
login,
|
|
109
|
+
logout,
|
|
110
|
+
ranInitialAuthCheck,
|
|
111
|
+
runInitialAuthCheck,
|
|
112
|
+
session,
|
|
113
|
+
signUp,
|
|
114
|
+
],
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<SolidAuthContext.Provider value={solidAuthFunctions}>
|
|
119
|
+
{children}
|
|
120
|
+
</SolidAuthContext.Provider>
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
BrowserSolidLdoProvider,
|
|
126
|
+
useSolidAuth: useSolidAuth,
|
|
127
|
+
useRootContainerFor: createUseRootContainerFor(
|
|
128
|
+
dataset as ConnectedLdoDataset<SolidConnectedPlugin[]>,
|
|
129
|
+
createUseResource(dataset as ConnectedLdoDataset<ConnectedPlugin[]>),
|
|
130
|
+
),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { solidConnectedPlugin } from "@ldo/connected-solid";
|
|
2
|
+
import { createLdoReactMethods } from "@ldo/react";
|
|
3
|
+
import { createBrowserSolidReactMethods } from "./createBrowserSolidReactMethods";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Default exports for just Solid methods
|
|
7
|
+
*/
|
|
8
|
+
export const {
|
|
9
|
+
dataset,
|
|
10
|
+
useLdo,
|
|
11
|
+
useMatchObject,
|
|
12
|
+
useMatchSubject,
|
|
13
|
+
useResource,
|
|
14
|
+
useSubject,
|
|
15
|
+
useSubscribeToResource,
|
|
16
|
+
} = createLdoReactMethods([solidConnectedPlugin]);
|
|
17
|
+
|
|
18
|
+
export const { BrowserSolidLdoProvider, useSolidAuth, useRootContainerFor } =
|
|
19
|
+
createBrowserSolidReactMethods(dataset);
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./SolidAuthContext";
|
|
4
|
-
|
|
5
|
-
export { useLdo } from "./SolidLdoProvider";
|
|
6
|
-
|
|
7
|
-
// hooks
|
|
8
|
-
export * from "./useResource";
|
|
9
|
-
export * from "./useSubject";
|
|
10
|
-
export * from "./useMatchSubject";
|
|
11
|
-
export * from "./useMatchObject";
|
|
12
|
-
export * from "./useRootContainer";
|
|
1
|
+
export * from "./createBrowserSolidReactMethods";
|
|
2
|
+
export * from "./defaultIntance";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected";
|
|
3
|
+
import type {
|
|
4
|
+
SolidConnectedPlugin,
|
|
5
|
+
SolidContainer,
|
|
6
|
+
SolidContainerUri,
|
|
7
|
+
SolidLeafUri,
|
|
8
|
+
} from "@ldo/connected-solid";
|
|
9
|
+
import type { UseResourceOptions, createUseResource } from "@ldo/react";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*
|
|
14
|
+
* Creates a useRootContainerFor function
|
|
15
|
+
*/
|
|
16
|
+
export function createUseRootContainerFor(
|
|
17
|
+
dataset: ConnectedLdoDataset<SolidConnectedPlugin[]>,
|
|
18
|
+
useResource: ReturnType<typeof createUseResource<ConnectedPlugin[]>>,
|
|
19
|
+
) {
|
|
20
|
+
/**
|
|
21
|
+
* Gets the root container for a specific URI
|
|
22
|
+
*/
|
|
23
|
+
return function useRootContainerFor(
|
|
24
|
+
uri?: SolidContainerUri | SolidLeafUri,
|
|
25
|
+
options?: UseResourceOptions<"solid">,
|
|
26
|
+
): SolidContainer | undefined {
|
|
27
|
+
const [rootContainerUri, setRootContainerUri] = useState<
|
|
28
|
+
SolidContainerUri | undefined
|
|
29
|
+
>(undefined);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (uri) {
|
|
33
|
+
const givenResource = dataset.getResource(uri);
|
|
34
|
+
givenResource.getRootContainer().then((result) => {
|
|
35
|
+
if (!result.isError) {
|
|
36
|
+
setRootContainerUri(result.uri);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
setRootContainerUri(undefined);
|
|
41
|
+
}
|
|
42
|
+
}, [uri]);
|
|
43
|
+
|
|
44
|
+
return useResource(rootContainerUri, options) as SolidContainer | undefined;
|
|
45
|
+
};
|
|
46
|
+
}
|