@learncard/core 8.1.1 → 8.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/core.cjs.development.js +103 -9
- package/dist/core.cjs.development.js.map +4 -4
- package/dist/core.cjs.production.min.js +64 -64
- package/dist/core.cjs.production.min.js.map +4 -4
- package/dist/core.d.ts +4 -1
- package/dist/core.esm.js +103 -9
- package/dist/core.esm.js.map +4 -4
- package/package.json +5 -5
@@ -7128,10 +7128,10 @@ var require_lodash = __commonJS({
|
|
7128
7128
|
return array && array.length ? baseUniq(array) : [];
|
7129
7129
|
}
|
7130
7130
|
__name(uniq, "uniq");
|
7131
|
-
function
|
7131
|
+
function uniqBy2(array, iteratee2) {
|
7132
7132
|
return array && array.length ? baseUniq(array, getIteratee(iteratee2, 2)) : [];
|
7133
7133
|
}
|
7134
|
-
__name(
|
7134
|
+
__name(uniqBy2, "uniqBy");
|
7135
7135
|
function uniqWith(array, comparator) {
|
7136
7136
|
comparator = typeof comparator == "function" ? comparator : undefined2;
|
7137
7137
|
return array && array.length ? baseUniq(array, undefined2, comparator) : [];
|
@@ -8971,7 +8971,7 @@ var require_lodash = __commonJS({
|
|
8971
8971
|
lodash.unionBy = unionBy;
|
8972
8972
|
lodash.unionWith = unionWith;
|
8973
8973
|
lodash.uniq = uniq;
|
8974
|
-
lodash.uniqBy =
|
8974
|
+
lodash.uniqBy = uniqBy2;
|
8975
8975
|
lodash.uniqWith = uniqWith;
|
8976
8976
|
lodash.unset = unset;
|
8977
8977
|
lodash.unzip = unzip;
|
@@ -46186,6 +46186,7 @@ __export(src_exports2, {
|
|
46186
46186
|
getEthereumPlugin: () => getEthereumPlugin,
|
46187
46187
|
getIDXPlugin: () => getIDXPlugin,
|
46188
46188
|
getTestCache: () => getTestCache,
|
46189
|
+
getTestStorage: () => getTestStorage,
|
46189
46190
|
getVCAPIPlugin: () => getVCAPIPlugin,
|
46190
46191
|
getVCPlugin: () => getVCPlugin,
|
46191
46192
|
getVCTemplatesPlugin: () => getVCTemplatesPlugin,
|
@@ -46238,6 +46239,12 @@ var mapObject = /* @__PURE__ */ __name((obj, callback) => {
|
|
46238
46239
|
Object.entries(obj).map(([key2, value], index) => [key2, callback(value, index)])
|
46239
46240
|
);
|
46240
46241
|
}, "mapObject");
|
46242
|
+
var isFulfilledAndNotEmpty = /* @__PURE__ */ __name((input) => input.status === "fulfilled" && !!input.value, "isFulfilledAndNotEmpty");
|
46243
|
+
var uniqBy = /* @__PURE__ */ __name((array, key2) => {
|
46244
|
+
return [
|
46245
|
+
...new Map(array.map((obj) => [key2 instanceof Function ? key2(obj) : obj[key2], obj])).values()
|
46246
|
+
];
|
46247
|
+
}, "uniqBy");
|
46241
46248
|
|
46242
46249
|
// src/wallet/base/wallet.ts
|
46243
46250
|
var getPlaneProviders = /* @__PURE__ */ __name((plugins, plane) => {
|
@@ -46278,7 +46285,7 @@ var generateReadPlane = /* @__PURE__ */ __name((learnCard) => {
|
|
46278
46285
|
return cachedResponse;
|
46279
46286
|
}
|
46280
46287
|
}
|
46281
|
-
const
|
46288
|
+
const results = await Promise.allSettled(
|
46282
46289
|
learnCard.plugins.map(async (plugin) => {
|
46283
46290
|
if (!pluginImplementsPlane(plugin, "read")) {
|
46284
46291
|
throw new Error("Plugin is not a Read Plugin");
|
@@ -46286,6 +46293,7 @@ var generateReadPlane = /* @__PURE__ */ __name((learnCard) => {
|
|
46286
46293
|
return plugin.read.get(learnCard, uri);
|
46287
46294
|
})
|
46288
46295
|
);
|
46296
|
+
const vc = results.find(isFulfilledAndNotEmpty)?.value;
|
46289
46297
|
if (vc && learnCardImplementsPlane(learnCard, "cache") && cache !== "skip-cache") {
|
46290
46298
|
await learnCard.cache.setVc(uri, vc);
|
46291
46299
|
}
|
@@ -46351,6 +46359,14 @@ var addCachingToIndexPlane = /* @__PURE__ */ __name((plane, name5) => ({
|
|
46351
46359
|
}
|
46352
46360
|
return plane.add(_learnCard, record);
|
46353
46361
|
},
|
46362
|
+
...plane.addMany ? {
|
46363
|
+
addMany: async (_learnCard, records, { cache = "cache-first" } = {}) => {
|
46364
|
+
if (cache !== "skip-cache" && learnCardImplementsPlane(_learnCard, "cache")) {
|
46365
|
+
await _learnCard.cache.flushIndex();
|
46366
|
+
}
|
46367
|
+
return plane.addMany?.(_learnCard, records);
|
46368
|
+
}
|
46369
|
+
} : {},
|
46354
46370
|
update: async (_learnCard, id, update2, { cache = "cache-first" } = {}) => {
|
46355
46371
|
if (cache !== "skip-cache" && learnCardImplementsPlane(_learnCard, "cache")) {
|
46356
46372
|
await _learnCard.cache.flushIndex();
|
@@ -46407,7 +46423,7 @@ var generateIndexPlane = /* @__PURE__ */ __name((learnCard) => {
|
|
46407
46423
|
return plugin.index.get(learnCard, query);
|
46408
46424
|
})
|
46409
46425
|
)).flat();
|
46410
|
-
const results =
|
46426
|
+
const results = uniqBy(resultsWithDuplicates, "id");
|
46411
46427
|
if (results && learnCardImplementsPlane(learnCard, "cache") && cache !== "skip-cache") {
|
46412
46428
|
await learnCard.cache.setIndex("all", query ?? {}, results);
|
46413
46429
|
}
|
@@ -46421,7 +46437,7 @@ var generateCachePlane = /* @__PURE__ */ __name((learnCard) => {
|
|
46421
46437
|
getIndex: async (name5, query) => {
|
46422
46438
|
learnCard.debug?.("learnCard.cache.getIndex");
|
46423
46439
|
try {
|
46424
|
-
const
|
46440
|
+
const results = await Promise.allSettled(
|
46425
46441
|
learnCard.plugins.map(async (plugin) => {
|
46426
46442
|
if (!pluginImplementsPlane(plugin, "cache")) {
|
46427
46443
|
throw new Error("Plugin is not a Cache Plugin");
|
@@ -46429,6 +46445,7 @@ var generateCachePlane = /* @__PURE__ */ __name((learnCard) => {
|
|
46429
46445
|
return plugin.cache.getIndex(learnCard, name5, query);
|
46430
46446
|
})
|
46431
46447
|
);
|
46448
|
+
const index = results.find(isFulfilledAndNotEmpty)?.value;
|
46432
46449
|
return index;
|
46433
46450
|
} catch (error) {
|
46434
46451
|
return void 0;
|
@@ -46461,7 +46478,7 @@ var generateCachePlane = /* @__PURE__ */ __name((learnCard) => {
|
|
46461
46478
|
getVc: async (uri) => {
|
46462
46479
|
learnCard.debug?.("learnCard.cache.getVc");
|
46463
46480
|
try {
|
46464
|
-
const
|
46481
|
+
const results = await Promise.allSettled(
|
46465
46482
|
learnCard.plugins.map(async (plugin) => {
|
46466
46483
|
if (!pluginImplementsPlane(plugin, "cache")) {
|
46467
46484
|
throw new Error("Plugin is not a Cache Plugin");
|
@@ -46469,6 +46486,7 @@ var generateCachePlane = /* @__PURE__ */ __name((learnCard) => {
|
|
46469
46486
|
return plugin.cache.getVc(learnCard, uri);
|
46470
46487
|
})
|
46471
46488
|
);
|
46489
|
+
const vc = results.find(isFulfilledAndNotEmpty)?.value;
|
46472
46490
|
return vc;
|
46473
46491
|
} catch (error) {
|
46474
46492
|
return void 0;
|
@@ -67672,8 +67690,8 @@ var getIDXPlugin = /* @__PURE__ */ __name(async (learnCard, { modelData, credent
|
|
67672
67690
|
alias = credentialAlias;
|
67673
67691
|
return dataStore.set(alias, { credentials: [] });
|
67674
67692
|
}, "removeAllCredentialsFromIdx");
|
67675
|
-
const addCredentialInIdx = /* @__PURE__ */ __name(async (
|
67676
|
-
const record = CredentialRecordValidator.
|
67693
|
+
const addCredentialInIdx = /* @__PURE__ */ __name(async (_record) => {
|
67694
|
+
const record = await CredentialRecordValidator.parseAsync(_record);
|
67677
67695
|
if (!record)
|
67678
67696
|
throw new Error("record is required");
|
67679
67697
|
if (!record.uri)
|
@@ -67689,6 +67707,23 @@ var getIDXPlugin = /* @__PURE__ */ __name(async (learnCard, { modelData, credent
|
|
67689
67707
|
existing.credentials.push(record);
|
67690
67708
|
return streamIdToCeramicURI(await dataStore.set(credentialAlias, existing));
|
67691
67709
|
}, "addCredentialInIdx");
|
67710
|
+
const addCredentialsInIdx = /* @__PURE__ */ __name(async (_records) => {
|
67711
|
+
const records = CredentialRecordValidator.array().parse(_records);
|
67712
|
+
const existing = await getCredentialsListFromIdx(credentialAlias);
|
67713
|
+
await Promise.all(
|
67714
|
+
records.map(async (record) => {
|
67715
|
+
await learnCard.read.get(record.uri);
|
67716
|
+
const indexOfExistingCredential = existing.credentials.findIndex((credential) => {
|
67717
|
+
return credential.id === record.id;
|
67718
|
+
});
|
67719
|
+
if (indexOfExistingCredential > -1) {
|
67720
|
+
existing.credentials[indexOfExistingCredential] = record;
|
67721
|
+
} else
|
67722
|
+
existing.credentials.push(record);
|
67723
|
+
})
|
67724
|
+
);
|
67725
|
+
return streamIdToCeramicURI(await dataStore.set(credentialAlias, existing));
|
67726
|
+
}, "addCredentialsInIdx");
|
67692
67727
|
return {
|
67693
67728
|
name: "IDX",
|
67694
67729
|
displayName: "IDX",
|
@@ -67709,6 +67744,16 @@ var getIDXPlugin = /* @__PURE__ */ __name(async (learnCard, { modelData, credent
|
|
67709
67744
|
return false;
|
67710
67745
|
}
|
67711
67746
|
},
|
67747
|
+
addMany: async (_learnCard, records) => {
|
67748
|
+
_learnCard.debug?.("learnCard.index.IDX.add");
|
67749
|
+
try {
|
67750
|
+
await addCredentialsInIdx(records);
|
67751
|
+
return true;
|
67752
|
+
} catch (error) {
|
67753
|
+
console.error("Error adding credential with IDX:", error);
|
67754
|
+
return false;
|
67755
|
+
}
|
67756
|
+
},
|
67712
67757
|
update: async (_learnCard) => {
|
67713
67758
|
_learnCard.debug?.("learnCard.index.IDX.update");
|
67714
67759
|
return false;
|
@@ -71386,6 +71431,55 @@ var getTestCache = /* @__PURE__ */ __name(() => {
|
|
71386
71431
|
methods: {}
|
71387
71432
|
};
|
71388
71433
|
}, "getTestCache");
|
71434
|
+
|
71435
|
+
// src/wallet/plugins/test-storage/index.ts
|
71436
|
+
var getTestStorage = /* @__PURE__ */ __name(() => {
|
71437
|
+
let index = [];
|
71438
|
+
let vcs = [];
|
71439
|
+
return {
|
71440
|
+
name: "Test Storage",
|
71441
|
+
displayName: "Test Storage",
|
71442
|
+
description: "[Testing] Tests Storage Implementations",
|
71443
|
+
read: {
|
71444
|
+
get: async (_learnCard, uri) => {
|
71445
|
+
_learnCard.debug?.("Test Storage, read, get", { uri });
|
71446
|
+
if (!uri)
|
71447
|
+
return void 0;
|
71448
|
+
const [_lc, method, vcIndex] = uri.split(":");
|
71449
|
+
if (method !== "test")
|
71450
|
+
return void 0;
|
71451
|
+
return vcs[Number.parseInt(vcIndex)];
|
71452
|
+
}
|
71453
|
+
},
|
71454
|
+
store: {
|
71455
|
+
upload: async (_learnCard, vc) => {
|
71456
|
+
_learnCard.debug?.("Test Storage, store, upload", { vc });
|
71457
|
+
const vcIndex = vcs.length;
|
71458
|
+
vcs.push(vc);
|
71459
|
+
return `lc:test:${vcIndex}`;
|
71460
|
+
}
|
71461
|
+
},
|
71462
|
+
index: {
|
71463
|
+
get: async (_learnCard, query) => {
|
71464
|
+
_learnCard.debug?.("Test Storage, index, get", { query });
|
71465
|
+
return index;
|
71466
|
+
},
|
71467
|
+
add: async (_learnCard, record) => {
|
71468
|
+
_learnCard.debug?.("Test Storage, index, add", { record });
|
71469
|
+
index.push(record);
|
71470
|
+
return true;
|
71471
|
+
},
|
71472
|
+
update: async () => false,
|
71473
|
+
remove: async (_learnCard, id) => {
|
71474
|
+
_learnCard.debug?.("Test Storage, index, remove", { id });
|
71475
|
+
let recordIndex = index.findIndex((record) => record.id === id);
|
71476
|
+
index.splice(recordIndex, 1);
|
71477
|
+
return true;
|
71478
|
+
}
|
71479
|
+
},
|
71480
|
+
methods: {}
|
71481
|
+
};
|
71482
|
+
}, "getTestStorage");
|
71389
71483
|
/*!
|
71390
71484
|
* A CredentialHandlerRegistration provides a CredentialManager to enable Web
|
71391
71485
|
* apps to register Profiles that can be presented to websites.
|