@prosopo/env 2.5.5 → 2.6.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.
- package/CHANGELOG.md +37 -0
- package/dist/cjs/env.cjs +104 -0
- package/dist/cjs/index.cjs +8 -0
- package/dist/cjs/mockenv.cjs +13 -0
- package/dist/cjs/provider.cjs +12 -0
- package/package.json +14 -9
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @prosopo/env
|
|
2
|
+
|
|
3
|
+
## 2.6.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [6ff193a]
|
|
8
|
+
- @prosopo/types@2.6.2
|
|
9
|
+
- @prosopo/database@2.6.2
|
|
10
|
+
- @prosopo/types-database@2.6.2
|
|
11
|
+
- @prosopo/types-env@2.6.2
|
|
12
|
+
|
|
13
|
+
## 2.6.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [52feffc]
|
|
18
|
+
- @prosopo/types-database@2.6.1
|
|
19
|
+
- @prosopo/database@2.6.1
|
|
20
|
+
- @prosopo/types@2.6.1
|
|
21
|
+
- @prosopo/types-env@2.6.1
|
|
22
|
+
|
|
23
|
+
## 2.6.0
|
|
24
|
+
|
|
25
|
+
### Minor Changes
|
|
26
|
+
|
|
27
|
+
- a0bfc8a: bump all pkg versions since independent versioning applied
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [a0bfc8a]
|
|
32
|
+
- @prosopo/common@2.6.0
|
|
33
|
+
- @prosopo/database@2.6.0
|
|
34
|
+
- @prosopo/types@2.6.0
|
|
35
|
+
- @prosopo/types-database@2.6.0
|
|
36
|
+
- @prosopo/types-env@2.6.0
|
|
37
|
+
- @prosopo/util@2.6.0
|
package/dist/cjs/env.cjs
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const keyring = require("@polkadot/keyring");
|
|
4
|
+
const common = require("@prosopo/common");
|
|
5
|
+
const database = require("@prosopo/database");
|
|
6
|
+
class Environment {
|
|
7
|
+
constructor(config, pair, authAccount) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.defaultEnvironment = this.config.defaultEnvironment;
|
|
10
|
+
this.pair = pair;
|
|
11
|
+
this.authAccount = authAccount;
|
|
12
|
+
this.logger = common.getLogger(this.config.logLevel, "ProsopoEnvironment");
|
|
13
|
+
this.keyring = new keyring.Keyring({
|
|
14
|
+
type: "sr25519"
|
|
15
|
+
});
|
|
16
|
+
if (this.pair) this.keyring.addPair(this.pair);
|
|
17
|
+
}
|
|
18
|
+
async getSigner() {
|
|
19
|
+
if (!this.pair) {
|
|
20
|
+
throw new common.ProsopoEnvError("CONTRACT.SIGNER_UNDEFINED", {
|
|
21
|
+
context: { failedFuncName: this.getSigner.name }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
this.pair = this.keyring.addPair(this.pair);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
throw new common.ProsopoEnvError("CONTRACT.SIGNER_UNDEFINED", {
|
|
28
|
+
context: { failedFuncName: this.getSigner.name, error }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return this.pair;
|
|
32
|
+
}
|
|
33
|
+
getDb() {
|
|
34
|
+
if (this.db === void 0) {
|
|
35
|
+
throw new common.ProsopoEnvError(
|
|
36
|
+
new Error("db not setup! Please call isReady() first")
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return this.db;
|
|
40
|
+
}
|
|
41
|
+
getAssetsResolver() {
|
|
42
|
+
if (this.assetsResolver === void 0) {
|
|
43
|
+
throw new common.ProsopoEnvError(
|
|
44
|
+
new Error("assetsResolver not setup! Please call isReady() first")
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return this.assetsResolver;
|
|
48
|
+
}
|
|
49
|
+
getPair() {
|
|
50
|
+
if (this.pair === void 0) {
|
|
51
|
+
throw new common.ProsopoEnvError(
|
|
52
|
+
new Error("pair not setup! Please call isReady() first")
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return this.pair;
|
|
56
|
+
}
|
|
57
|
+
async isReady() {
|
|
58
|
+
try {
|
|
59
|
+
if (this.pair && this.config.account.password && this.pair.isLocked) {
|
|
60
|
+
this.pair.unlock(this.config.account.password);
|
|
61
|
+
}
|
|
62
|
+
await this.getSigner();
|
|
63
|
+
if (!this.db) {
|
|
64
|
+
await this.importDatabase();
|
|
65
|
+
}
|
|
66
|
+
if (this.db && !this.db.connected) {
|
|
67
|
+
this.logger.warn(
|
|
68
|
+
`Database connection is not ready (state: ${this.db.connection?.readyState}), reconnecting...`
|
|
69
|
+
);
|
|
70
|
+
await this.db.connect();
|
|
71
|
+
this.logger.info("Connected to db");
|
|
72
|
+
}
|
|
73
|
+
} catch (err) {
|
|
74
|
+
throw new common.ProsopoEnvError("GENERAL.ENVIRONMENT_NOT_READY", {
|
|
75
|
+
context: { error: err },
|
|
76
|
+
logger: this.logger
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async importDatabase() {
|
|
81
|
+
try {
|
|
82
|
+
if (this.config.database) {
|
|
83
|
+
const dbConfig = this.config.database[this.defaultEnvironment];
|
|
84
|
+
if (dbConfig) {
|
|
85
|
+
this.db = new database.ProviderDatabase(
|
|
86
|
+
dbConfig.endpoint,
|
|
87
|
+
dbConfig.dbname,
|
|
88
|
+
dbConfig.authSource,
|
|
89
|
+
this.logger
|
|
90
|
+
);
|
|
91
|
+
await this.db.connect();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
throw new common.ProsopoEnvError("DATABASE.DATABASE_IMPORT_FAILED", {
|
|
96
|
+
context: {
|
|
97
|
+
error,
|
|
98
|
+
environment: this.config.database ? this.config.database[this.defaultEnvironment] ? this.config.database[this.defaultEnvironment]?.type : void 0 : void 0
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.Environment = Environment;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const env = require("./env.cjs");
|
|
4
|
+
const provider = require("./provider.cjs");
|
|
5
|
+
const mockenv = require("./mockenv.cjs");
|
|
6
|
+
exports.Environment = env.Environment;
|
|
7
|
+
exports.ProviderEnvironment = provider.ProviderEnvironment;
|
|
8
|
+
exports.MockEnvironment = mockenv.MockEnvironment;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const mnemonic = require("@polkadot/util-crypto/mnemonic");
|
|
4
|
+
const provider = require("./provider.cjs");
|
|
5
|
+
class MockEnvironment extends provider.ProviderEnvironment {
|
|
6
|
+
createAccountAndAddToKeyring() {
|
|
7
|
+
const mnemonic$1 = mnemonic.mnemonicGenerate();
|
|
8
|
+
const account = this.keyring.addFromMnemonic(mnemonic$1);
|
|
9
|
+
const { address } = account;
|
|
10
|
+
return { address, mnemonic: mnemonic$1, contractAddress: void 0 };
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.MockEnvironment = MockEnvironment;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const types = require("@prosopo/types");
|
|
4
|
+
const env = require("./env.cjs");
|
|
5
|
+
class ProviderEnvironment extends env.Environment {
|
|
6
|
+
cleanup() {
|
|
7
|
+
this.getDb().cleanupScheduledTaskStatus(types.ScheduledTaskStatus.Running).catch((err) => {
|
|
8
|
+
this.logger.error("Failed to cleanup scheduled tasks", err);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ProviderEnvironment = ProviderEnvironment;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/env",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.2",
|
|
4
4
|
"description": "Path env prosopo environment",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
"@polkadot/keyring": "12.6.2",
|
|
25
25
|
"@polkadot/util": "12.6.2",
|
|
26
26
|
"@polkadot/util-crypto": "12.6.2",
|
|
27
|
-
"@prosopo/common": "2.
|
|
28
|
-
"@prosopo/database": "2.
|
|
29
|
-
"@prosopo/types": "2.
|
|
30
|
-
"@prosopo/types-database": "2.
|
|
31
|
-
"@prosopo/types-env": "2.
|
|
32
|
-
"@prosopo/util": "2.
|
|
27
|
+
"@prosopo/common": "2.6.0",
|
|
28
|
+
"@prosopo/database": "2.6.2",
|
|
29
|
+
"@prosopo/types": "2.6.2",
|
|
30
|
+
"@prosopo/types-database": "2.6.2",
|
|
31
|
+
"@prosopo/types-env": "2.6.2",
|
|
32
|
+
"@prosopo/util": "2.6.0",
|
|
33
33
|
"express": "4.21.2"
|
|
34
34
|
},
|
|
35
35
|
"overrides": {
|
|
36
36
|
"@polkadot/keyring": "12.6.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@prosopo/config": "2.
|
|
39
|
+
"@prosopo/config": "2.6.0",
|
|
40
40
|
"@vitest/coverage-v8": "3.0.9",
|
|
41
41
|
"concurrently": "9.0.1",
|
|
42
42
|
"del-cli": "6.0.0",
|
|
@@ -49,5 +49,10 @@
|
|
|
49
49
|
},
|
|
50
50
|
"author": "Prosopo",
|
|
51
51
|
"license": "Apache-2.0",
|
|
52
|
-
"sideEffects": false
|
|
52
|
+
"sideEffects": false,
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/prosopo/captcha.git",
|
|
56
|
+
"directory": "packages/env"
|
|
57
|
+
}
|
|
53
58
|
}
|