@learncard/learn-cloud-plugin 2.3.39 → 2.3.40

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.
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAc5C,OAAO,EAAE,gCAAgC,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAS7E,cAAc,SAAS,CAAC;AAqCxB;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC5B,kBAAkB,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,gCAAgC,CAAC,EACxE,KAAK,MAAM,EACX,oBAAmB,MAAM,EAAO,EAChC,0BAAyB,MAAM,EAAO,EACtC,oCAAiC,KAClC,OAAO,CAAC,gBAAgB,CAwoB1B,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAc5C,OAAO,EAAE,gCAAgC,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAS7E,cAAc,SAAS,CAAC;AAqCxB;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC5B,kBAAkB,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,gCAAgC,CAAC,EACxE,KAAK,MAAM,EACX,oBAAmB,MAAM,EAAO,EAChC,0BAAyB,MAAM,EAAO,EACtC,oCAAiC,KAClC,OAAO,CAAC,gBAAgB,CAssB1B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@learncard/learn-cloud-plugin",
3
- "version": "2.3.39",
3
+ "version": "2.3.40",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -39,8 +39,8 @@
39
39
  "url": "https://github.com/learningeconomy/LearnCard/issues"
40
40
  },
41
41
  "devDependencies": {
42
- "@learncard/learn-cloud-service": "^2.5.31",
43
- "@learncard/types": "5.18.3",
42
+ "@learncard/learn-cloud-service": "^2.5.32",
43
+ "@learncard/types": "5.19.0",
44
44
  "@types/lodash": "^4.14.191",
45
45
  "@types/node": "^17.0.31",
46
46
  "aqu": "0.4.3",
@@ -50,10 +50,10 @@
50
50
  },
51
51
  "types": "./dist/index.d.ts",
52
52
  "dependencies": {
53
- "@learncard/core": "9.4.33",
54
- "@learncard/didkit-plugin": "1.9.13",
55
- "@learncard/helpers": "^1.4.1",
56
- "@learncard/learn-cloud-client": "1.6.39",
53
+ "@learncard/core": "9.4.34",
54
+ "@learncard/didkit-plugin": "1.9.14",
55
+ "@learncard/helpers": "^1.5.0",
56
+ "@learncard/learn-cloud-client": "1.6.40",
57
57
  "json-stringify-deterministic": "^1.0.8",
58
58
  "lodash": "^4.17.21",
59
59
  "pbkdf2-hmac": "^1.2.1"
package/src/plugin.ts CHANGED
@@ -77,47 +77,90 @@ export const getLearnCloudPlugin = async (
77
77
  let client = await getLearnCloudClient(url, learnCard);
78
78
 
79
79
  let dids: string[] = [learnCard.id.did()];
80
+ let didsLoaded = false;
80
81
 
81
- void client.user.getDids
82
- .query()
83
- .then(result => (dids = result))
84
- .catch(error => learnCard.debug?.('Unable to preload LearnCloud DIDs', error));
82
+ const loadDids = async (currentClient: LearnCloudClient): Promise<void> => {
83
+ if (didsLoaded) return;
85
84
 
86
- let otherClients: Record<string, LearnCloudClient> = {};
85
+ dids = await currentClient.user.getDids.query();
86
+ didsLoaded = true;
87
+ };
88
+
89
+ const otherClients = new Map<string, Promise<LearnCloudClient>>();
90
+ const learnCloudDids = new WeakMap<LearnCloudClient, Promise<string>>();
91
+
92
+ const getLearnCloudDid = (currentClient: LearnCloudClient): Promise<string> => {
93
+ let learnCloudDid = learnCloudDids.get(currentClient);
94
+
95
+ if (!learnCloudDid) {
96
+ learnCloudDid = currentClient.utilities.getDid.query();
97
+ learnCloudDids.set(currentClient, learnCloudDid);
98
+ }
87
99
 
88
- let learnCloudDid: ReturnType<typeof client.utilities.getDid.query> | undefined;
89
- const getLearnCloudDid = () => (learnCloudDid ??= client.utilities.getDid.query());
100
+ return learnCloudDid;
101
+ };
102
+
103
+ const getOtherClient = async (
104
+ otherUrl: string,
105
+ _learnCard: typeof initialLearnCard
106
+ ): Promise<LearnCloudClient> => {
107
+ const key = `${_learnCard.id.did()}\0${otherUrl}`;
108
+ let otherClient = otherClients.get(key);
90
109
 
91
- const getOtherClient = async (url: string) => {
92
- if (!otherClients[url]) otherClients[url] = await getLearnCloudClient(url, learnCard);
110
+ if (!otherClient) {
111
+ otherClient = getLearnCloudClient(otherUrl, _learnCard);
112
+ otherClients.set(key, otherClient);
113
+ }
93
114
 
94
- return otherClients[url]!;
115
+ try {
116
+ return await otherClient;
117
+ } catch (error) {
118
+ if (otherClients.get(key) === otherClient) otherClients.delete(key);
119
+
120
+ throw error;
121
+ }
95
122
  };
96
123
 
97
- const updateLearnCard = async (
124
+ let updateQueue = Promise.resolve();
125
+
126
+ const updateLearnCard = (
98
127
  _learnCard: LearnCard<any, 'id', LearnCloudPluginDependentMethods>
99
- ) => {
100
- const oldDid = learnCard.id.did();
101
- const newDid = _learnCard.id.did();
128
+ ): Promise<LearnCloudClient> => {
129
+ const update = updateQueue.then(async () => {
130
+ const oldDid = learnCard.id.did();
131
+ const newDid = _learnCard.id.did();
132
+
133
+ if (oldDid !== newDid) {
134
+ if (automaticallyAssociateDids) {
135
+ await loadDids(client);
102
136
 
103
- if (oldDid !== newDid) {
104
- if (!dids.includes(newDid) && automaticallyAssociateDids) {
105
- const presentation = await _learnCard.invoke.getDidAuthVp();
137
+ if (!dids.includes(newDid)) {
138
+ const presentation = await _learnCard.invoke.getDidAuthVp();
106
139
 
107
- await client.user.addDid.mutate({ presentation });
140
+ await client.user.addDid.mutate({ presentation });
108
141
 
109
- if (newDid.split(':')[1] === 'web') {
110
- await client.user.setPrimaryDid.mutate({ presentation });
142
+ if (newDid.split(':')[1] === 'web') {
143
+ await client.user.setPrimaryDid.mutate({ presentation });
144
+ }
145
+
146
+ dids = await client.user.getDids.query();
147
+ }
111
148
  }
112
149
 
113
- dids = await client.user.getDids.query();
150
+ client = await getLearnCloudClient(url, _learnCard);
114
151
  }
115
152
 
116
- client = await getLearnCloudClient(url, _learnCard);
117
- learnCloudDid = undefined;
118
- }
153
+ learnCard = _learnCard;
154
+
155
+ return client;
156
+ });
119
157
 
120
- learnCard = _learnCard;
158
+ updateQueue = update.then(
159
+ () => undefined,
160
+ () => undefined
161
+ );
162
+
163
+ return update;
121
164
  };
122
165
 
123
166
  return {
@@ -126,7 +169,7 @@ export const getLearnCloudPlugin = async (
126
169
  description: 'LearnCloud Integration',
127
170
  methods: {
128
171
  learnCloudCreate: async (_learnCard, document) => {
129
- await updateLearnCard(_learnCard);
172
+ const currentClient = await updateLearnCard(_learnCard);
130
173
 
131
174
  const item = await generateEncryptedRecord(
132
175
  _learnCard,
@@ -134,12 +177,16 @@ export const getLearnCloudPlugin = async (
134
177
  unencryptedCustomFields
135
178
  );
136
179
 
137
- return client.customStorage.create.mutate({
138
- item: await generateJWE(_learnCard, await getLearnCloudDid(), item),
180
+ return currentClient.customStorage.create.mutate({
181
+ item: await generateJWE(
182
+ _learnCard,
183
+ await getLearnCloudDid(currentClient),
184
+ item
185
+ ),
139
186
  });
140
187
  },
141
188
  learnCloudCreateMany: async (_learnCard, documents) => {
142
- await updateLearnCard(_learnCard);
189
+ const currentClient = await updateLearnCard(_learnCard);
143
190
 
144
191
  const items = await Promise.all(
145
192
  documents.map(async document =>
@@ -147,8 +194,12 @@ export const getLearnCloudPlugin = async (
147
194
  )
148
195
  );
149
196
 
150
- return client.customStorage.createMany.mutate({
151
- items: await generateJWE(_learnCard, await getLearnCloudDid(), items),
197
+ return currentClient.customStorage.createMany.mutate({
198
+ items: await generateJWE(
199
+ _learnCard,
200
+ await getLearnCloudDid(currentClient),
201
+ items
202
+ ),
152
203
  });
153
204
  },
154
205
  learnCloudRead: async (_learnCard, query, includeAssociatedDids) => {
@@ -182,10 +233,10 @@ export const getLearnCloudPlugin = async (
182
233
  paginationOptions,
183
234
  includeAssociatedDids
184
235
  ) => {
185
- await updateLearnCard(_learnCard);
236
+ const currentClient = await updateLearnCard(_learnCard);
186
237
 
187
238
  if (!query) {
188
- const jwe: JWE = (await client.customStorage.read.query({
239
+ const jwe: JWE = (await currentClient.customStorage.read.query({
189
240
  includeAssociatedDids,
190
241
  ...paginationOptions,
191
242
  })) as any;
@@ -219,8 +270,8 @@ export const getLearnCloudPlugin = async (
219
270
  )
220
271
  );
221
272
 
222
- const jwe: JWE = (await client.customStorage.read.query({
223
- query: await generateJWE(_learnCard, await getLearnCloudDid(), {
273
+ const jwe: JWE = (await currentClient.customStorage.read.query({
274
+ query: await generateJWE(_learnCard, await getLearnCloudDid(currentClient), {
224
275
  ...unencryptedEntries,
225
276
  ...(fields.length > 0 ? { fields: { $in: fields } } : {}),
226
277
  }),
@@ -246,9 +297,10 @@ export const getLearnCloudPlugin = async (
246
297
  };
247
298
  },
248
299
  learnCloudCount: async (_learnCard, query, includeAssociatedDids) => {
249
- await updateLearnCard(_learnCard);
300
+ const currentClient = await updateLearnCard(_learnCard);
250
301
 
251
- if (!query) return client.customStorage.count.query({ includeAssociatedDids });
302
+ if (!query)
303
+ return currentClient.customStorage.count.query({ includeAssociatedDids });
252
304
 
253
305
  const fields = await generateEncryptedFieldsArray(_learnCard, query, [
254
306
  ...unencryptedCustomFields,
@@ -261,8 +313,8 @@ export const getLearnCloudPlugin = async (
261
313
  )
262
314
  );
263
315
 
264
- return client.customStorage.count.query({
265
- query: await generateJWE(_learnCard, await getLearnCloudDid(), {
316
+ return currentClient.customStorage.count.query({
317
+ query: await generateJWE(_learnCard, await getLearnCloudDid(currentClient), {
266
318
  ...unencryptedEntries,
267
319
  ...(fields.length > 0 ? { fields: { $in: fields } } : {}),
268
320
  }),
@@ -270,19 +322,23 @@ export const getLearnCloudPlugin = async (
270
322
  });
271
323
  },
272
324
  learnCloudUpdate: async (_learnCard, query, update) => {
273
- await updateLearnCard(_learnCard);
325
+ const currentClient = await updateLearnCard(_learnCard);
274
326
 
275
327
  const documents = await _learnCard.invoke.learnCloudRead(query);
276
328
 
277
329
  const updates = await Promise.all(
278
330
  documents.map(async document =>
279
- client.customStorage.update.mutate({
280
- query: await generateJWE(_learnCard, await getLearnCloudDid(), {
281
- _id: document._id,
282
- }),
331
+ currentClient.customStorage.update.mutate({
332
+ query: await generateJWE(
333
+ _learnCard,
334
+ await getLearnCloudDid(currentClient),
335
+ {
336
+ _id: document._id,
337
+ }
338
+ ),
283
339
  update: await generateJWE(
284
340
  _learnCard,
285
- await getLearnCloudDid(),
341
+ await getLearnCloudDid(currentClient),
286
342
  await generateEncryptedRecord(
287
343
  _learnCard,
288
344
  { ...document, ...update },
@@ -296,9 +352,10 @@ export const getLearnCloudPlugin = async (
296
352
  return updates.reduce((sum, current) => current + sum, 0);
297
353
  },
298
354
  learnCloudDelete: async (_learnCard, query, includeAssociatedDids) => {
299
- await updateLearnCard(_learnCard);
355
+ const currentClient = await updateLearnCard(_learnCard);
300
356
 
301
- if (!query) return client.customStorage.delete.mutate({ includeAssociatedDids });
357
+ if (!query)
358
+ return currentClient.customStorage.delete.mutate({ includeAssociatedDids });
302
359
 
303
360
  const fields = await generateEncryptedFieldsArray(_learnCard, query, [
304
361
  ...unencryptedCustomFields,
@@ -311,8 +368,8 @@ export const getLearnCloudPlugin = async (
311
368
  )
312
369
  );
313
370
 
314
- return client.customStorage.delete.mutate({
315
- query: await generateJWE(_learnCard, await getLearnCloudDid(), {
371
+ return currentClient.customStorage.delete.mutate({
372
+ query: await generateJWE(_learnCard, await getLearnCloudDid(currentClient), {
316
373
  ...unencryptedEntries,
317
374
  ...(fields.length > 0 ? { fields: { $in: fields } } : {}),
318
375
  }),
@@ -320,7 +377,8 @@ export const getLearnCloudPlugin = async (
320
377
  });
321
378
  },
322
379
  learnCloudBatchResolve: async (_learnCard, uris) => {
323
- const results = await client.storage.batchResolve.query({ uris });
380
+ const currentClient = await updateLearnCard(_learnCard);
381
+ const results = await currentClient.storage.batchResolve.query({ uris });
324
382
 
325
383
  return Promise.all(
326
384
  results.map(async result => {
@@ -348,20 +406,21 @@ export const getLearnCloudPlugin = async (
348
406
  },
349
407
  read: {
350
408
  get: async (_learnCard, uri) => {
351
- learnCard.debug?.('LearnCloud read.get', uri);
409
+ _learnCard.debug?.('LearnCloud read.get', uri);
352
410
 
353
411
  if (!uri) return undefined;
412
+ const currentClient = await updateLearnCard(_learnCard);
354
413
 
355
414
  const parts = uri.split(':');
356
415
 
357
- learnCard.debug?.('LearnCloud read.get parts:', parts);
416
+ _learnCard.debug?.('LearnCloud read.get parts:', parts);
358
417
 
359
418
  if (parts.length !== 5) return undefined;
360
419
 
361
420
  const [lc, method, uriUrl] = parts as [string, string, string, string, string];
362
421
 
363
422
  if (lc !== 'lc' || method !== 'cloud') {
364
- learnCard.debug?.('LearnCloud read.get not cloud URI!', { lc, method });
423
+ _learnCard.debug?.('LearnCloud read.get not cloud URI!', { lc, method });
365
424
 
366
425
  return undefined;
367
426
  }
@@ -378,7 +437,7 @@ export const getLearnCloudPlugin = async (
378
437
  }://${uriUrl}`
379
438
  ).replaceAll('%3A', ':');
380
439
 
381
- learnCard.debug?.('LearnCloud read.get different LearnCloud!', {
440
+ _learnCard.debug?.('LearnCloud read.get different LearnCloud!', {
382
441
  uriUrl,
383
442
  url,
384
443
  fullUrl,
@@ -388,16 +447,16 @@ export const getLearnCloudPlugin = async (
388
447
  },
389
448
  });
390
449
 
391
- const otherClient = await getOtherClient(fullUrl);
450
+ const otherClient = await getOtherClient(fullUrl, _learnCard);
392
451
 
393
452
  try {
394
453
  const result = await otherClient.storage.resolve.query({ uri: uri });
395
454
 
396
- learnCard.debug?.('LearnCloud read.get result', result);
455
+ _learnCard.debug?.('LearnCloud read.get result', result);
397
456
 
398
457
  const decryptedResult = await _learnCard.invoke.decryptDagJwe(result);
399
458
 
400
- learnCard.debug?.('LearnCloud read.get decryptedResult', decryptedResult);
459
+ _learnCard.debug?.('LearnCloud read.get decryptedResult', decryptedResult);
401
460
 
402
461
  const parsed = await VCValidator.or(VPValidator)
403
462
  .or(StoredCredentialEnvelopeValidator)
@@ -410,13 +469,13 @@ export const getLearnCloudPlugin = async (
410
469
  }
411
470
 
412
471
  try {
413
- const result = await client.storage.resolve.query({ uri: uri });
472
+ const result = await currentClient.storage.resolve.query({ uri });
414
473
 
415
- learnCard.debug?.('LearnCloud read.get result', result);
474
+ _learnCard.debug?.('LearnCloud read.get result', result);
416
475
 
417
476
  const decryptedResult = await _learnCard.invoke.decryptDagJwe(result);
418
477
 
419
- learnCard.debug?.('LearnCloud read.get decryptedResult', decryptedResult);
478
+ _learnCard.debug?.('LearnCloud read.get decryptedResult', decryptedResult);
420
479
 
421
480
  const parsed = await VCValidator.or(VPValidator)
422
481
  .or(StoredCredentialEnvelopeValidator)
@@ -431,8 +490,9 @@ export const getLearnCloudPlugin = async (
431
490
  store: {
432
491
  upload: async (_learnCard, credential) => {
433
492
  _learnCard.debug?.("learnCard.store['LearnCard Network'].upload");
493
+ const currentClient = await updateLearnCard(_learnCard);
434
494
 
435
- return client.storage.store.mutate({
495
+ return currentClient.storage.store.mutate({
436
496
  item: normalizeEnvelopeForTransport(credential),
437
497
  });
438
498
  },
@@ -442,21 +502,23 @@ export const getLearnCloudPlugin = async (
442
502
  { recipients = [] } = { recipients: [] }
443
503
  ) => {
444
504
  _learnCard.debug?.("learnCard.store['LearnCard Network'].upload");
505
+ const currentClient = await updateLearnCard(_learnCard);
445
506
 
446
507
  const jwe = await _learnCard.invoke.createDagJwe(
447
508
  normalizeEnvelopeForTransport(credential),
448
509
  [_learnCard.id.did(), ...recipients]
449
510
  );
450
511
 
451
- return client.storage.store.mutate({ item: jwe });
512
+ return currentClient.storage.store.mutate({ item: jwe });
452
513
  },
453
514
  delete: async (_learnCard, uri) => {
454
515
  _learnCard.debug?.("learnCard.store['LearnCloud'].delete", { uri });
516
+ const currentClient = await updateLearnCard(_learnCard);
455
517
 
456
518
  let deleted = false;
457
519
 
458
520
  try {
459
- deleted = Boolean(await client.storage.delete.mutate({ uri }));
521
+ deleted = Boolean(await currentClient.storage.delete.mutate({ uri }));
460
522
  } catch (error) {
461
523
  _learnCard.debug?.('LearnCloud store.delete storage.delete failed', error);
462
524
  }
@@ -500,7 +562,7 @@ export const getLearnCloudPlugin = async (
500
562
  return records;
501
563
  },
502
564
  getPage: async (_learnCard, query, paginationOptions) => {
503
- await updateLearnCard(_learnCard);
565
+ const currentClient = await updateLearnCard(_learnCard);
504
566
 
505
567
  _learnCard.debug?.('LearnCloud index.getPaginated', query, paginationOptions);
506
568
 
@@ -513,7 +575,7 @@ export const getLearnCloudPlugin = async (
513
575
 
514
576
  if (!query) {
515
577
  _learnCard.debug?.('LearnCloud index.get (no query)');
516
- const jwe: JWE = (await client.index.get.query(options)) as any;
578
+ const jwe = await currentClient.index.get.query(options);
517
579
 
518
580
  _learnCard.debug?.('LearnCloud index.get (no query response)', jwe);
519
581
 
@@ -555,8 +617,8 @@ export const getLearnCloudPlugin = async (
555
617
  unencryptedEntries
556
618
  );
557
619
 
558
- const jwe: JWE = (await client.index.get.query({
559
- query: await generateJWE(_learnCard, await getLearnCloudDid(), {
620
+ const jwe: JWE = (await currentClient.index.get.query({
621
+ query: await generateJWE(_learnCard, await getLearnCloudDid(currentClient), {
560
622
  ...unencryptedEntries,
561
623
  ...(fields.length > 0 ? { fields: { $in: fields } } : {}),
562
624
  }),
@@ -584,11 +646,11 @@ export const getLearnCloudPlugin = async (
584
646
  };
585
647
  },
586
648
  getCount: async (_learnCard, query) => {
587
- await updateLearnCard(_learnCard);
649
+ const currentClient = await updateLearnCard(_learnCard);
588
650
 
589
651
  if (!query) {
590
652
  _learnCard.debug?.('LearnCloud index.count (no query)');
591
- const jwe = await client.index.count.query();
653
+ const jwe = await currentClient.index.count.query();
592
654
 
593
655
  _learnCard.debug?.('LearnCloud index.count (no query response)', jwe);
594
656
 
@@ -620,8 +682,8 @@ export const getLearnCloudPlugin = async (
620
682
  unencryptedEntries
621
683
  );
622
684
 
623
- const jwe = await client.index.count.query({
624
- query: await generateJWE(_learnCard, await getLearnCloudDid(), {
685
+ const jwe = await currentClient.index.count.query({
686
+ query: await generateJWE(_learnCard, await getLearnCloudDid(currentClient), {
625
687
  ...unencryptedEntries,
626
688
  ...(fields.length > 0 ? { fields: { $in: fields } } : {}),
627
689
  }),
@@ -638,12 +700,12 @@ export const getLearnCloudPlugin = async (
638
700
  return count;
639
701
  },
640
702
  add: async (_learnCard, record) => {
641
- await updateLearnCard(_learnCard);
703
+ const currentClient = await updateLearnCard(_learnCard);
642
704
 
643
705
  const id = record.id || _learnCard.invoke.crypto().randomUUID();
644
706
 
645
- return client.index.add.mutate({
646
- record: await generateJWE(_learnCard, await getLearnCloudDid(), {
707
+ return currentClient.index.add.mutate({
708
+ record: await generateJWE(_learnCard, await getLearnCloudDid(currentClient), {
647
709
  ...(await generateEncryptedRecord(
648
710
  _learnCard,
649
711
  { ...record, id },
@@ -654,7 +716,7 @@ export const getLearnCloudPlugin = async (
654
716
  });
655
717
  },
656
718
  addMany: async (_learnCard, _records) => {
657
- await updateLearnCard(_learnCard);
719
+ const currentClient = await updateLearnCard(_learnCard);
658
720
 
659
721
  const results = await Promise.all(
660
722
  chunk(_records, 25).map(async batch => {
@@ -673,10 +735,10 @@ export const getLearnCloudPlugin = async (
673
735
  })
674
736
  );
675
737
 
676
- return client.index.addMany.mutate({
738
+ return currentClient.index.addMany.mutate({
677
739
  records: await generateJWE(
678
740
  _learnCard,
679
- await getLearnCloudDid(),
741
+ await getLearnCloudDid(currentClient),
680
742
  records
681
743
  ),
682
744
  });
@@ -686,7 +748,7 @@ export const getLearnCloudPlugin = async (
686
748
  return results.every(Boolean);
687
749
  },
688
750
  update: async (_learnCard, id, updates) => {
689
- await updateLearnCard(_learnCard);
751
+ const currentClient = await updateLearnCard(_learnCard);
690
752
 
691
753
  const records = await _learnCard.index.LearnCloud.get({ id });
692
754
 
@@ -696,24 +758,24 @@ export const getLearnCloudPlugin = async (
696
758
 
697
759
  const newRecord = { ...record, ...updates };
698
760
 
699
- return client.index.update.mutate({
761
+ return currentClient.index.update.mutate({
700
762
  id: await hash(_learnCard, id),
701
763
  updates: await generateJWE(
702
764
  _learnCard,
703
- await getLearnCloudDid(),
765
+ await getLearnCloudDid(currentClient),
704
766
  await generateEncryptedRecord(_learnCard, newRecord, unencryptedFields)
705
767
  ),
706
768
  });
707
769
  },
708
770
  remove: async (_learnCard, id) => {
709
- await updateLearnCard(_learnCard);
771
+ const currentClient = await updateLearnCard(_learnCard);
710
772
 
711
- return client.index.remove.mutate({ id: await hash(_learnCard, id) });
773
+ return currentClient.index.remove.mutate({ id: await hash(_learnCard, id) });
712
774
  },
713
775
  removeAll: async _learnCard => {
714
- await updateLearnCard(_learnCard);
776
+ const currentClient = await updateLearnCard(_learnCard);
715
777
 
716
- return client.index.removeAll.mutate();
778
+ return currentClient.index.removeAll.mutate();
717
779
  },
718
780
  },
719
781
  };