@@ -69,7 +69,6 @@ function unHookGetItemURL (rs): void {
69
69
* @param {XMLHttpRequestBodyInit } body - Request body
70
70
* @returns {Blob } Blob equivalent of the body
71
71
*
72
- *
73
72
* @private
74
73
*/
75
74
function requestBodyToBlob ( body : XMLHttpRequestBodyInit ) : Blob {
@@ -104,29 +103,23 @@ function requestBodyToBlob(body: XMLHttpRequestBodyInit): Blob {
104
103
/**
105
104
* @class Solid
106
105
*
107
- * To use this backend, you need to specify the authURL like so:
106
+ * To use this backend, you need to specify the authURL before calling connect like so:
108
107
*
109
108
* @example
110
- * remoteStorage.setAuthURL('https://login.example.com');
109
+ * solid.setAuthURL('https://login.example.com');
110
+ * solid.connect();
111
111
*
112
- * In order to set the Solid options for the widget you have to specify the valid options like so:
113
- *
114
- * @example
115
- * remoteStorage.setApiKeys({
116
- * solid: {
117
- * providers: [
118
- * {
119
- * name: "provider name",
120
- * authURL: "auth URL"
121
- * }
122
- * ],
123
- * allowAnyProvider: true|false
124
- * }
125
- * });
112
+ * If connect is successful a list of available pods for the Solid account is retrieved and
113
+ * a `pod-not-selected` event is fired. After receiving this event you have to call getPodURLs
114
+ * to get the list of available pods and set one of them to be used by calling setPodURL. After
115
+ * setting the pod URL the `connected` event is fired.
116
+ *
117
+ * You can find a list of running solid servers on the solid project website here:
118
+ * https://solidproject.org/for-developers#hosted-pod-services
126
119
**/
127
120
class Solid extends RemoteBase implements Remote , ConfigObserver {
128
121
authURL : string ;
129
- podURLs : string [ ] = [ ] ;
122
+ podURLs : string [ ] = null ;
130
123
selectedPodURL : string ;
131
124
sessionProperties : object ;
132
125
configStorage : ConfigStorage ;
@@ -135,12 +128,13 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
135
128
constructor ( remoteStorage ) {
136
129
super ( remoteStorage ) ;
137
130
this . online = true ;
138
- this . storageApi = 'draft-dejong-remotestorage-19' ;
139
131
this . addEvents ( [ 'connected' , 'not-connected' , 'pod-not-selected' ] ) ;
140
132
133
+ // We use a custom ConfigStore to store the solid session in a rs friendly manner to
134
+ // make configuration and disconnect work.
141
135
this . configStorage = new ConfigStorage ( this ) ;
142
136
this . session = new Session ( {
143
- secureStorage : new InMemoryStorage ( ) ,
137
+ secureStorage : new InMemoryStorage ( ) , // Inrupt prefers InMemoryStorage for tokens. We respect that.
144
138
insecureStorage : this . configStorage
145
139
} , 'any' ) ;
146
140
@@ -154,6 +148,15 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
154
148
}
155
149
}
156
150
151
+ /**
152
+ * Solid Session storage state changed.
153
+ *
154
+ * This function is called by the ConfigStore that we provided to Session as an insecure storage.
155
+ *
156
+ * @param {string } config - The entire Session configuration object serialized into a string
157
+ *
158
+ * @private
159
+ */
157
160
onConfigChanged ( config : string ) : void {
158
161
if ( config ) {
159
162
const sessionConfig = JSON . parse ( config ) ;
@@ -178,6 +181,7 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
178
181
}
179
182
}
180
183
184
+ this . podURLs = null ;
181
185
localStorage . removeItem ( SETTINGS_KEY ) ;
182
186
}
183
187
@@ -236,6 +240,7 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
236
240
const handleError = function ( ) {
237
241
this . connected = false ;
238
242
this . sessionProperties = null ;
243
+ this . podURLs = null ;
239
244
if ( hasLocalStorage ) {
240
245
localStorage . removeItem ( SETTINGS_KEY ) ;
241
246
}
@@ -252,20 +257,42 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
252
257
253
258
/**
254
259
* Set the auth URL
260
+ *
255
261
* @param {string } authURL - Auth URL
262
+ *
263
+ * @public
256
264
*/
257
265
setAuthURL ( authURL : string ) : void {
258
266
this . authURL = authURL ;
259
267
}
260
268
261
269
/**
270
+ * Get a list of pod URLs for this Solid account.
271
+ *
272
+ * If the Solid Session is not connected, this function returns null.
262
273
*
263
274
* @returns Get the list of pod URLs
275
+ *
276
+ * @public
264
277
*/
265
278
getPodURLs ( ) : string [ ] {
266
279
return this . podURLs ;
267
280
}
268
281
282
+ /**
283
+ * Set the pod URL to use as the storage.
284
+ *
285
+ * Pod URL must be one of the URLs provided by the getPodURLs function. This function does
286
+ * not validate this constraint.
287
+ *
288
+ * If the Solid Session is connected and the pod URL is updated to be null, a
289
+ * `pod-not-selected` event will be fired. If Session is connected and the pod URL is set,
290
+ * a `connected` event will be fired.
291
+ *
292
+ * @param {string } podURL - URL of the pod to be used as storage
293
+ *
294
+ * @public
295
+ */
269
296
setPodURL ( podURL : string ) : void {
270
297
if ( this . selectedPodURL === podURL ) {
271
298
return ;
@@ -299,12 +326,21 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
299
326
}
300
327
}
301
328
302
- getPodURL ( ) : string | null {
329
+ /**
330
+ * Get the pod URL that is being used as the storage.
331
+ *
332
+ * @returns {string } The in-use pod URL or null
333
+ *
334
+ * @public
335
+ */
336
+ getPodURL ( ) : string {
303
337
return this . selectedPodURL ;
304
338
}
305
339
306
340
/**
307
341
* Initiate the authorization flow's OAuth dance.
342
+ *
343
+ * @public
308
344
*/
309
345
connect ( ) : void {
310
346
this . rs . setBackend ( 'solid' ) ;
@@ -324,10 +360,12 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
324
360
/**
325
361
* Get the connected Solid session
326
362
*
327
- * @returns {Session } that is being used by this instance
363
+ * @returns {Session } that is being used by this instance or null if Session is not connected
364
+ *
365
+ * @public
328
366
*/
329
367
getSession ( ) : Session {
330
- return ( this . session . info && this . session . info . isLoggedIn ) ?this . session :undefined ;
368
+ return ( this . session . info && this . session . info . isLoggedIn ) ?this . session :null ;
331
369
}
332
370
333
371
/**
@@ -336,7 +374,6 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
336
374
* @param {string } path - Path of the resource
337
375
* @returns {string } Full URL of the resource on the pod
338
376
*
339
- *
340
377
* @private
341
378
*/
342
379
getFileURL ( path : string ) : string {
@@ -388,7 +425,7 @@ class Solid extends RemoteBase implements Remote, ConfigObserver {
388
425
statusCode : 200 ,
389
426
body : listing ,
390
427
contentType : 'application/json; charset=UTF-8' ,
391
- // revision: ?
428
+ // revision: ? Skipping ETag
392
429
} as RemoteResponse ) ;
393
430
} ) . catch ( error => {
394
431
if ( error instanceof FetchError ) {
0 commit comments