@learncard/lca-api-plugin 1.2.23 → 2.0.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.
@@ -0,0 +1 @@
1
+ export {};
package/dist/types.d.ts CHANGED
@@ -72,8 +72,8 @@ export declare const SigningAuthorityValidator: z.ZodObject<{
72
72
  _id: z.ZodOptional<z.ZodString>;
73
73
  ownerDid: z.ZodString;
74
74
  name: z.ZodString;
75
- did: z.ZodOptional<z.ZodString>;
76
- endpoint: z.ZodOptional<z.ZodString>;
75
+ did: z.ZodString;
76
+ endpoint: z.ZodString;
77
77
  }, z.core.$strip>;
78
78
  /** @group LCA API Plugin */
79
79
  export type SigningAuthorityType = z.infer<typeof SigningAuthorityValidator>;
@@ -346,7 +346,12 @@ export declare const NotificationValidator: z.ZodObject<{
346
346
  }, z.core.$strip>;
347
347
  timestamp: z.ZodOptional<z.ZodISODateTime>;
348
348
  }, z.core.$strip>>;
349
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
349
+ metadata: z.ZodOptional<z.ZodObject<{
350
+ connectionPrompt: z.ZodOptional<z.ZodObject<{
351
+ promptId: z.ZodString;
352
+ counterpartProfileId: z.ZodString;
353
+ }, z.core.$strip>>;
354
+ }, z.core.$catchall<z.ZodUnknown>>>;
350
355
  }, z.core.$loose>>;
351
356
  sent: z.ZodOptional<z.ZodISODateTime>;
352
357
  webhookUrl: z.ZodOptional<z.ZodString>;
@@ -547,7 +552,12 @@ export declare const PaginatedNotificationsValidator: z.ZodObject<{
547
552
  }, z.core.$strip>;
548
553
  timestamp: z.ZodOptional<z.ZodISODateTime>;
549
554
  }, z.core.$strip>>;
550
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
555
+ metadata: z.ZodOptional<z.ZodObject<{
556
+ connectionPrompt: z.ZodOptional<z.ZodObject<{
557
+ promptId: z.ZodString;
558
+ counterpartProfileId: z.ZodString;
559
+ }, z.core.$strip>>;
560
+ }, z.core.$catchall<z.ZodUnknown>>>;
551
561
  }, z.core.$loose>>;
552
562
  sent: z.ZodOptional<z.ZodISODateTime>;
553
563
  webhookUrl: z.ZodOptional<z.ZodString>;
@@ -727,7 +737,7 @@ export type LCAPluginMethods = {
727
737
  getSigningAuthorities: () => Promise<SigningAuthorityType[] | false>;
728
738
  authorizeSigningAuthority: (name: string, authorization: SigningAuthorityAuthorization) => Promise<boolean>;
729
739
  resetLCAClient: () => Promise<void>;
730
- generateBoostInfo: (description: string) => Promise<{
740
+ generateBoostInfo: (description: string, locale?: string) => Promise<{
731
741
  title: string;
732
742
  description: string;
733
743
  category: string;
@@ -800,5 +810,8 @@ export type LCAPluginMethods = {
800
810
  }>;
801
811
  };
802
812
  /** @group LearnCardNetwork Plugin */
803
- export type LCAPlugin = Plugin<'LearnCard App', never, LCAPluginMethods, 'id', LCAPluginDependentMethods>;
813
+ export type LCAPlugin = Plugin<'LearnCard App', never, LCAPluginMethods, 'id', LCAPluginDependentMethods> & {
814
+ /** Whether the plugin fell back because its initial LCA API setup failed. */
815
+ isOffline: boolean;
816
+ };
804
817
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@learncard/lca-api-plugin",
3
- "version": "1.2.23",
3
+ "version": "2.0.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -24,9 +24,9 @@
24
24
  ],
25
25
  "scripts": {
26
26
  "build": "node ./scripts/build.mjs && shx cp ./scripts/mixedEntypoint.js ./dist/index.cjs && tsc --p tsconfig.json && shx cp ./dist/index.d.ts ./dist/index.d.cts",
27
- "test": "jest",
28
- "test:watch": "jest --watch",
29
- "test:coverage": "jest --silent --ci --coverage --coverageReporters=\"text\" --coverageReporters=\"text-summary\""
27
+ "test": "vitest run",
28
+ "test:watch": "vitest",
29
+ "test:coverage": "vitest run --coverage"
30
30
  },
31
31
  "author": "WeLibrary, LLC (www.welibrary.io)",
32
32
  "license": "MIT",
@@ -39,24 +39,20 @@
39
39
  "url": "https://github.com/learningeconomy/LearnCard/issues"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/jest": "^29.2.2",
43
42
  "@types/node": "^17.0.31",
44
43
  "aqu": "0.4.3",
45
44
  "esbuild": "^0.27.1",
46
- "esbuild-jest": "^0.5.0",
47
45
  "esbuild-plugin-copy": "^1.3.0",
48
- "jest": "^29.3.0",
49
46
  "rimraf": "^3.0.2",
50
- "shx": "^0.3.4",
51
- "ts-jest": "^29.0.3"
47
+ "shx": "^0.3.4"
52
48
  },
53
49
  "types": "./dist/index.d.ts",
54
50
  "dependencies": {
55
- "@learncard/core": "9.4.29",
56
- "@learncard/didkit-plugin": "1.9.9",
57
- "@learncard/init": "2.4.10",
58
- "@learncard/lca-api-client": "1.2.3",
59
- "@learncard/types": "5.18.1",
51
+ "@learncard/core": "9.4.31",
52
+ "@learncard/didkit-plugin": "1.9.11",
53
+ "@learncard/init": "2.4.12",
54
+ "@learncard/lca-api-client": "1.2.4",
55
+ "@learncard/types": "5.18.2",
60
56
  "hex-lite": "^1.5.0",
61
57
  "isomorphic-fetch": "^3.0.0",
62
58
  "isomorphic-webcrypto": "^2.3.8",
package/src/plugin.ts CHANGED
@@ -114,6 +114,7 @@ export const getLCAPlugin = async (
114
114
 
115
115
  return {
116
116
  name: 'LearnCard App',
117
+ isOffline: false,
117
118
  displayName: 'LearnCard App Plugin',
118
119
  description: 'Adds bespoke logic to the LearnCard App.',
119
120
  methods: {
@@ -199,11 +200,14 @@ export const getLCAPlugin = async (
199
200
  client = await getNewClient(url, _learnCard);
200
201
  learnCard = _learnCard;
201
202
  },
202
- generateBoostInfo: async (_learnCard, description) => {
203
+ generateBoostInfo: async (_learnCard, description, locale) => {
203
204
  await initialized;
204
205
  await updateLearnCard(_learnCard);
205
206
 
206
- const result = await client.ai.generateBoostInfo.query({ description });
207
+ const result = await client.ai.generateBoostInfo.query({
208
+ description,
209
+ locale,
210
+ });
207
211
 
208
212
  return {
209
213
  title: result.title,
@@ -548,6 +552,7 @@ export const getLCAPlugin = async (
548
552
  );
549
553
  return {
550
554
  name: 'LearnCard App',
555
+ isOffline: true,
551
556
  displayName: 'LearnCard App Plugin (Offline)',
552
557
  description: 'Adds bespoke logic to the LearnCard App. (Unable to connect to LCA API)',
553
558
  methods: {
@@ -0,0 +1,41 @@
1
+ import { vi } from 'vitest';
2
+ import { getClient } from '@learncard/lca-api-client';
3
+
4
+ import { getLCAPlugin } from '../plugin';
5
+
6
+ vi.mock('@learncard/lca-api-client', () => ({ getClient: vi.fn() }));
7
+
8
+ const mockedGetClient = vi.mocked(getClient);
9
+
10
+ const learnCard = {
11
+ id: { did: () => 'did:key:z6MkTest' },
12
+ invoke: { getProfile: () => new Promise<never>(() => undefined) },
13
+ };
14
+
15
+ describe('getLCAPlugin', () => {
16
+ beforeEach(() => {
17
+ mockedGetClient.mockReset();
18
+ });
19
+
20
+ it('reports when initial setup falls back to offline mode', async () => {
21
+ const consoleError = vi.spyOn(console, 'error').mockImplementation(() => undefined);
22
+
23
+ try {
24
+ mockedGetClient.mockRejectedValueOnce(new Error('connection failed'));
25
+
26
+ const plugin = await getLCAPlugin(learnCard as never, 'https://example.com/trpc');
27
+
28
+ expect(plugin.isOffline).toBe(true);
29
+ } finally {
30
+ consoleError.mockRestore();
31
+ }
32
+ });
33
+
34
+ it('reports when initial setup remains online', async () => {
35
+ mockedGetClient.mockResolvedValueOnce({} as never);
36
+
37
+ const plugin = await getLCAPlugin(learnCard as never, 'https://example.com/trpc');
38
+
39
+ expect(plugin.isOffline).toBe(false);
40
+ });
41
+ });
package/src/types.ts CHANGED
@@ -92,8 +92,8 @@ export const SigningAuthorityValidator = z.object({
92
92
  _id: z.string().optional(),
93
93
  ownerDid: z.string(),
94
94
  name: z.string(),
95
- did: z.string().optional(),
96
- endpoint: z.string().optional(),
95
+ did: z.string(),
96
+ endpoint: z.string(),
97
97
  });
98
98
 
99
99
  /** @group LCA API Plugin */
@@ -293,7 +293,10 @@ export type LCAPluginMethods = {
293
293
  authorization: SigningAuthorityAuthorization
294
294
  ) => Promise<boolean>;
295
295
  resetLCAClient: () => Promise<void>;
296
- generateBoostInfo: (description: string) => Promise<{
296
+ generateBoostInfo: (
297
+ description: string,
298
+ locale?: string
299
+ ) => Promise<{
297
300
  title: string;
298
301
  description: string;
299
302
  category: string;
@@ -396,4 +399,7 @@ export type LCAPlugin = Plugin<
396
399
  LCAPluginMethods,
397
400
  'id',
398
401
  LCAPluginDependentMethods
399
- >;
402
+ > & {
403
+ /** Whether the plugin fell back because its initial LCA API setup failed. */
404
+ isOffline: boolean;
405
+ };