javascript-solid-server 0.0.146 → 0.0.148

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javascript-solid-server",
3
- "version": "0.0.146",
3
+ "version": "0.0.148",
4
4
  "description": "A minimal, fast Solid server",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -182,10 +182,10 @@ export async function createPodStructure(name, webId, podUri, issuer, defaultQuo
182
182
  await storage.write(`${podPath}settings/prefs.jsonld`, serialize(prefs));
183
183
 
184
184
  // Generate and write type indexes
185
- const publicTypeIndex = generateTypeIndex(`${podUri}settings/publicTypeIndex.jsonld`);
185
+ const publicTypeIndex = generateTypeIndex(`${podUri}settings/publicTypeIndex.jsonld`, { listed: true });
186
186
  await storage.write(`${podPath}settings/publicTypeIndex.jsonld`, serialize(publicTypeIndex));
187
187
 
188
- const privateTypeIndex = generateTypeIndex(`${podUri}settings/privateTypeIndex.jsonld`);
188
+ const privateTypeIndex = generateTypeIndex(`${podUri}settings/privateTypeIndex.jsonld`, { listed: false });
189
189
  await storage.write(`${podPath}settings/privateTypeIndex.jsonld`, serialize(privateTypeIndex));
190
190
 
191
191
  // Create default ACL files
package/src/server.js CHANGED
@@ -606,10 +606,10 @@ export function createServer(options = {}) {
606
606
  const prefs = generatePreferences({ webId, podUri });
607
607
  await storage.write('/settings/prefs.jsonld', serialize(prefs));
608
608
 
609
- const publicTypeIndex = generateTypeIndex(`${podUri}settings/publicTypeIndex.jsonld`);
609
+ const publicTypeIndex = generateTypeIndex(`${podUri}settings/publicTypeIndex.jsonld`, { listed: true });
610
610
  await storage.write('/settings/publicTypeIndex.jsonld', serialize(publicTypeIndex));
611
611
 
612
- const privateTypeIndex = generateTypeIndex(`${podUri}settings/privateTypeIndex.jsonld`);
612
+ const privateTypeIndex = generateTypeIndex(`${podUri}settings/privateTypeIndex.jsonld`, { listed: false });
613
613
  await storage.write('/settings/privateTypeIndex.jsonld', serialize(privateTypeIndex));
614
614
 
615
615
  // ACL files
@@ -24,7 +24,6 @@ const PIM = 'http://www.w3.org/ns/pim/space#';
24
24
  */
25
25
  export function generateProfileJsonLd({ webId, name, podUri, issuer }) {
26
26
  const pod = podUri.endsWith('/') ? podUri : podUri + '/';
27
- const profileDoc = webId.split('#')[0];
28
27
 
29
28
  return {
30
29
  '@context': {
@@ -39,12 +38,14 @@ export function generateProfileJsonLd({ webId, name, podUri, issuer }) {
39
38
  'preferencesFile': { '@id': 'pim:preferencesFile', '@type': '@id' },
40
39
  'publicTypeIndex': { '@id': 'solid:publicTypeIndex', '@type': '@id' },
41
40
  'privateTypeIndex': { '@id': 'solid:privateTypeIndex', '@type': '@id' },
41
+ 'isPrimaryTopicOf': { '@id': 'foaf:isPrimaryTopicOf', '@type': '@id' },
42
42
  'mainEntityOfPage': { '@id': 'schema:mainEntityOfPage', '@type': '@id' }
43
43
  },
44
44
  '@id': webId,
45
45
  '@type': ['foaf:Person', 'schema:Person'],
46
46
  'foaf:name': name,
47
- 'mainEntityOfPage': profileDoc,
47
+ 'isPrimaryTopicOf': '',
48
+ 'mainEntityOfPage': '',
48
49
  'inbox': `${pod}inbox/`,
49
50
  'storage': pod,
50
51
  'oidcIssuer': issuer,
@@ -97,17 +98,25 @@ export function generatePreferences({ webId, podUri }) {
97
98
  }
98
99
 
99
100
  /**
100
- * Generate an empty type index
101
+ * Generate an empty type index.
102
+ * Per the Solid Type Indexes spec, a public index is additionally typed
103
+ * `solid:ListedDocument` and a private one `solid:UnlistedDocument`.
101
104
  * @param {string} uri - URI of the type index
105
+ * @param {object} [opts]
106
+ * @param {boolean} [opts.listed] - true for publicTypeIndex, false for privateTypeIndex.
107
+ * If omitted, only `solid:TypeIndex` is set (back-compat).
102
108
  * @returns {object} JSON-LD type index document
103
109
  */
104
- export function generateTypeIndex(uri) {
110
+ export function generateTypeIndex(uri, opts = {}) {
111
+ const types = ['solid:TypeIndex'];
112
+ if (opts.listed === true) types.push('solid:ListedDocument');
113
+ else if (opts.listed === false) types.push('solid:UnlistedDocument');
105
114
  return {
106
115
  '@context': {
107
116
  'solid': SOLID
108
117
  },
109
118
  '@id': uri,
110
- '@type': 'solid:TypeIndex'
119
+ '@type': types.length === 1 ? types[0] : types
111
120
  };
112
121
  }
113
122
 
package/test/pod.test.js CHANGED
@@ -131,5 +131,33 @@ describe('Pod Lifecycle', () => {
131
131
  const prefs = await request('/elsa/settings/prefs.jsonld');
132
132
  assertStatus(prefs, 401);
133
133
  });
134
+
135
+ it('should mark type indexes as ListedDocument / UnlistedDocument', async () => {
136
+ await createTestPod('frida');
137
+
138
+ const pub = await request('/frida/settings/publicTypeIndex.jsonld');
139
+ assertStatus(pub, 200);
140
+ const pubBody = await pub.json();
141
+ assert.ok(
142
+ Array.isArray(pubBody['@type']) && pubBody['@type'].includes('solid:ListedDocument'),
143
+ 'publicTypeIndex should be solid:ListedDocument'
144
+ );
145
+ assert.ok(
146
+ Array.isArray(pubBody['@type']) && pubBody['@type'].includes('solid:TypeIndex'),
147
+ 'publicTypeIndex should be solid:TypeIndex'
148
+ );
149
+
150
+ const priv = await request('/frida/settings/privateTypeIndex.jsonld', { auth: 'frida' });
151
+ assertStatus(priv, 200);
152
+ const privBody = await priv.json();
153
+ assert.ok(
154
+ Array.isArray(privBody['@type']) && privBody['@type'].includes('solid:UnlistedDocument'),
155
+ 'privateTypeIndex should be solid:UnlistedDocument'
156
+ );
157
+ assert.ok(
158
+ Array.isArray(privBody['@type']) && privBody['@type'].includes('solid:TypeIndex'),
159
+ 'privateTypeIndex should be solid:TypeIndex'
160
+ );
161
+ });
134
162
  });
135
163
  });
@@ -83,11 +83,20 @@ describe('WebID Profile', () => {
83
83
  assert.ok(jsonLd['inbox'].endsWith('/webidtest/inbox/'), 'Should have inbox');
84
84
  });
85
85
 
86
- it('should have mainEntityOfPage', async () => {
86
+ it('should have mainEntityOfPage pointing to the document', async () => {
87
87
  const res = await request(profilePath);
88
88
  const jsonLd = await res.json();
89
89
 
90
- assert.ok(jsonLd['mainEntityOfPage'], 'Should have mainEntityOfPage');
90
+ // Empty string is a relative URI reference to the document itself (JSON-LD)
91
+ assert.strictEqual(jsonLd['mainEntityOfPage'], '', 'mainEntityOfPage should be "" (self)');
92
+ });
93
+
94
+ it('should have isPrimaryTopicOf pointing to the document', async () => {
95
+ const res = await request(profilePath);
96
+ const jsonLd = await res.json();
97
+
98
+ // Empty string is a relative URI reference to the document itself (JSON-LD)
99
+ assert.strictEqual(jsonLd['isPrimaryTopicOf'], '', 'isPrimaryTopicOf should be "" (self)');
91
100
  });
92
101
  });
93
102