@noeldemartin/solid-utils 0.5.0 → 0.6.0-next.508449b33de64b0bcade86b642c9793381434231

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.
Files changed (66) hide show
  1. package/dist/chai.d.ts +31 -0
  2. package/dist/chai.js +23 -0
  3. package/dist/chai.js.map +1 -0
  4. package/dist/helpers-DGXMj9cx.js +107 -0
  5. package/dist/helpers-DGXMj9cx.js.map +1 -0
  6. package/dist/io-wCcrq4b9.js +401 -0
  7. package/dist/io-wCcrq4b9.js.map +1 -0
  8. package/dist/noeldemartin-solid-utils.d.ts +61 -65
  9. package/dist/noeldemartin-solid-utils.js +224 -0
  10. package/dist/noeldemartin-solid-utils.js.map +1 -0
  11. package/dist/testing.d.ts +40 -0
  12. package/dist/testing.js +7 -0
  13. package/dist/testing.js.map +1 -0
  14. package/dist/vitest.d.ts +50 -0
  15. package/dist/vitest.js +55 -0
  16. package/dist/vitest.js.map +1 -0
  17. package/package.json +67 -63
  18. package/src/chai/assertions.ts +35 -0
  19. package/src/chai/index.ts +19 -0
  20. package/src/errors/UnauthorizedError.ts +1 -3
  21. package/src/errors/UnsuccessfulNetworkRequestError.ts +2 -2
  22. package/src/helpers/auth.test.ts +221 -0
  23. package/src/helpers/auth.ts +28 -27
  24. package/src/helpers/identifiers.test.ts +76 -0
  25. package/src/helpers/identifiers.ts +14 -17
  26. package/src/helpers/index.ts +0 -1
  27. package/src/helpers/interop.ts +23 -16
  28. package/src/helpers/io.test.ts +228 -0
  29. package/src/helpers/io.ts +57 -77
  30. package/src/helpers/jsonld.ts +6 -6
  31. package/src/helpers/vocabs.ts +3 -6
  32. package/src/helpers/wac.test.ts +64 -0
  33. package/src/helpers/wac.ts +10 -6
  34. package/src/index.ts +4 -0
  35. package/src/models/SolidDocument.test.ts +77 -0
  36. package/src/models/SolidDocument.ts +14 -18
  37. package/src/models/SolidStore.ts +22 -12
  38. package/src/models/SolidThing.ts +5 -7
  39. package/src/models/index.ts +2 -0
  40. package/src/{helpers/testing.ts → testing/helpers.ts} +24 -27
  41. package/src/testing/hepers.test.ts +329 -0
  42. package/src/testing/index.ts +1 -2
  43. package/src/types/index.ts +2 -0
  44. package/src/types/n3.d.ts +0 -2
  45. package/src/vitest/index.ts +20 -0
  46. package/src/vitest/matchers.ts +68 -0
  47. package/.github/workflows/ci.yml +0 -16
  48. package/.nvmrc +0 -1
  49. package/CHANGELOG.md +0 -70
  50. package/dist/noeldemartin-solid-utils.cjs.js +0 -2
  51. package/dist/noeldemartin-solid-utils.cjs.js.map +0 -1
  52. package/dist/noeldemartin-solid-utils.esm.js +0 -2
  53. package/dist/noeldemartin-solid-utils.esm.js.map +0 -1
  54. package/dist/noeldemartin-solid-utils.umd.js +0 -90
  55. package/dist/noeldemartin-solid-utils.umd.js.map +0 -1
  56. package/noeldemartin.config.js +0 -9
  57. package/src/main.ts +0 -5
  58. package/src/plugins/chai/assertions.ts +0 -40
  59. package/src/plugins/chai/index.ts +0 -5
  60. package/src/plugins/cypress/types.d.ts +0 -15
  61. package/src/plugins/index.ts +0 -2
  62. package/src/plugins/jest/index.ts +0 -5
  63. package/src/plugins/jest/matchers.ts +0 -65
  64. package/src/plugins/jest/types.d.ts +0 -14
  65. package/src/testing/ResponseStub.ts +0 -46
  66. package/src/testing/mocking.ts +0 -33
@@ -0,0 +1,50 @@
1
+ import { MatcherState } from '@vitest/expect';
2
+
3
+ declare const _default: {
4
+ toEqualJsonLD(this: MatcherState, received: any, expected: JsonLD): Promise<{
5
+ pass: boolean;
6
+ message: () => string;
7
+ }>;
8
+ toEqualSparql(this: MatcherState, received: any, expected: string): {
9
+ pass: boolean;
10
+ message: () => string;
11
+ };
12
+ toEqualTurtle(this: MatcherState, received: any, expected: string): {
13
+ pass: boolean;
14
+ message: () => string;
15
+ };
16
+ };
17
+
18
+ export declare function installVitestSolidMatchers(): void;
19
+
20
+ declare type JsonLD = Partial<{
21
+ '@context': Record<string, unknown>;
22
+ '@id': string;
23
+ '@type': null | string | string[];
24
+ }> & {
25
+ [k: string]: unknown;
26
+ };
27
+
28
+ export declare type VitestSolidMatchers<R = unknown> = {
29
+ [K in keyof typeof _default]: (...args: Parameters<(typeof _default)[K]> extends [any, ...infer Rest] ? Rest : never) => ReturnType<(typeof _default)[K]> extends Promise<any> ? Promise<R> : R;
30
+ };
31
+
32
+ export { }
33
+
34
+
35
+ declare module '@vitest/expect' {
36
+ interface Assertion<T> extends VitestSolidMatchers<T> {
37
+ }
38
+ interface AsymmetricMatchersContaining extends VitestSolidMatchers {
39
+ }
40
+ }
41
+
42
+
43
+ declare global {
44
+ namespace Chai {
45
+ interface Assertion extends ChaiSolidAssertions {
46
+ }
47
+ interface Include extends ChaiSolidAssertions {
48
+ }
49
+ }
50
+ }
package/dist/vitest.js ADDED
@@ -0,0 +1,55 @@
1
+ import { expect as l } from "vitest";
2
+ import { n as r, b as i } from "./io-wCcrq4b9.js";
3
+ import { t as o, s as u, j as c } from "./helpers-DGXMj9cx.js";
4
+ function a(e, t) {
5
+ const s = e.success, n = t.state.utils;
6
+ return { pass: s, message: s ? () => [e.message, n.matcherHint(t.hint)].join(`
7
+
8
+ `) : () => [
9
+ e.message,
10
+ n.matcherHint(t.hint),
11
+ [
12
+ `Expected: not ${n.printExpected(t.expected)}`,
13
+ `Received: ${n.printReceived(t.received)}`
14
+ ].join(`
15
+ `)
16
+ ].join(`
17
+
18
+ `) };
19
+ }
20
+ const m = {
21
+ async toEqualJsonLD(e, t) {
22
+ const s = await c(t, e);
23
+ return a(s, {
24
+ state: this,
25
+ hint: "toEqualJsonLD",
26
+ expected: t,
27
+ received: e
28
+ });
29
+ },
30
+ toEqualSparql(e, t) {
31
+ const s = u(t, e);
32
+ return a(s, {
33
+ state: this,
34
+ hint: "toEqualSparql",
35
+ expected: i(t),
36
+ received: i(e)
37
+ });
38
+ },
39
+ toEqualTurtle(e, t) {
40
+ const s = o(t, e);
41
+ return a(s, {
42
+ state: this,
43
+ hint: "toEqualTurtle",
44
+ expected: r(t),
45
+ received: r(e)
46
+ });
47
+ }
48
+ };
49
+ function d() {
50
+ l.extend(m);
51
+ }
52
+ export {
53
+ d as installVitestSolidMatchers
54
+ };
55
+ //# sourceMappingURL=vitest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest.js","sources":["../src/vitest/matchers.ts","../src/vitest/index.ts"],"sourcesContent":["import type { MatcherState, MatchersObject } from '@vitest/expect';\n\nimport { normalizeSparql, normalizeTurtle } from '@noeldemartin/solid-utils/helpers/io';\nimport { jsonldEquals, sparqlEquals, turtleEquals } from '@noeldemartin/solid-utils/testing/helpers';\nimport type { EqualityResult } from '@noeldemartin/solid-utils/testing/helpers';\nimport type { JsonLD } from '@noeldemartin/solid-utils/helpers';\n\ninterface FormatResultOptions {\n state: MatcherState;\n hint: string;\n expected: unknown;\n received: unknown;\n}\n\nfunction formatResult(result: EqualityResult, options: FormatResultOptions) {\n const pass = result.success;\n const utils = options.state.utils;\n const message = pass\n ? () => [result.message, utils.matcherHint(options.hint)].join('\\n\\n')\n : () =>\n [\n result.message,\n utils.matcherHint(options.hint),\n [\n `Expected: not ${utils.printExpected(options.expected)}`,\n `Received: ${utils.printReceived(options.received)}`,\n ].join('\\n'),\n ].join('\\n\\n');\n\n return { pass, message };\n}\n\nexport function defineMatchers<T extends MatchersObject>(matchers: T): T {\n return matchers;\n}\n\nexport default defineMatchers({\n async toEqualJsonLD(received, expected: JsonLD) {\n const result = await jsonldEquals(expected, received);\n\n return formatResult(result, {\n state: this,\n hint: 'toEqualJsonLD',\n expected,\n received,\n });\n },\n toEqualSparql(received, expected: string) {\n const result = sparqlEquals(expected, received);\n\n return formatResult(result, {\n state: this,\n hint: 'toEqualSparql',\n expected: normalizeSparql(expected),\n received: normalizeSparql(received),\n });\n },\n toEqualTurtle(received, expected: string) {\n const result = turtleEquals(expected, received);\n\n return formatResult(result, {\n state: this,\n hint: 'toEqualTurtle',\n expected: normalizeTurtle(expected),\n received: normalizeTurtle(received),\n });\n },\n});\n","import { expect } from 'vitest';\n\nimport matchers from './matchers';\n\nexport type VitestSolidMatchers<R = unknown> = {\n [K in keyof typeof matchers]: (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: Parameters<(typeof matchers)[K]> extends [any, ...infer Rest] ? Rest : never\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) => ReturnType<(typeof matchers)[K]> extends Promise<any> ? Promise<R> : R;\n};\n\nexport function installVitestSolidMatchers(): void {\n expect.extend(matchers);\n}\n\ndeclare module '@vitest/expect' {\n interface Assertion<T> extends VitestSolidMatchers<T> {}\n interface AsymmetricMatchersContaining extends VitestSolidMatchers {}\n}\n"],"names":["formatResult","result","options","pass","utils","matchers","received","expected","jsonldEquals","sparqlEquals","normalizeSparql","turtleEquals","normalizeTurtle","installVitestSolidMatchers","expect"],"mappings":";;;AAcA,SAASA,EAAaC,GAAwBC,GAA8B;AACxE,QAAMC,IAAOF,EAAO,SACdG,IAAQF,EAAQ,MAAM;AAarB,SAAA,EAAE,MAAAC,GAAM,SAZCA,IACV,MAAM,CAACF,EAAO,SAASG,EAAM,YAAYF,EAAQ,IAAI,CAAC,EAAE,KAAK;AAAA;AAAA,CAAM,IACnE,MACE;AAAA,IACID,EAAO;AAAA,IACPG,EAAM,YAAYF,EAAQ,IAAI;AAAA,IAC9B;AAAA,MACI,iBAAiBE,EAAM,cAAcF,EAAQ,QAAQ,CAAC;AAAA,MACtD,aAAaE,EAAM,cAAcF,EAAQ,QAAQ,CAAC;AAAA,IACtD,EAAE,KAAK;AAAA,CAAI;AAAA,EAAA,EACb,KAAK;AAAA;AAAA,CAAM,EAEE;AAC3B;AAMA,MAAAG,IAA8B;AAAA,EAC1B,MAAM,cAAcC,GAAUC,GAAkB;AAC5C,UAAMN,IAAS,MAAMO,EAAaD,GAAUD,CAAQ;AAEpD,WAAON,EAAaC,GAAQ;AAAA,MACxB,OAAO;AAAA,MACP,MAAM;AAAA,MACN,UAAAM;AAAA,MACA,UAAAD;AAAA,IAAA,CACH;AAAA,EACL;AAAA,EACA,cAAcA,GAAUC,GAAkB;AAChC,UAAAN,IAASQ,EAAaF,GAAUD,CAAQ;AAE9C,WAAON,EAAaC,GAAQ;AAAA,MACxB,OAAO;AAAA,MACP,MAAM;AAAA,MACN,UAAUS,EAAgBH,CAAQ;AAAA,MAClC,UAAUG,EAAgBJ,CAAQ;AAAA,IAAA,CACrC;AAAA,EACL;AAAA,EACA,cAAcA,GAAUC,GAAkB;AAChC,UAAAN,IAASU,EAAaJ,GAAUD,CAAQ;AAE9C,WAAON,EAAaC,GAAQ;AAAA,MACxB,OAAO;AAAA,MACP,MAAM;AAAA,MACN,UAAUW,EAAgBL,CAAQ;AAAA,MAClC,UAAUK,EAAgBN,CAAQ;AAAA,IAAA,CACrC;AAAA,EAAA;AAET;ACvDO,SAASO,IAAmC;AAC/C,EAAAC,EAAO,OAAOT,CAAQ;AAC1B;"}
package/package.json CHANGED
@@ -1,65 +1,69 @@
1
1
  {
2
- "name": "@noeldemartin/solid-utils",
3
- "version": "0.5.0",
4
- "description": "My JavaScript utilities for Solid",
5
- "main": "dist/noeldemartin-solid-utils.cjs.js",
6
- "module": "dist/noeldemartin-solid-utils.esm.js",
7
- "browser": "dist/noeldemartin-solid-utils.umd.js",
8
- "types": "dist/noeldemartin-solid-utils.d.ts",
9
- "sideEffects": false,
10
- "scripts": {
11
- "build": "rm dist -rf && npm run build:js && npm run build:types",
12
- "build:js": "noeldemartin-build-javascript",
13
- "build:types": "noeldemartin-build-types",
14
- "lint": "noeldemartin-lint src",
15
- "publish-next": "noeldemartin-publish-next",
16
- "test": "jest --verbose",
17
- "test:coverage": "jest --coverage"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/noeldemartin/solid-utils.git"
22
- },
23
- "engines": {
24
- "node": ">=14.x"
25
- },
26
- "author": "Noel De Martin",
27
- "license": "MIT",
28
- "bugs": {
29
- "url": "https://github.com/noeldemartin/solid-utils/issues"
30
- },
31
- "homepage": "https://github.com/noeldemartin/solid-utils",
32
- "dependencies": {
33
- "@babel/runtime": "^7.14.0",
34
- "@noeldemartin/solid-utils-external": "^0.1.1",
35
- "@noeldemartin/utils": "^0.6.0",
36
- "@rdfjs/types": "^1.1.0",
37
- "core-js": "^3.12.1",
38
- "md5": "^2.3.0"
39
- },
40
- "devDependencies": {
41
- "@babel/core": "^7.14.3",
42
- "@babel/plugin-proposal-class-properties": "^7.13.0",
43
- "@babel/plugin-transform-runtime": "^7.14.3",
44
- "@babel/preset-env": "^7.14.2",
45
- "@babel/preset-typescript": "^7.13.0",
46
- "@microsoft/api-extractor": "^7.15.2",
47
- "@noeldemartin/eslint-config-typescript": "^0.1.1",
48
- "@noeldemartin/scripts": "^0.1.2",
49
- "@rollup/plugin-alias": "^3.1.2",
50
- "@rollup/plugin-babel": "^5.3.0",
51
- "@rollup/plugin-commonjs": "^19.0.0",
52
- "@rollup/plugin-node-resolve": "^13.0.0",
53
- "@rollup/plugin-typescript": "^8.2.1",
54
- "@types/chai": "^4.2.18",
55
- "@types/jest": "^26.0.23",
56
- "@types/md5": "^2.3.0",
57
- "babel-plugin-transform-remove-imports": "^1.5.4",
58
- "eslint": "^7.26.0",
59
- "jest": "^26.6.3",
60
- "rollup": "^2.48.0",
61
- "rollup-plugin-terser": "^7.0.2",
62
- "ts-jest": "^26.5.6",
63
- "typescript": "^4.2.4"
64
- }
2
+ "name": "@noeldemartin/solid-utils",
3
+ "version": "0.6.0-next.508449b33de64b0bcade86b642c9793381434231",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/noeldemartin-solid-utils.d.ts",
9
+ "default": "./dist/noeldemartin-solid-utils.js"
10
+ },
11
+ "./testing": {
12
+ "types": "./dist/testing.d.ts",
13
+ "default": "./dist/testing.js"
14
+ },
15
+ "./vitest": {
16
+ "types": "./dist/vitest.d.ts",
17
+ "default": "./dist/vitest.js"
18
+ },
19
+ "./chai": {
20
+ "types": "./dist/chai.d.ts",
21
+ "default": "./dist/chai.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "src",
26
+ "dist"
27
+ ],
28
+ "license": "MIT",
29
+ "author": "Noel De Martin",
30
+ "repository": "github:NoelDeMartin/solid-utils",
31
+ "scripts": {
32
+ "build": "vite build",
33
+ "lint": "noeldemartin-lint src",
34
+ "test": "vitest --run",
35
+ "test:ci": "vitest --run --reporter verbose",
36
+ "verify": "noeldemartin-verify"
37
+ },
38
+ "dependencies": {
39
+ "@noeldemartin/utils": "0.7.0-next.d98a97003e3b0af1b9fc05dbfd6e57fab3c2f181",
40
+ "@rdfjs/types": "^2.0.1",
41
+ "jsonld": "^8.3.3",
42
+ "md5": "^2.3.0",
43
+ "n3": "^1.24.2"
44
+ },
45
+ "devDependencies": {
46
+ "@noeldemartin/eslint-config-typescript": "^0.1.2",
47
+ "@noeldemartin/scripts": "0.3.0-next.2dfd366e59e45ecf5ead1a617e4d0e870dbea507",
48
+ "@noeldemartin/testing": "0.0.0-next.cd489a93da5eaad3f89a4d9ae3734f7ef911b6f6",
49
+ "@tsconfig/node22": "^22.0.0",
50
+ "@types/chai": "^5.2.0",
51
+ "@types/jsonld": "^1.5.15",
52
+ "@types/md5": "^2.3.5",
53
+ "@types/n3": "^1.24.1",
54
+ "@types/node": "^22.13.10",
55
+ "@vitest/expect": "^3.0.9",
56
+ "typescript": "^5.8.2",
57
+ "vite": "^6.2.2",
58
+ "vite-plugin-dts": "4.5.0",
59
+ "vitest": "^3.0.9"
60
+ },
61
+ "eslintConfig": {
62
+ "extends": [
63
+ "@noeldemartin/eslint-config-typescript"
64
+ ]
65
+ },
66
+ "prettier": {
67
+ "printWidth": 120
68
+ }
65
69
  }
@@ -0,0 +1,35 @@
1
+ import { sparqlEquals, turtleEquals } from '@noeldemartin/solid-utils/testing/helpers';
2
+ import type { EqualityResult } from '@noeldemartin/solid-utils/testing/helpers';
3
+
4
+ export function defineChaiAssertions<T extends Record<string, (this: Chai.AssertionStatic, ...args: any[]) => void>>(
5
+ assertions: T): T {
6
+ return assertions;
7
+ }
8
+
9
+ export default defineChaiAssertions({
10
+ turtle(graph: string): void {
11
+ const self = this as unknown as Chai.AssertionStatic;
12
+ const actual = self._obj as string;
13
+ const assert = self.assert.bind(this);
14
+ const expected = graph;
15
+ const result = turtleEquals(expected, actual);
16
+
17
+ assert(result.success, result.message, '', result.expected, result.actual);
18
+ },
19
+ sparql(query: string): void {
20
+ const self = this as unknown as Chai.AssertionStatic;
21
+ const actual = self._obj as string;
22
+ const assert = self.assert.bind(this);
23
+ const expected = query;
24
+ const result = sparqlEquals(expected, actual);
25
+
26
+ assert(result.success, result.message, '', result.expected, result.actual);
27
+ },
28
+ equalityResult(): void {
29
+ const self = this as unknown as Chai.AssertionStatic;
30
+ const result = self._obj as EqualityResult;
31
+ const assert = self.assert.bind(this);
32
+
33
+ assert(result.success, result.message, '', result.expected, result.actual);
34
+ },
35
+ });
@@ -0,0 +1,19 @@
1
+ import assertions from './assertions';
2
+
3
+ export type ChaiSolidAssertions = {
4
+ [assertion in keyof typeof assertions]: (typeof assertions)[assertion];
5
+ };
6
+
7
+ export function installChaiSolidAssertions(): void {
8
+ (globalThis as { chai?: Chai.ChaiStatic }).chai?.use((_chai) => {
9
+ return Object.entries(assertions).forEach(([name, method]) => _chai.Assertion.addMethod(name, method));
10
+ });
11
+ }
12
+
13
+ declare global {
14
+ // eslint-disable-next-line @typescript-eslint/no-namespace
15
+ namespace Chai {
16
+ interface Assertion extends ChaiSolidAssertions {}
17
+ interface Include extends ChaiSolidAssertions {}
18
+ }
19
+ }
@@ -19,9 +19,7 @@ export default class UnauthorizedError extends JSError {
19
19
  }
20
20
 
21
21
  public get forbidden(): boolean | undefined {
22
- return typeof this.responseStatus !== 'undefined'
23
- ? this.responseStatus === 403
24
- : undefined;
22
+ return typeof this.responseStatus !== 'undefined' ? this.responseStatus === 403 : undefined;
25
23
  }
26
24
 
27
25
  }
@@ -1,7 +1,7 @@
1
1
  import { JSError } from '@noeldemartin/utils';
2
2
 
3
3
  function getErrorMessage(messageOrResponse: string | Response, response?: Response): string {
4
- response = response ?? messageOrResponse as Response;
4
+ response = response ?? (messageOrResponse as Response);
5
5
 
6
6
  return typeof messageOrResponse === 'string'
7
7
  ? `${messageOrResponse} (returned ${response.status} status code)`
@@ -17,7 +17,7 @@ export default class UnsuccessfulRequestError extends JSError {
17
17
  constructor(messageOrResponse: string | Response, response?: Response) {
18
18
  super(getErrorMessage(messageOrResponse, response));
19
19
 
20
- this.response = response ?? messageOrResponse as Response;
20
+ this.response = response ?? (messageOrResponse as Response);
21
21
  }
22
22
 
23
23
  }
@@ -0,0 +1,221 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { FakeResponse, FakeServer } from '@noeldemartin/testing';
4
+
5
+ import { MalformedSolidDocumentError } from '@noeldemartin/solid-utils/errors';
6
+
7
+ import { fetchLoginUserProfile } from './auth';
8
+
9
+ describe('Auth helpers', () => {
10
+
11
+ it('reads NSS profiles', async () => {
12
+ // Arrange
13
+ const server = new FakeServer();
14
+ const webId = 'https://alice.solidcommunity.net/profile/card#me';
15
+
16
+ server.respondOnce(
17
+ 'https://alice.solidcommunity.net/profile/card',
18
+ FakeResponse.success(
19
+ `
20
+ @prefix foaf: <http://xmlns.com/foaf/0.1/>.
21
+ @prefix solid: <http://www.w3.org/ns/solid/terms#>.
22
+ @prefix pim: <http://www.w3.org/ns/pim/space#>.
23
+ @prefix schema: <http://schema.org/>.
24
+
25
+ <>
26
+ a foaf:PersonalProfileDocument ;
27
+ foaf:maker <#me> ;
28
+ foaf:primaryTopic <#me> .
29
+
30
+ <#me>
31
+ a foaf:Person, schema:Person ;
32
+ foaf:name "Alice" ;
33
+ pim:preferencesFile </settings/prefs.ttl> ;
34
+ pim:storage </> ;
35
+ solid:oidcIssuer <https://solidcommunity.net> ;
36
+ solid:privateTypeIndex </settings/privateTypeIndex.ttl> ;
37
+ solid:publicTypeIndex </settings/publicTypeIndex.ttl> .
38
+ `,
39
+ { 'WAC-Allow': 'user="read control write"' },
40
+ ),
41
+ );
42
+
43
+ // Act
44
+ const profile = await fetchLoginUserProfile(webId, { fetch: server.fetch });
45
+
46
+ // Assert
47
+ expect(server.getRequests()).toHaveLength(1);
48
+
49
+ expect(profile).toEqual({
50
+ webId,
51
+ name: 'Alice',
52
+ cloaked: false,
53
+ oidcIssuerUrl: 'https://solidcommunity.net',
54
+ storageUrls: ['https://alice.solidcommunity.net/'],
55
+ privateTypeIndexUrl: 'https://alice.solidcommunity.net/settings/privateTypeIndex.ttl',
56
+ publicTypeIndexUrl: 'https://alice.solidcommunity.net/settings/publicTypeIndex.ttl',
57
+ writableProfileUrl: 'https://alice.solidcommunity.net/profile/card',
58
+ });
59
+ });
60
+
61
+ it('reads ESS profiles (public)', async () => {
62
+ // Arrange
63
+ const server = new FakeServer();
64
+ const webId = 'https://id.inrupt.com/alice';
65
+
66
+ // The first request returns a 303 to `${webId}?lookup`,
67
+ // but in order to simplify mocking requests we're assuming it doesn't.
68
+ server.respondOnce(
69
+ 'https://id.inrupt.com/alice',
70
+ FakeResponse.success(`
71
+ @prefix foaf: <http://xmlns.com/foaf/0.1/>.
72
+ @prefix solid: <http://www.w3.org/ns/solid/terms#>.
73
+ @prefix pim: <http://www.w3.org/ns/pim/space#>.
74
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
75
+
76
+ <${webId}>
77
+ a foaf:Agent ;
78
+ rdfs:seeAlso <https://storage.inrupt.com/storage-hash/extendedProfile> ;
79
+ pim:storage <https://storage.inrupt.com/storage-hash/> ;
80
+ solid:oidcIssuer <https://login.inrupt.com> ;
81
+ foaf:isPrimaryTopicOf <https://storage.inrupt.com/storage-hash/extendedProfile> .
82
+ `),
83
+ );
84
+ server.respondOnce(
85
+ 'https://storage.inrupt.com/storage-hash/extendedProfile',
86
+ new FakeResponse(undefined, undefined, 401),
87
+ );
88
+
89
+ // Act
90
+ const profile = await fetchLoginUserProfile(webId, { fetch: server.fetch });
91
+
92
+ // Assert
93
+ expect(server.getRequests()).toHaveLength(2);
94
+
95
+ expect(profile).toEqual({
96
+ webId,
97
+ cloaked: true,
98
+ oidcIssuerUrl: 'https://login.inrupt.com',
99
+ storageUrls: ['https://storage.inrupt.com/storage-hash/'],
100
+ writableProfileUrl: null,
101
+ });
102
+ });
103
+
104
+ it('reads ESS profiles (authenticated)', async () => {
105
+ // Arrange
106
+ const server = new FakeServer();
107
+ const webId = 'https://id.inrupt.com/alice';
108
+
109
+ // The first request returns a 303 to `${webId}?lookup`,
110
+ // but in order to simplify mocking requests we're assuming it doesn't.
111
+ server.respondOnce(
112
+ 'https://id.inrupt.com/alice',
113
+ FakeResponse.success(`
114
+ @prefix foaf: <http://xmlns.com/foaf/0.1/>.
115
+ @prefix solid: <http://www.w3.org/ns/solid/terms#>.
116
+ @prefix pim: <http://www.w3.org/ns/pim/space#>.
117
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
118
+
119
+ <${webId}>
120
+ a foaf:Agent ;
121
+ rdfs:seeAlso <https://storage.inrupt.com/storage-hash/extendedProfile> ;
122
+ pim:storage <https://storage.inrupt.com/storage-hash/> ;
123
+ solid:oidcIssuer <https://login.inrupt.com> ;
124
+ foaf:isPrimaryTopicOf <https://storage.inrupt.com/storage-hash/extendedProfile> .
125
+ `),
126
+ );
127
+ server.respondOnce(
128
+ 'https://storage.inrupt.com/storage-hash/extendedProfile',
129
+ FakeResponse.success(
130
+ `
131
+ @prefix foaf: <http://xmlns.com/foaf/0.1/> .
132
+ @prefix schema: <http://schema.org/> .
133
+
134
+ <${webId}>
135
+ a foaf:Person, schema:Person ;
136
+ foaf:name "Alice" .
137
+
138
+ <https://storage.inrupt.com/storage-hash/extendedProfile>
139
+ a foaf:Document ;
140
+ foaf:maker <${webId}> ;
141
+ foaf:primaryTopic <${webId}> .
142
+ `,
143
+ { 'WAC-Allow': 'user="read control write"' },
144
+ ),
145
+ );
146
+
147
+ // Act
148
+ const profile = await fetchLoginUserProfile(webId, { fetch: server.fetch });
149
+
150
+ // Assert
151
+ expect(server.getRequests()).toHaveLength(2);
152
+
153
+ expect(profile).toEqual({
154
+ webId,
155
+ name: 'Alice',
156
+ cloaked: false,
157
+ oidcIssuerUrl: 'https://login.inrupt.com',
158
+ storageUrls: ['https://storage.inrupt.com/storage-hash/'],
159
+ writableProfileUrl: 'https://storage.inrupt.com/storage-hash/extendedProfile',
160
+ });
161
+ });
162
+
163
+ it('reads use.id profiles', async () => {
164
+ // Arrange
165
+ const server = new FakeServer();
166
+ const webId = 'https://use.id/alice';
167
+ const profileTurtle = `
168
+ @prefix foaf: <http://xmlns.com/foaf/0.1/>.
169
+ @prefix solid: <http://www.w3.org/ns/solid/terms#>.
170
+ @prefix pim: <http://www.w3.org/ns/pim/space#>.
171
+
172
+ <${webId}/profile>
173
+ a foaf:PersonalProfileDocument;
174
+ foaf:maker <${webId}>;
175
+ foaf:primaryTopic <${webId}>.
176
+
177
+ <${webId}>
178
+ solid:oidcIssuer <https://idp.use.id/>;
179
+ pim:storage <https://pods.use.id/storage-hash/>.
180
+ `;
181
+
182
+ // The first request returns a 303 to `${webId}/profile`,
183
+ // but in order to simplify mocking requests we're assuming it doesn't.
184
+ server.respondOnce('https://use.id/alice', FakeResponse.success(profileTurtle, { 'WAC-Allow': 'user="read"' }));
185
+ server.respondOnce(
186
+ 'https://use.id/alice/profile',
187
+ FakeResponse.success(profileTurtle, { 'WAC-Allow': 'user="read"' }),
188
+ );
189
+
190
+ // Act
191
+ const profile = await fetchLoginUserProfile(webId, { fetch: server.fetch });
192
+
193
+ // Assert
194
+ expect(server.getRequests()).toHaveLength(2);
195
+
196
+ expect(profile).toEqual({
197
+ webId,
198
+ cloaked: false,
199
+ oidcIssuerUrl: 'https://idp.use.id/',
200
+ storageUrls: ['https://pods.use.id/storage-hash/'],
201
+ writableProfileUrl: null,
202
+ });
203
+ });
204
+
205
+ it('throws errors reading required profiles', async () => {
206
+ // Arrange
207
+ const server = new FakeServer();
208
+ const webId = 'https://pod.example.com/profile/card#me';
209
+
210
+ server.respondOnce('https://pod.example.com/profile/card', FakeResponse.success('invalid turtle'));
211
+
212
+ // Act
213
+ const fetchProfile = fetchLoginUserProfile(webId, { fetch: server.fetch, required: true });
214
+
215
+ // Assert
216
+ await expect(fetchProfile).rejects.toBeInstanceOf(MalformedSolidDocumentError);
217
+
218
+ expect(server.getRequests()).toHaveLength(1);
219
+ });
220
+
221
+ });