@prosopo/database 3.5.5 → 3.5.6

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,48 @@
1
+
2
+ > @prosopo/database@3.5.6 build:cjs
3
+ > NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV
4
+
5
+ ViteCommonJSConfig: .
6
+ {
7
+ tsConfigPaths: [
8
+ '/home/runner/work/captcha/captcha/packages/common/tsconfig.json',
9
+ '/home/runner/work/captcha/captcha/packages/locale/tsconfig.json',
10
+ '/home/runner/work/captcha/captcha/packages/types/tsconfig.json',
11
+ '/home/runner/work/captcha/captcha/packages/util/tsconfig.json',
12
+ '/home/runner/work/captcha/captcha/packages/util-crypto/tsconfig.json',
13
+ '/home/runner/work/captcha/captcha/packages/types-database/tsconfig.json',
14
+ '/home/runner/work/captcha/captcha/packages/user-access-policy/tsconfig.json',
15
+ '/home/runner/work/captcha/captcha/packages/api-route/tsconfig.json',
16
+ '/home/runner/work/captcha/captcha/packages/redis-client/tsconfig.json',
17
+ '/home/runner/work/captcha/captcha/packages/api/tsconfig.json'
18
+ ]
19
+ }
20
+ {
21
+ externals: [
22
+ '@prosopo/common',
23
+ '@prosopo/locale',
24
+ '@prosopo/types',
25
+ '@prosopo/util',
26
+ '@prosopo/util-crypto',
27
+ '@prosopo/types-database',
28
+ '@prosopo/user-access-policy',
29
+ '@prosopo/api-route',
30
+ '@prosopo/redis-client',
31
+ '@prosopo/api'
32
+ ]
33
+ }
34
+ vite v6.4.1 building SSR bundle for production...
35
+ Bundle build started
36
+ transforming...
37
+ Build end
38
+ ✓ 8 modules transformed.
39
+ rendering chunks...
40
+ dist/cjs/base/index.cjs  0.28 kB
41
+ dist/cjs/base/mongoMemory.cjs  0.71 kB
42
+ dist/cjs/index.cjs  0.78 kB
43
+ dist/cjs/databases/index.cjs  0.89 kB
44
+ dist/cjs/databases/client.cjs  1.91 kB
45
+ dist/cjs/base/mongo.cjs  4.48 kB
46
+ dist/cjs/databases/captcha.cjs  5.82 kB
47
+ dist/cjs/databases/provider.cjs 43.19 kB
48
+ ✓ built in 227ms
@@ -0,0 +1,48 @@
1
+
2
+ > @prosopo/database@3.5.6 build
3
+ > NODE_ENV=${NODE_ENV:-development}; vite build --config vite.esm.config.ts --mode $NODE_ENV
4
+
5
+ ViteEsmConfig: .
6
+ {
7
+ tsConfigPaths: [
8
+ '/home/runner/work/captcha/captcha/packages/common/tsconfig.json',
9
+ '/home/runner/work/captcha/captcha/packages/locale/tsconfig.json',
10
+ '/home/runner/work/captcha/captcha/packages/types/tsconfig.json',
11
+ '/home/runner/work/captcha/captcha/packages/util/tsconfig.json',
12
+ '/home/runner/work/captcha/captcha/packages/util-crypto/tsconfig.json',
13
+ '/home/runner/work/captcha/captcha/packages/types-database/tsconfig.json',
14
+ '/home/runner/work/captcha/captcha/packages/user-access-policy/tsconfig.json',
15
+ '/home/runner/work/captcha/captcha/packages/api-route/tsconfig.json',
16
+ '/home/runner/work/captcha/captcha/packages/redis-client/tsconfig.json',
17
+ '/home/runner/work/captcha/captcha/packages/api/tsconfig.json'
18
+ ]
19
+ }
20
+ {
21
+ externals: [
22
+ '@prosopo/common',
23
+ '@prosopo/locale',
24
+ '@prosopo/types',
25
+ '@prosopo/util',
26
+ '@prosopo/util-crypto',
27
+ '@prosopo/types-database',
28
+ '@prosopo/user-access-policy',
29
+ '@prosopo/api-route',
30
+ '@prosopo/redis-client',
31
+ '@prosopo/api'
32
+ ]
33
+ }
34
+ vite v6.4.1 building SSR bundle for production...
35
+ Bundle build started
36
+ transforming...
37
+ Build end
38
+ ✓ 8 modules transformed.
39
+ rendering chunks...
40
+ dist/base/index.js  0.15 kB
41
+ dist/index.js  0.54 kB
42
+ dist/base/mongoMemory.js  0.59 kB
43
+ dist/databases/index.js  0.67 kB
44
+ dist/databases/client.js  1.79 kB
45
+ dist/base/mongo.js  4.06 kB
46
+ dist/databases/captcha.js  5.41 kB
47
+ dist/databases/provider.js 42.97 kB
48
+ ✓ built in 412ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @prosopo/database
2
2
 
3
+ ## 3.5.6
4
+ ### Patch Changes
5
+
6
+ - 7d5eb3f: bump
7
+ - Updated dependencies [7d5eb3f]
8
+ - @prosopo/common@3.1.26
9
+ - @prosopo/locale@3.1.26
10
+ - @prosopo/redis-client@1.0.11
11
+ - @prosopo/types@3.6.4
12
+ - @prosopo/types-database@4.0.6
13
+ - @prosopo/user-access-policy@3.5.32
14
+
3
15
  ## 3.5.5
4
16
  ### Patch Changes
5
17
 
@@ -20,7 +20,7 @@ var TableNames = /* @__PURE__ */ ((TableNames2) => {
20
20
  TableNames2["client"] = "client";
21
21
  TableNames2["session"] = "session";
22
22
  TableNames2["detector"] = "detector";
23
- TableNames2["clientEntropy"] = "clientEntropy";
23
+ TableNames2["clientContextEntropy"] = "clientContextEntropy";
24
24
  return TableNames2;
25
25
  })(TableNames || {});
26
26
  const PROVIDER_TABLES = [
@@ -80,9 +80,9 @@ const PROVIDER_TABLES = [
80
80
  schema: typesDatabase.DetectorRecordSchema
81
81
  },
82
82
  {
83
- collectionName: "clientEntropy",
84
- modelName: "ClientEntropy",
85
- schema: typesDatabase.ClientEntropyRecordSchema
83
+ collectionName: "clientContextEntropy",
84
+ modelName: "ClientContextEntropy",
85
+ schema: typesDatabase.ClientContextEntropyRecordSchema
86
86
  }
87
87
  ];
88
88
  class ProviderDatabase extends mongo.MongoDatabase {
@@ -1366,37 +1366,37 @@ class ProviderDatabase extends mongo.MongoDatabase {
1366
1366
  return (keyRecords || []).map((record) => record.detectorKey);
1367
1367
  }
1368
1368
  /**
1369
- * @description set client entropy
1369
+ * @description set client context-specific entropy
1370
1370
  */
1371
- async setClientEntropy(account, entropy) {
1372
- const filter = { account };
1373
- await this.tables?.clientEntropy.updateOne(
1371
+ async setClientContextEntropy(account, contextType, entropy) {
1372
+ const filter = { account, contextType };
1373
+ await this.tables?.clientContextEntropy.updateOne(
1374
1374
  filter,
1375
- { $set: { entropy } },
1375
+ { $set: { account, contextType, entropy } },
1376
1376
  { upsert: true }
1377
1377
  );
1378
1378
  }
1379
1379
  /**
1380
- * @description get client entropy
1380
+ * @description get client context-specific entropy
1381
1381
  */
1382
- async getClientEntropy(account) {
1383
- const filter = { account };
1384
- const doc = await this.tables?.clientEntropy.findOne(filter).lean();
1382
+ async getClientContextEntropy(account, contextType) {
1383
+ const filter = { account, contextType };
1384
+ const doc = await this.tables?.clientContextEntropy.findOne(filter).lean();
1385
1385
  return doc ? doc.entropy : void 0;
1386
1386
  }
1387
- /** Sample captcha records from the database */
1388
- async sampleEntropy(sampleSize, siteKey) {
1387
+ /** Sample captcha records from the database for a specific context */
1388
+ async sampleContextEntropy(sampleSize, siteKey, contextType) {
1389
1389
  const size = sampleSize ? Math.abs(Math.trunc(sampleSize)) : 1;
1390
1390
  const max = 1e4;
1391
1391
  if (size > max) {
1392
1392
  throw new common.ProsopoDBError("DATABASE.CAPTCHA_SAMPLE_SIZE_EXCEEDED", {
1393
1393
  context: {
1394
- failedFuncName: this.sampleEntropy.name,
1394
+ failedFuncName: this.sampleContextEntropy.name,
1395
1395
  sampleSize
1396
1396
  }
1397
1397
  });
1398
1398
  }
1399
- const cursor = this.tables?.powcaptcha.aggregate([
1399
+ const pipeline = [
1400
1400
  {
1401
1401
  $match: {
1402
1402
  dappAccount: siteKey,
@@ -1405,24 +1405,54 @@ class ProviderDatabase extends mongo.MongoDatabase {
1405
1405
  }
1406
1406
  }
1407
1407
  },
1408
+ {
1409
+ $lookup: {
1410
+ from: "session",
1411
+ localField: "sessionId",
1412
+ foreignField: "sessionId",
1413
+ as: "sessionData"
1414
+ }
1415
+ },
1416
+ {
1417
+ $unwind: {
1418
+ path: "$sessionData",
1419
+ preserveNullAndEmptyArrays: false
1420
+ }
1421
+ }
1422
+ ];
1423
+ if (contextType === types.ContextType.Webview) {
1424
+ pipeline.push({
1425
+ $match: {
1426
+ "sessionData.webView": true
1427
+ }
1428
+ });
1429
+ } else if (contextType === types.ContextType.Default) {
1430
+ pipeline.push({
1431
+ $match: {
1432
+ "sessionData.webView": false
1433
+ }
1434
+ });
1435
+ }
1436
+ pipeline.push(
1408
1437
  { $limit: max },
1409
1438
  { $sample: { size } },
1410
1439
  {
1411
1440
  $project: {
1412
1441
  _id: 0,
1413
- frictionlessTokenId: 1
1442
+ sessionId: 1
1414
1443
  }
1415
1444
  }
1416
- ]);
1445
+ );
1446
+ const cursor = this.tables?.powcaptcha.aggregate(pipeline);
1417
1447
  const docs = await cursor;
1418
1448
  if (docs?.length === 0) {
1419
1449
  return [];
1420
1450
  }
1421
1451
  return (await Promise.all(
1422
1452
  docs.map(async (doc) => {
1423
- if (doc.frictionlessTokenId) {
1424
- const tokenRecord = await this.getSessionRecordByToken(
1425
- doc.frictionlessTokenId
1453
+ if (doc.sessionId) {
1454
+ const tokenRecord = await this.getSessionRecordBySessionId(
1455
+ doc.sessionId
1426
1456
  );
1427
1457
  return tokenRecord?.decryptedHeadHash;
1428
1458
  }
@@ -1,8 +1,8 @@
1
1
  import { isHex } from "@polkadot/util/is";
2
2
  import { ProsopoDBError } from "@prosopo/common";
3
3
  import { connectToRedis, setupRedisIndex } from "@prosopo/redis-client";
4
- import { DatasetWithIdsAndTreeSchema, StoredStatusNames, CaptchaStatus, ApiParams, CaptchaStates } from "@prosopo/types";
5
- import { CaptchaRecordSchema, PoWCaptchaRecordSchema, DatasetRecordSchema, SolutionRecordSchema, UserCommitmentRecordSchema, UserSolutionRecordSchema, PendingRecordSchema, ScheduledTaskRecordSchema, ClientRecordSchema, SessionRecordSchema, DetectorRecordSchema, ClientEntropyRecordSchema, UserCommitmentSchema, ScheduledTaskSchema } from "@prosopo/types-database";
4
+ import { DatasetWithIdsAndTreeSchema, StoredStatusNames, CaptchaStatus, ApiParams, CaptchaStates, ContextType } from "@prosopo/types";
5
+ import { CaptchaRecordSchema, PoWCaptchaRecordSchema, DatasetRecordSchema, SolutionRecordSchema, UserCommitmentRecordSchema, UserSolutionRecordSchema, PendingRecordSchema, ScheduledTaskRecordSchema, ClientRecordSchema, SessionRecordSchema, DetectorRecordSchema, ClientContextEntropyRecordSchema, UserCommitmentSchema, ScheduledTaskSchema } from "@prosopo/types-database";
6
6
  import { accessRulesRedisIndex, createRedisAccessRulesStorage } from "@prosopo/user-access-policy/redis";
7
7
  import { MongoDatabase } from "../base/mongo.js";
8
8
  const TWENTY_FOUR_HOURS_IN_MS = 24 * 60 * 60 * 1e3;
@@ -18,7 +18,7 @@ var TableNames = /* @__PURE__ */ ((TableNames2) => {
18
18
  TableNames2["client"] = "client";
19
19
  TableNames2["session"] = "session";
20
20
  TableNames2["detector"] = "detector";
21
- TableNames2["clientEntropy"] = "clientEntropy";
21
+ TableNames2["clientContextEntropy"] = "clientContextEntropy";
22
22
  return TableNames2;
23
23
  })(TableNames || {});
24
24
  const PROVIDER_TABLES = [
@@ -78,9 +78,9 @@ const PROVIDER_TABLES = [
78
78
  schema: DetectorRecordSchema
79
79
  },
80
80
  {
81
- collectionName: "clientEntropy",
82
- modelName: "ClientEntropy",
83
- schema: ClientEntropyRecordSchema
81
+ collectionName: "clientContextEntropy",
82
+ modelName: "ClientContextEntropy",
83
+ schema: ClientContextEntropyRecordSchema
84
84
  }
85
85
  ];
86
86
  class ProviderDatabase extends MongoDatabase {
@@ -1364,37 +1364,37 @@ class ProviderDatabase extends MongoDatabase {
1364
1364
  return (keyRecords || []).map((record) => record.detectorKey);
1365
1365
  }
1366
1366
  /**
1367
- * @description set client entropy
1367
+ * @description set client context-specific entropy
1368
1368
  */
1369
- async setClientEntropy(account, entropy) {
1370
- const filter = { account };
1371
- await this.tables?.clientEntropy.updateOne(
1369
+ async setClientContextEntropy(account, contextType, entropy) {
1370
+ const filter = { account, contextType };
1371
+ await this.tables?.clientContextEntropy.updateOne(
1372
1372
  filter,
1373
- { $set: { entropy } },
1373
+ { $set: { account, contextType, entropy } },
1374
1374
  { upsert: true }
1375
1375
  );
1376
1376
  }
1377
1377
  /**
1378
- * @description get client entropy
1378
+ * @description get client context-specific entropy
1379
1379
  */
1380
- async getClientEntropy(account) {
1381
- const filter = { account };
1382
- const doc = await this.tables?.clientEntropy.findOne(filter).lean();
1380
+ async getClientContextEntropy(account, contextType) {
1381
+ const filter = { account, contextType };
1382
+ const doc = await this.tables?.clientContextEntropy.findOne(filter).lean();
1383
1383
  return doc ? doc.entropy : void 0;
1384
1384
  }
1385
- /** Sample captcha records from the database */
1386
- async sampleEntropy(sampleSize, siteKey) {
1385
+ /** Sample captcha records from the database for a specific context */
1386
+ async sampleContextEntropy(sampleSize, siteKey, contextType) {
1387
1387
  const size = sampleSize ? Math.abs(Math.trunc(sampleSize)) : 1;
1388
1388
  const max = 1e4;
1389
1389
  if (size > max) {
1390
1390
  throw new ProsopoDBError("DATABASE.CAPTCHA_SAMPLE_SIZE_EXCEEDED", {
1391
1391
  context: {
1392
- failedFuncName: this.sampleEntropy.name,
1392
+ failedFuncName: this.sampleContextEntropy.name,
1393
1393
  sampleSize
1394
1394
  }
1395
1395
  });
1396
1396
  }
1397
- const cursor = this.tables?.powcaptcha.aggregate([
1397
+ const pipeline = [
1398
1398
  {
1399
1399
  $match: {
1400
1400
  dappAccount: siteKey,
@@ -1403,24 +1403,54 @@ class ProviderDatabase extends MongoDatabase {
1403
1403
  }
1404
1404
  }
1405
1405
  },
1406
+ {
1407
+ $lookup: {
1408
+ from: "session",
1409
+ localField: "sessionId",
1410
+ foreignField: "sessionId",
1411
+ as: "sessionData"
1412
+ }
1413
+ },
1414
+ {
1415
+ $unwind: {
1416
+ path: "$sessionData",
1417
+ preserveNullAndEmptyArrays: false
1418
+ }
1419
+ }
1420
+ ];
1421
+ if (contextType === ContextType.Webview) {
1422
+ pipeline.push({
1423
+ $match: {
1424
+ "sessionData.webView": true
1425
+ }
1426
+ });
1427
+ } else if (contextType === ContextType.Default) {
1428
+ pipeline.push({
1429
+ $match: {
1430
+ "sessionData.webView": false
1431
+ }
1432
+ });
1433
+ }
1434
+ pipeline.push(
1406
1435
  { $limit: max },
1407
1436
  { $sample: { size } },
1408
1437
  {
1409
1438
  $project: {
1410
1439
  _id: 0,
1411
- frictionlessTokenId: 1
1440
+ sessionId: 1
1412
1441
  }
1413
1442
  }
1414
- ]);
1443
+ );
1444
+ const cursor = this.tables?.powcaptcha.aggregate(pipeline);
1415
1445
  const docs = await cursor;
1416
1446
  if (docs?.length === 0) {
1417
1447
  return [];
1418
1448
  }
1419
1449
  return (await Promise.all(
1420
1450
  docs.map(async (doc) => {
1421
- if (doc.frictionlessTokenId) {
1422
- const tokenRecord = await this.getSessionRecordByToken(
1423
- doc.frictionlessTokenId
1451
+ if (doc.sessionId) {
1452
+ const tokenRecord = await this.getSessionRecordBySessionId(
1453
+ doc.sessionId
1424
1454
  );
1425
1455
  return tokenRecord?.decryptedHeadHash;
1426
1456
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prosopo/database",
3
- "version": "3.5.5",
3
+ "version": "3.5.6",
4
4
  "description": "Prosopo database plugins for provider",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -35,19 +35,19 @@
35
35
  "homepage": "https://github.com/prosopo/captcha#readme",
36
36
  "dependencies": {
37
37
  "@polkadot/util": "13.5.7",
38
- "@prosopo/common": "3.1.25",
39
- "@prosopo/locale": "3.1.25",
40
- "@prosopo/redis-client": "1.0.10",
41
- "@prosopo/types": "3.6.3",
42
- "@prosopo/types-database": "4.0.5",
43
- "@prosopo/user-access-policy": "3.5.31",
38
+ "@prosopo/common": "3.1.26",
39
+ "@prosopo/locale": "3.1.26",
40
+ "@prosopo/redis-client": "1.0.11",
41
+ "@prosopo/types": "3.6.4",
42
+ "@prosopo/types-database": "4.0.6",
43
+ "@prosopo/user-access-policy": "3.5.32",
44
44
  "make-dir": "3.1.0",
45
45
  "mongodb": "6.15.0",
46
46
  "mongodb-memory-server": "10.3.0",
47
47
  "mongoose": "8.13.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@prosopo/config": "3.1.25",
50
+ "@prosopo/config": "3.1.26",
51
51
  "@types/node": "22.10.2",
52
52
  "@vitest/coverage-v8": "3.2.4",
53
53
  "concurrently": "9.0.1",