@prosopo/database 0.3.1 → 0.3.2

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.
@@ -35,39 +35,13 @@ try {
35
35
  } catch (error) {
36
36
  CaptchaEvent = mongoose.model("CaptchaEvent", captchaEventSchema);
37
37
  }
38
- const addCaptchaEventRecord = async (record) => {
39
- try {
40
- const newRecord = new CaptchaEvent(record);
41
- await newRecord.save();
42
- logger.info("Record added successfully");
43
- } catch (error) {
44
- logger.error("Error adding record to the database:", error);
45
- }
46
- };
47
38
  const saveCaptchaEvent = async (events, accountId, atlasUri) => {
48
- return new Promise((resolve, reject) => {
49
- const connection = mongoose.createConnection(atlasUri);
50
- for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
51
- connection.once("open", resolve).on("error", (e) => {
52
- logger.warn(`Mongoose connection error`);
53
- logger.error(e);
54
- if (attempt === MAX_RETRIES) {
55
- reject(
56
- new common.ProsopoDBError("DATABASE.CONNECT_ERROR", {
57
- context: { failedFuncName: saveCaptchaEvent.name, db: "events database" },
58
- logger
59
- })
60
- );
61
- } else {
62
- connection?.removeAllListeners("error");
63
- }
64
- });
65
- }
66
- const captchaEventData = {
67
- ...events,
68
- accountId
69
- };
70
- addCaptchaEventRecord(captchaEventData).then(() => logger.info("Captcha event data saved")).catch((error) => logger.error("Error saving captcha event data:", error)).finally(() => connection.close());
71
- });
39
+ await mongoose.connect(atlasUri).then(() => console.log("Connected to MongoDB Atlas"));
40
+ const captchaEventData = {
41
+ ...events,
42
+ accountId
43
+ };
44
+ await CaptchaEvent.create(captchaEventData);
45
+ logger.info("Mongo Saved Events");
72
46
  };
73
47
  exports.saveCaptchaEvent = saveCaptchaEvent;
@@ -1,3 +1,3 @@
1
1
  import { StoredEvents } from '@prosopo/types';
2
- export declare const saveCaptchaEvent: (events: StoredEvents, accountId: string, atlasUri: string) => Promise<unknown>;
2
+ export declare const saveCaptchaEvent: (events: StoredEvents, accountId: string, atlasUri: string) => Promise<void>;
3
3
  //# sourceMappingURL=eventsDatabase.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"eventsDatabase.d.ts","sourceRoot":"","sources":["../../src/eventsDatabase/eventsDatabase.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AA+ChE,eAAO,MAAM,gBAAgB,WAAkB,YAAY,aAAa,MAAM,YAAY,MAAM,qBAiC/F,CAAA"}
1
+ {"version":3,"file":"eventsDatabase.d.ts","sourceRoot":"","sources":["../../src/eventsDatabase/eventsDatabase.ts"],"names":[],"mappings":"AAaA,OAAO,EAAqB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAsChE,eAAO,MAAM,gBAAgB,WAAkB,YAAY,aAAa,MAAM,YAAY,MAAM,kBAU/F,CAAA"}
@@ -1,4 +1,4 @@
1
- import { ProsopoDBError, getLoggerDefault } from '@prosopo/common';
1
+ import { getLoggerDefault } from '@prosopo/common';
2
2
  import mongoose from 'mongoose';
3
3
  const logger = getLoggerDefault();
4
4
  const MAX_RETRIES = 3;
@@ -34,42 +34,13 @@ try {
34
34
  catch (error) {
35
35
  CaptchaEvent = mongoose.model('CaptchaEvent', captchaEventSchema);
36
36
  }
37
- const addCaptchaEventRecord = async (record) => {
38
- try {
39
- const newRecord = new CaptchaEvent(record);
40
- await newRecord.save();
41
- logger.info('Record added successfully');
42
- }
43
- catch (error) {
44
- logger.error('Error adding record to the database:', error);
45
- }
46
- };
47
37
  export const saveCaptchaEvent = async (events, accountId, atlasUri) => {
48
- return new Promise((resolve, reject) => {
49
- const connection = mongoose.createConnection(atlasUri);
50
- for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
51
- connection.once('open', resolve).on('error', (e) => {
52
- logger.warn(`Mongoose connection error`);
53
- logger.error(e);
54
- if (attempt === MAX_RETRIES) {
55
- reject(new ProsopoDBError('DATABASE.CONNECT_ERROR', {
56
- context: { failedFuncName: saveCaptchaEvent.name, db: 'events database' },
57
- logger: logger,
58
- }));
59
- }
60
- else {
61
- connection?.removeAllListeners('error');
62
- }
63
- });
64
- }
65
- const captchaEventData = {
66
- ...events,
67
- accountId,
68
- };
69
- addCaptchaEventRecord(captchaEventData)
70
- .then(() => logger.info('Captcha event data saved'))
71
- .catch((error) => logger.error('Error saving captcha event data:', error))
72
- .finally(() => connection.close());
73
- });
38
+ await mongoose.connect(atlasUri).then(() => console.log('Connected to MongoDB Atlas'));
39
+ const captchaEventData = {
40
+ ...events,
41
+ accountId,
42
+ };
43
+ await CaptchaEvent.create(captchaEventData);
44
+ logger.info('Mongo Saved Events');
74
45
  };
75
46
  //# sourceMappingURL=eventsDatabase.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"eventsDatabase.js","sourceRoot":"","sources":["../../src/eventsDatabase/eventsDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElE,OAAO,QAAmB,MAAM,UAAU,CAAA;AAC1C,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAA;AACjC,MAAM,WAAW,GAAG,CAAC,CAAA;AAErB,MAAM,kBAAkB,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC;IAC3C,WAAW,EAAE;QACT;YACI,CAAC,EAAE,MAAM;YACT,CAAC,EAAE,MAAM;YACT,SAAS,EAAE,MAAM;SACpB;KACJ;IACD,WAAW,EAAE;QACT;YACI,CAAC,EAAE,MAAM;YACT,CAAC,EAAE,MAAM;YACT,SAAS,EAAE,MAAM;SACpB;KACJ;IACD,cAAc,EAAE;QACZ;YACI,GAAG,EAAE,MAAM;YACX,SAAS,EAAE,MAAM;YACjB,UAAU,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE;YAC9C,SAAS,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE;SAChD;KACJ;IACD,SAAS,EAAE,MAAM;CACpB,CAAC,C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E,KAAK,EAAE;YAC9C,SAAS,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE;SAChD;KACJ;IACD,SAAS,EAAE,MAAM;CACpB,CAAC,CAAA;AACF,IAAI,YAA6C,CAAA;AACjD,IAAI;IACA,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;CAChD;AAAC,OAAO,KAAK,EAAE;IACZ,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAA;CACpE;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,MAAoB,EAAE,SAAiB,EAAE,QAAgB,EAAE,EAAE;IAChG,MAAM,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,CAAA;IAEtF,MAAM,gBAAgB,GAAG;QACrB,GAAG,MAAM;QACT,SAAS;KACZ,CAAA;IAED,MAAM,YAAY,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;IAC3C,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA;AACrC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prosopo/database",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Prosopo database plugins for provider",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -37,11 +37,11 @@
37
37
  "homepage": "https://github.com/prosopo/captcha#readme",
38
38
  "dependencies": {
39
39
  "@polkadot/util": "12.6.1",
40
- "@prosopo/captcha-contract": "0.3.1",
41
- "@prosopo/common": "0.3.1",
42
- "@prosopo/config": "0.3.1",
43
- "@prosopo/types": "0.3.1",
44
- "@prosopo/types-database": "0.3.1",
40
+ "@prosopo/captcha-contract": "0.3.2",
41
+ "@prosopo/common": "0.3.2",
42
+ "@prosopo/config": "0.3.2",
43
+ "@prosopo/types": "0.3.2",
44
+ "@prosopo/types-database": "0.3.2",
45
45
  "mongodb": "5.8.0",
46
46
  "mongodb-memory-server": "^8.7.2",
47
47
  "mongoose": "^7.3.3"
package/typedoc.config.js CHANGED
@@ -1,3 +1,16 @@
1
+ // Copyright 2021-2024 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
1
14
  export default {
2
15
  entryPoints: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.js', 'src/**/*.jsx', 'src/**/*.json'],
3
16
  includes: 'src',
@@ -1,3 +1,16 @@
1
+ // Copyright 2021-2024 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
1
14
  import { ViteCommonJSConfig } from '@prosopo/config'
2
15
  import path from 'path'
3
16