@learncard/partner-connect 0.5.2 → 0.6.1
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 +395 -83
- package/dist/index.d.ts +257 -25
- package/dist/partner-connect.esm.js +3294 -431
- package/dist/partner-connect.esm.js.map +1 -1
- package/dist/partner-connect.js +3295 -430
- package/dist/partner-connect.js.map +1 -1
- package/dist/partner-connect.mjs +3294 -431
- package/dist/partner-connect.mjs.map +1 -1
- package/package.json +3 -2
- package/src/docs-snippets.test.ts +79 -0
- package/src/index.ts +496 -33
- package/src/mock-host.ts +2447 -523
- package/src/mock-mode.test.ts +1337 -7
- package/src/origin-resolution.test.ts +229 -0
- package/src/types.ts +130 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@learncard/partner-connect",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/learningeconomy/LearnCard"
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"author": "Learning Economy Foundation (www.learningeconomy.io)",
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@learncard/
|
|
46
|
+
"@learncard/partner-connect-core": "0.2.0",
|
|
47
|
+
"@learncard/types": "5.23.1"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@rollup/plugin-commonjs": "^22.0.2",
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/**
|
|
3
|
+
* Runs the Partner Connect code samples embedded in the docs (docs/snippets/,
|
|
4
|
+
* kept byte-identical to the pages by scripts/check-docs-snippets.mjs) in
|
|
5
|
+
* practice mode, and checks what the pages promise.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from 'node:fs';
|
|
8
|
+
import { resolve } from 'node:path';
|
|
9
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
10
|
+
|
|
11
|
+
import { createPartnerConnect } from './index';
|
|
12
|
+
import type { PartnerConnect } from './index';
|
|
13
|
+
|
|
14
|
+
const SNIPPETS = resolve(__dirname, '../../../docs/snippets');
|
|
15
|
+
const IMPORT_LINE = "import { createPartnerConnect } from '@learncard/partner-connect';";
|
|
16
|
+
|
|
17
|
+
type AsyncFn = (...args: unknown[]) => Promise<Record<string, unknown>>;
|
|
18
|
+
const AsyncFunction = Object.getPrototypeOf(async () => undefined).constructor as new (
|
|
19
|
+
...args: string[]
|
|
20
|
+
) => AsyncFn;
|
|
21
|
+
|
|
22
|
+
const clients: PartnerConnect[] = [];
|
|
23
|
+
|
|
24
|
+
const runSnippet = async (path: string, returns: string[]) => {
|
|
25
|
+
const source = readFileSync(resolve(SNIPPETS, path), 'utf8');
|
|
26
|
+
expect(source).toContain(IMPORT_LINE);
|
|
27
|
+
|
|
28
|
+
const logs: unknown[][] = [];
|
|
29
|
+
const run = new AsyncFunction(
|
|
30
|
+
'createPartnerConnect',
|
|
31
|
+
'console',
|
|
32
|
+
`${source.replace(IMPORT_LINE, '')}\nreturn { ${returns.join(', ')} };`
|
|
33
|
+
);
|
|
34
|
+
const create = (...args: Parameters<typeof createPartnerConnect>) => {
|
|
35
|
+
const client = createPartnerConnect(...args);
|
|
36
|
+
clients.push(client);
|
|
37
|
+
return client;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const values = await run(create, { log: (...args: unknown[]) => logs.push(args) });
|
|
41
|
+
return { values, logs };
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
describe('docs snippets (practice mode)', () => {
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
clients.splice(0).forEach(client => client.destroy());
|
|
47
|
+
localStorage.clear();
|
|
48
|
+
vi.restoreAllMocks();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('publish-your-app/build.ts signs in, awards an inline template, and gets consent', async () => {
|
|
52
|
+
vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
|
53
|
+
const { values } = await runSnippet('publish-your-app/build.ts', [
|
|
54
|
+
'learnCard',
|
|
55
|
+
'user',
|
|
56
|
+
'credential',
|
|
57
|
+
'granted',
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
expect((values.user as { did: string }).did).toMatch(/^did:/);
|
|
61
|
+
expect(values.credential).toMatchObject({ templateVersion: 1 });
|
|
62
|
+
expect((values.credential as { credentialUri: string }).credentialUri).toBeTruthy();
|
|
63
|
+
expect(values.granted).toBe(true);
|
|
64
|
+
|
|
65
|
+
const manifest = (values.learnCard as PartnerConnect).getCapturedManifest();
|
|
66
|
+
expect(manifest?.templates.map(template => template.alias)).toEqual(['course-complete']);
|
|
67
|
+
expect(manifest?.consentRequests).toHaveLength(1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('partner-connect/send-inline-template.ts logs a credential and template version', async () => {
|
|
71
|
+
vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
|
72
|
+
const { logs } = await runSnippet('partner-connect/send-inline-template.ts', []);
|
|
73
|
+
|
|
74
|
+
expect(logs).toHaveLength(1);
|
|
75
|
+
const [credentialUri, templateVersion] = logs[0];
|
|
76
|
+
expect(credentialUri).toBeTruthy();
|
|
77
|
+
expect(templateVersion).toBe(1);
|
|
78
|
+
});
|
|
79
|
+
});
|