@prosopo/dotenv 2.0.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.
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const ARRAY_JOINER = "";
4
+ function arrayJoin(arr, joiner) {
5
+ return arr.join(joiner ? joiner : ARRAY_JOINER);
6
+ }
7
+ exports.ARRAY_JOINER = ARRAY_JOINER;
8
+ exports.arrayJoin = arrayJoin;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const error = require("./error.cjs");
4
+ class AsyncFactory {
5
+ constructor() {
6
+ throw new error.ProsopoEnvError("GENERAL.ASYNC_FACTORY_CREATE");
7
+ }
8
+ static async create(...args) {
9
+ return await Object.create(this.prototype).init(...args);
10
+ }
11
+ }
12
+ exports.AsyncFactory = AsyncFactory;
13
+ exports.default = AsyncFactory;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ require("./index.cjs");
4
+ const logger = require("./logger.cjs");
5
+ const i18n = require("i18next");
6
+ class ProsopoBaseError extends Error {
7
+ constructor(error, options) {
8
+ const logger$1 = options?.logger || logger.getLoggerDefault();
9
+ const logLevel = options?.logLevel || "error";
10
+ if (error instanceof Error) {
11
+ super(error.message);
12
+ this.translationKey = options?.translationKey;
13
+ this.context = {
14
+ ...options?.context,
15
+ ...options?.translationKey ? { translationMessage: i18n.t(options.translationKey) } : {}
16
+ };
17
+ } else {
18
+ super(i18n.t(error));
19
+ this.translationKey = error;
20
+ this.context = options?.context;
21
+ }
22
+ if (!options?.silent)
23
+ this.logError(logger$1, logLevel);
24
+ }
25
+ logError(logger2, logLevel) {
26
+ const errorFormatter = "\n*************** ERROR ***************\n";
27
+ const errorName = `Error Type: ${this.name}
28
+ `;
29
+ const errorParams = JSON.stringify({ error: this.message, context: this.context }, null, 4);
30
+ const errorMessage = `${errorFormatter}${errorName}${errorParams}`;
31
+ logger2[logLevel](errorMessage);
32
+ }
33
+ }
34
+ class ProsopoError extends ProsopoBaseError {
35
+ constructor(error, options) {
36
+ const errorName = options?.name || "ProsopoError";
37
+ const optionsAll = { ...options, name: errorName };
38
+ super(error, optionsAll);
39
+ }
40
+ }
41
+ class ProsopoEnvError extends ProsopoBaseError {
42
+ constructor(error, options) {
43
+ const errorName = options?.name || "ProsopoEnvError";
44
+ const optionsAll = { ...options, name: errorName };
45
+ super(error, optionsAll);
46
+ }
47
+ }
48
+ class ProsopoContractError extends ProsopoBaseError {
49
+ constructor(error, options) {
50
+ const errorName = options?.name || "ProsopoContractError";
51
+ const optionsAll = { ...options, name: errorName };
52
+ super(error, optionsAll);
53
+ }
54
+ }
55
+ class ProsopoTxQueueError extends ProsopoBaseError {
56
+ constructor(error, options) {
57
+ const errorName = options?.name || "ProsopoTxQueueError";
58
+ const optionsAll = { ...options, name: errorName };
59
+ super(error, optionsAll);
60
+ }
61
+ }
62
+ class ProsopoDBError extends ProsopoBaseError {
63
+ constructor(error, options) {
64
+ const errorName = options?.name || "ProsopoDBError";
65
+ const optionsAll = { ...options, name: errorName };
66
+ super(error, optionsAll);
67
+ }
68
+ }
69
+ class ProsopoCliError extends ProsopoBaseError {
70
+ constructor(error, options) {
71
+ const errorName = options?.name || "ProsopoCliError";
72
+ const optionsAll = { ...options, name: errorName };
73
+ super(error, optionsAll);
74
+ }
75
+ }
76
+ class ProsopoDatasetError extends ProsopoBaseError {
77
+ constructor(error, options) {
78
+ const errorName = options?.name || "ProsopoDatasetError";
79
+ const optionsAll = { ...options, name: errorName };
80
+ super(error, optionsAll);
81
+ }
82
+ }
83
+ class ProsopoApiError extends ProsopoBaseError {
84
+ constructor(error, options) {
85
+ const errorName = options?.name || "ProsopoApiError";
86
+ const code = options?.context?.code || 500;
87
+ const optionsAll = {
88
+ ...options,
89
+ name: errorName,
90
+ context: { ...options?.context, code }
91
+ };
92
+ super(error, optionsAll);
93
+ this.code = code;
94
+ }
95
+ }
96
+ exports.ProsopoApiError = ProsopoApiError;
97
+ exports.ProsopoBaseError = ProsopoBaseError;
98
+ exports.ProsopoCliError = ProsopoCliError;
99
+ exports.ProsopoContractError = ProsopoContractError;
100
+ exports.ProsopoDBError = ProsopoDBError;
101
+ exports.ProsopoDatasetError = ProsopoDatasetError;
102
+ exports.ProsopoEnvError = ProsopoEnvError;
103
+ exports.ProsopoError = ProsopoError;
104
+ exports.ProsopoTxQueueError = ProsopoTxQueueError;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const blake2 = require("@polkadot/util-crypto/blake2");
4
+ const array = require("./array.cjs");
5
+ const HEX_HASH_BIT_LENGTH = 256;
6
+ function hexHash(data, bitLength) {
7
+ return blake2.blake2AsHex(data, bitLength);
8
+ }
9
+ function hexHashArray(arr) {
10
+ return hexHash(array.arrayJoin(arr));
11
+ }
12
+ exports.HEX_HASH_BIT_LENGTH = HEX_HASH_BIT_LENGTH;
13
+ exports.hexHash = hexHash;
14
+ exports.hexHashArray = hexHashArray;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ const i18n = require("i18next");
3
+ const LanguageDetector = require("i18next-browser-languagedetector");
4
+ const Backend = require("i18next-http-backend");
5
+ const i18nextHttpMiddleware = require("i18next-http-middleware");
6
+ const reactI18next = require("react-i18next");
7
+ const en = require("./locales/en.json.cjs");
8
+ const utils = require("./utils.cjs");
9
+ const commonOptions = {
10
+ debug: false,
11
+ fallbackLng: "en",
12
+ resources: {
13
+ en: {
14
+ translation: en.default
15
+ }
16
+ }
17
+ };
18
+ const reactOptions = {
19
+ react: {
20
+ useSuspense: false
21
+ }
22
+ };
23
+ const nodeOptions = {};
24
+ if (utils.isClientSide()) {
25
+ i18n.use(LanguageDetector).use(reactI18next.initReactI18next).init({ ...commonOptions, ...reactOptions });
26
+ } else {
27
+ i18n.use(new Backend(void 0, { reloadInterval: false })).use(i18nextHttpMiddleware.LanguageDetector).init({ ...commonOptions, ...nodeOptions });
28
+ }
29
+ module.exports = i18n;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ require("./i18n.cjs");
4
+ require("./react/index.cjs");
5
+ require("./node/index.cjs");
6
+ const utils = require("./utils.cjs");
7
+ require("./custom.cjs");
8
+ const error = require("./error.cjs");
9
+ const logger = require("./logger.cjs");
10
+ const array = require("./array.cjs");
11
+ const hash = require("./hash.cjs");
12
+ const asyncFactory = require("./asyncFactory.cjs");
13
+ const string = require("./string.cjs");
14
+ const UrlConverter = require("./node/UrlConverter.cjs");
15
+ exports.TranslationKeysSchema = utils.TranslationKeysSchema;
16
+ exports.isClientSide = utils.isClientSide;
17
+ exports.reverseHexString = utils.reverseHexString;
18
+ exports.ProsopoApiError = error.ProsopoApiError;
19
+ exports.ProsopoBaseError = error.ProsopoBaseError;
20
+ exports.ProsopoCliError = error.ProsopoCliError;
21
+ exports.ProsopoContractError = error.ProsopoContractError;
22
+ exports.ProsopoDBError = error.ProsopoDBError;
23
+ exports.ProsopoDatasetError = error.ProsopoDatasetError;
24
+ exports.ProsopoEnvError = error.ProsopoEnvError;
25
+ exports.ProsopoError = error.ProsopoError;
26
+ exports.ProsopoTxQueueError = error.ProsopoTxQueueError;
27
+ exports.LogLevel = logger.LogLevel;
28
+ exports.Loggable = logger.Loggable;
29
+ exports.getLogLevel = logger.getLogLevel;
30
+ exports.getLogger = logger.getLogger;
31
+ exports.getLoggerDefault = logger.getLoggerDefault;
32
+ exports.ARRAY_JOINER = array.ARRAY_JOINER;
33
+ exports.arrayJoin = array.arrayJoin;
34
+ exports.HEX_HASH_BIT_LENGTH = hash.HEX_HASH_BIT_LENGTH;
35
+ exports.hexHash = hash.hexHash;
36
+ exports.hexHashArray = hash.hexHashArray;
37
+ exports.AsyncFactory = asyncFactory.AsyncFactory;
38
+ exports.capitaliseFirstLetter = string.capitaliseFirstLetter;
39
+ exports.UrlConverter = UrlConverter.UrlConverter;
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const ACCOUNT = {
4
+ NO_POLKADOT_EXTENSION: "Polkadot extension not found"
5
+ };
6
+ const WIDGET = {
7
+ SELECT_ALL: "Select all containing the following",
8
+ IF_NONE_CLICK_NEXT: "If there are none, click Next",
9
+ NEXT: "Next",
10
+ SUBMIT: "Submit",
11
+ CANCEL: "Cancel",
12
+ SELECT_ACCOUNT: "Select account",
13
+ NO_ACCOUNTS_FOUND: "No accounts found",
14
+ ACCOUNT_NOT_FOUND: "Account not found",
15
+ NO_EXTENSION_FOUND: "No extension found",
16
+ EXTENSION_NOT_FOUND: "Extension not found",
17
+ CANVAS: "Error with Captcha canvas"
18
+ };
19
+ const GENERAL = {
20
+ BAD_SURI: "Bad SURI",
21
+ CANNOT_FIND_CONFIG_FILE: "prosopo.config.js / prosopo.config.ts cannot be found.",
22
+ JSON_LOAD_FAILED: "Failed to load JSON file",
23
+ CREATE_JSON_FILE_FAILED: "Failed to create JSON file",
24
+ ASSERT_ERROR: "AssertionError",
25
+ GENERATE_CAPTCHAS_JSON_FAILED: "Something went wrong while creating captchas json file",
26
+ CALCULATE_CAPTCHA_SOLUTION: "Something went wrong while calculating captcha solutions",
27
+ MNEMONIC_UNDEFINED: "Mnemonic Undefined. Please set the mnemonic in environment variables",
28
+ NO_MNEMONIC_OR_SEED: "No mnemonic or seed provided",
29
+ ASYNC_FACTORY_CREATE: "Use `create` factory method",
30
+ CANT_FIND_KEYRINGPAIR: "Can't find the keyringpair for {{address}}",
31
+ ENVIRONMENT_NOT_READY: "Environment not ready",
32
+ INVALID_SIGNATURE: "Invalid signature",
33
+ PAIR_TYPE_UNDEFINED: "Pair type undefined",
34
+ NOT_IMPLEMENTED: "Not implemented",
35
+ NO_PAIR_TYPE_OR_SS58_FORMAT: "No pair type or ss58 format provided",
36
+ SITE_KEY_MISSING: "SITE KEY missing",
37
+ ACCOUNT_NOT_FOUND: "Account not found"
38
+ };
39
+ const CONTRACT = {
40
+ INVALID_METHOD: "Invalid contract method",
41
+ TX_ERROR: "Error making tx",
42
+ QUERY_ERROR: "Error making query",
43
+ INVALID_ADDRESS: "Failed to encode invalid address",
44
+ INVALID_STORAGE_NAME: "Failed to find given storage name",
45
+ CAPTCHA_SOLUTION_COMMITMENT_DOES_NOT_EXIST: "Captcha solution commitment does not exist",
46
+ DAPP_NOT_ACTIVE: "Dapp is not active",
47
+ CONTRACT_UNDEFINED: "Contract undefined",
48
+ SIGNER_UNDEFINED: "Signer undefined",
49
+ SIGNER_NOT_SUPPORTED: "Signer is not supported. Use connect instead, e.g. contract.connect(signer)",
50
+ CANNOT_FIND_KEYPAIR: "Cannot find keypair",
51
+ INVALID_TYPE: "Invalid type",
52
+ INVALID_ABI: "Invalid ABI",
53
+ NOT_HANDLED: "Not handled",
54
+ INVALID_STORAGE_TYPE: "Invalid storage type",
55
+ INTERRUPTED_EVENT: "Event interrupted",
56
+ TOO_MANY_CALLS: "Too many calls",
57
+ UNKNOWN_ERROR: "Unknown error",
58
+ CHAIN_DECIMALS_UNDEFINED: "Chain decimals are not defined",
59
+ INVALID_DATA_FORMAT: "Invalid data format",
60
+ INVALID_BLOCKHASH: "Invalid blockhash",
61
+ TX_QUEUE_ERROR: "Error in Transaction Queue",
62
+ DISPATCH_ERROR: "Error dispatching transaction"
63
+ };
64
+ const CONFIG = {
65
+ UNKNOWN_ENVIRONMENT: "Unknown environment requested",
66
+ INVALID_CAPTCHA_NUMBER: "Please configure captchas configurations correctly",
67
+ CONFIGURATIONS_LOAD_FAILED: "Prosopo configurations load failed",
68
+ INVALID_LOG_LEVEL: "Invalid log level",
69
+ INVALID_PACKAGE_DIR: "Invalid package directory"
70
+ };
71
+ const DATASET = {
72
+ DATASET_PARSE_ERROR: "Error parsing dataset",
73
+ SOLUTION_PARSE_ERROR: "Error parsing dataset",
74
+ HASH_ERROR: "Error hashing dataset",
75
+ INVALID_DATASET_ID: "Invalid dataset id",
76
+ DATASET_ID_UNDEFINED: "Dataset id undefined",
77
+ NOT_ENOUGH_LABELS: "Not enough labels",
78
+ NOT_ENOUGH_IMAGES: "Not enough images",
79
+ CAPTCHAS_COUNT_LESS_THAN_CONFIGURED: "Number of captchas in dataset is less than configured number of captchas",
80
+ SOLUTIONS_COUNT_LESS_THAN_CONFIGURED: "Number of solutions in dataset is less than configured number of solutions",
81
+ DUPLICATE_IMAGE: "duplicate image detected",
82
+ MERKLE_ERROR: "Error creating merkle tree"
83
+ };
84
+ const DATABASE = {
85
+ CONNECT_ERROR: "Failed to connect",
86
+ DATABASE_IMPORT_FAILED: "Failed to import database engine",
87
+ DATABASE_UNDEFINED: "Database client is not connected",
88
+ DATABASE_HOST_UNDEFINED: "Database host address is not defined",
89
+ COLLECTION_UNDEFINED: "Database collection is not available",
90
+ DATASET_LOAD_FAILED: "Data set load failed",
91
+ DATASET_GET_FAILED: "Failed to get dataset",
92
+ CAPTCHA_GET_FAILED: "Failed to get captcha",
93
+ CAPTCHA_UPDATE_FAILED: "Failed to update captcha",
94
+ IMAGE_GET_FAILED: "Failed to get image",
95
+ NO_CAPTCHAS_FOUND: "No captcha matching datasetId",
96
+ PENDING_RECORD_NOT_FOUND: "No pending record found",
97
+ INVALID_HASH: "Invalid hash",
98
+ SOLUTION_GET_FAILED: "Failed to get solution",
99
+ DATASET_WITH_SOLUTIONS_GET_FAILED: "No datasets found with required number of solutions",
100
+ SOLUTION_APPROVE_FAILED: "Failed to approve solution",
101
+ SOLUTION_FLAG_FAILED: "Failed to flag solution as processed",
102
+ TABLES_UNDEFINED: "Tables undefined",
103
+ CONNECTION_UNDEFINED: "Connection undefined",
104
+ COMMITMENT_FLAG_FAILED: "Failed to flag commitment as processed"
105
+ };
106
+ const CAPTCHA = {
107
+ PARSE_ERROR: "Error parsing captcha",
108
+ INVALID_CAPTCHA_ID: "Invalid captcha id",
109
+ SOLUTION_HASH_ERROR: "Error hashing solution",
110
+ INVALID_ITEM_FORMAT: "Only image and text item types allowed",
111
+ INVALID_SOLUTION_TYPE: "Invalid solution type",
112
+ INVALID_ITEM_HASH: "Invalid item hash",
113
+ DIFFERENT_DATASET_IDS: "Dataset ids do not match",
114
+ INVALID_BLOCK_NO: "Invalid block number",
115
+ INVALID_TIMESTAMP: "Invalid timestamp",
116
+ ID_MISMATCH: "captcha id mismatch",
117
+ MISSING_ITEM_HASH: "missing item hash",
118
+ INVALID_LEAF_HASH: "Invalid leaf hash",
119
+ INVALID_CAPTCHA_CHALLENGE: "Invalid captcha challenge",
120
+ INVALID_DATASET_CONTENT_ID: "Invalid dataset content id",
121
+ DAPP_USER_SOLUTION_NOT_FOUND: "Dapp user solution not found",
122
+ INVALID_PROVIDER_URL: "Invalid provider url",
123
+ NO_CAPTCHA: "No captcha found",
124
+ INVALID_TOKEN: "Invalid token",
125
+ IP_ADDRESS_MISMATCH: "IP address mismatch",
126
+ INVALID_SOLUTION: "Invalid solution"
127
+ };
128
+ const API = {
129
+ BODY_UNDEFINED: "Body must be defined in API POST call",
130
+ PARAMETER_UNDEFINED: "Parameters must be defined in API POST call",
131
+ CAPTCHA_FAILED: "You answered one or more captchas incorrectly. Please try again",
132
+ CAPTCHA_PENDING: "Captcha solutions submitted and awaiting approval",
133
+ CAPTCHA_PASSED: "You correctly answered the captchas",
134
+ BAD_REQUEST: "BadRequest",
135
+ PAYMENT_INFO_NOT_FOUND: "Payment info not found for given block and transaction hashes",
136
+ USER_VERIFIED: "User verified",
137
+ USER_NOT_VERIFIED: "User not verified",
138
+ USER_NOT_VERIFIED_TIME_EXPIRED: "User not verified. Captcha solution has expired.",
139
+ USER_NOT_VERIFIED_NO_SOLUTION: "User not verified. No captcha solution found.",
140
+ USER_ALREADY_VERIFIED: "This solution has already been verified. User should complete a new captcha.",
141
+ UNKNOWN: "Unknown API error"
142
+ };
143
+ const CLI = {
144
+ PARAMETER_ERROR: "Invalid parameter"
145
+ };
146
+ const DEVELOPER = {
147
+ PROSOPO_SITE_KEY_MISSING: "PROSOPO_SITE_KEY is not set in .env file.",
148
+ BALANCE_TOO_LOW: "{{mnemonic}} balance too low: {{balance}}",
149
+ CAPTCHA_ID_MISSING: "Cannot find captcha data id",
150
+ COMMITMENT_ID_MISSING: "Commitment id missing",
151
+ PROVIDER_NOT_FOUND: "Provider not found",
152
+ PROVIDER_NO_CAPTCHA: "No captchas returned from provider",
153
+ CREATE_ACCOUNT_FAILED: "Could not create an account!",
154
+ CREATE_ACCOUNT_FAILED_OUT_OF_FUNDS: "Could not create an account as there are no funds. Restart the substrate node.",
155
+ NO_MOCK_ENV: "MockEnvironment not set up",
156
+ ACCOUNT_TYPE_MISSING: "{{accountType}} not created by databasePopulator",
157
+ FUNDING_FAILED: "Funding failed",
158
+ MISSING_PROVIDER_PAIR: "Missing provider pair",
159
+ NETWORK_NOT_FOUND: "Network not found",
160
+ MISSING_ENV_VARIABLE: "Missing environment variable",
161
+ GENERAL: "General Dev Error, see context",
162
+ MISSING_SECRET_KEY: "Missing secret key",
163
+ KEY_ERROR: "Key error",
164
+ METHOD_NOT_IMPLEMENTED: "Method not implemented"
165
+ };
166
+ const FS = {
167
+ DIRECTORY_NOT_FOUND: "Directory not found",
168
+ FILE_NOT_FOUND: "File not found",
169
+ FILE_ALREADY_EXISTS: "File already exists",
170
+ DIRECTORY_ALREADY_EXISTS: "Directory already exists",
171
+ SAME_FILE: "Same file",
172
+ INVALID_DIR_FORMAT: "Invalid directory format"
173
+ };
174
+ const PROGUI = {
175
+ NO_STATE_PROVIDER: "useGlobalState must be used within a GlobalStateProvider"
176
+ };
177
+ const translationEn = {
178
+ ACCOUNT,
179
+ WIDGET,
180
+ GENERAL,
181
+ CONTRACT,
182
+ CONFIG,
183
+ DATASET,
184
+ DATABASE,
185
+ CAPTCHA,
186
+ API,
187
+ CLI,
188
+ DEVELOPER,
189
+ FS,
190
+ PROGUI
191
+ };
192
+ exports.ACCOUNT = ACCOUNT;
193
+ exports.API = API;
194
+ exports.CAPTCHA = CAPTCHA;
195
+ exports.CLI = CLI;
196
+ exports.CONFIG = CONFIG;
197
+ exports.CONTRACT = CONTRACT;
198
+ exports.DATABASE = DATABASE;
199
+ exports.DATASET = DATASET;
200
+ exports.DEVELOPER = DEVELOPER;
201
+ exports.FS = FS;
202
+ exports.GENERAL = GENERAL;
203
+ exports.PROGUI = PROGUI;
204
+ exports.WIDGET = WIDGET;
205
+ exports.default = translationEn;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tslib = require("tslib");
4
+ const browser = require("consola/browser");
5
+ const zod = require("zod");
6
+ const error = require("./error.cjs");
7
+ var _Loggable_logger;
8
+ const LogLevel = zod.enum([
9
+ "trace",
10
+ "debug",
11
+ "info",
12
+ "warn",
13
+ "error",
14
+ "fatal",
15
+ "log"
16
+ ]);
17
+ function getLogger(logLevel, scope) {
18
+ return getLoggerAdapterConsola(getLogLevel(logLevel), scope);
19
+ }
20
+ function getLoggerDefault() {
21
+ return defaultLogger;
22
+ }
23
+ const getLoggerAdapterConsola = (logLevel, scope) => {
24
+ const logger = browser.createConsola({
25
+ formatOptions: { colors: true, date: true }
26
+ }).withTag(scope);
27
+ let currentLevel = logLevel;
28
+ const result = {
29
+ log: logger.log,
30
+ info: logger.info,
31
+ debug: logger.debug,
32
+ trace: logger.trace,
33
+ warn: logger.warn,
34
+ error: logger.error,
35
+ fatal: logger.fatal,
36
+ setLogLevel: (level) => {
37
+ let logLevel2 = Number.NaN;
38
+ const levelSafe = getLogLevel(level);
39
+ switch (levelSafe) {
40
+ case LogLevel.enum.trace:
41
+ logLevel2 = browser.LogLevels.trace;
42
+ break;
43
+ case LogLevel.enum.debug:
44
+ logLevel2 = browser.LogLevels.debug;
45
+ break;
46
+ case LogLevel.enum.info:
47
+ logLevel2 = browser.LogLevels.info;
48
+ break;
49
+ case LogLevel.enum.warn:
50
+ logLevel2 = browser.LogLevels.warn;
51
+ break;
52
+ case LogLevel.enum.error:
53
+ logLevel2 = browser.LogLevels.error;
54
+ break;
55
+ case LogLevel.enum.fatal:
56
+ logLevel2 = browser.LogLevels.fatal;
57
+ break;
58
+ case LogLevel.enum.log:
59
+ logLevel2 = browser.LogLevels.log;
60
+ break;
61
+ default:
62
+ throw new Error(`Invalid log level translation to consola's log level: ${level}`);
63
+ }
64
+ logger.level = logLevel2;
65
+ currentLevel = levelSafe;
66
+ },
67
+ getLogLevel: () => {
68
+ return currentLevel;
69
+ }
70
+ };
71
+ result.setLogLevel(logLevel);
72
+ return result;
73
+ };
74
+ function getLogLevel(logLevel) {
75
+ const logLevelLocal = logLevel || process.env.PROSOPO_LOG_LEVEL || "Info";
76
+ const logLevelStr = logLevelLocal.toString().toLowerCase();
77
+ try {
78
+ return LogLevel.parse(logLevelStr);
79
+ } catch (e) {
80
+ throw new error.ProsopoEnvError("CONFIG.INVALID_LOG_LEVEL", {
81
+ context: { logLevel }
82
+ });
83
+ }
84
+ }
85
+ const defaultLogger = getLoggerAdapterConsola(LogLevel.enum.info, "global");
86
+ class Loggable {
87
+ constructor() {
88
+ _Loggable_logger.set(this, void 0);
89
+ tslib.__classPrivateFieldSet(this, _Loggable_logger, getLoggerDefault(), "f");
90
+ }
91
+ get logger() {
92
+ return tslib.__classPrivateFieldGet(this, _Loggable_logger, "f");
93
+ }
94
+ set logger(logger) {
95
+ tslib.__classPrivateFieldSet(this, _Loggable_logger, logger, "f");
96
+ }
97
+ }
98
+ _Loggable_logger = /* @__PURE__ */ new WeakMap();
99
+ exports.LogLevel = LogLevel;
100
+ exports.Loggable = Loggable;
101
+ exports.getLogLevel = getLogLevel;
102
+ exports.getLogger = getLogger;
103
+ exports.getLoggerDefault = getLoggerDefault;
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ require("../index.cjs");
4
+ const error = require("../error.cjs");
5
+ class UrlConverter {
6
+ constructor() {
7
+ this.symbols = [
8
+ "",
9
+ "0",
10
+ "1",
11
+ "2",
12
+ "3",
13
+ "4",
14
+ "5",
15
+ "6",
16
+ "7",
17
+ "8",
18
+ "9",
19
+ "a",
20
+ "b",
21
+ "c",
22
+ "d",
23
+ "e",
24
+ "f",
25
+ "g",
26
+ "h",
27
+ "i",
28
+ "j",
29
+ "k",
30
+ "l",
31
+ "m",
32
+ "n",
33
+ "o",
34
+ "p",
35
+ "q",
36
+ "r",
37
+ "s",
38
+ "t",
39
+ "u",
40
+ "v",
41
+ "w",
42
+ "x",
43
+ "y",
44
+ "z",
45
+ "/",
46
+ ".",
47
+ "-",
48
+ "_",
49
+ "%",
50
+ ":",
51
+ "http://",
52
+ "https://",
53
+ "www.",
54
+ ".com",
55
+ ".net",
56
+ ".org",
57
+ ".co.uk",
58
+ ".io"
59
+ ];
60
+ this.symbolNBits = 6;
61
+ this.byteNBits = 8;
62
+ this.symbolToNumMap = this.symbols.reduce((obj, symb, i, arr) => {
63
+ obj[symb] = i;
64
+ return obj;
65
+ }, {});
66
+ this.numToSymbolMap = this.symbols.reduce((obj, symb, i, arr) => {
67
+ obj[i] = symb;
68
+ return obj;
69
+ }, {});
70
+ this.longestSymbolLength = this.symbols.reduce((longest, symb) => {
71
+ return Math.max(longest, symb.length);
72
+ }, 0);
73
+ const maxSymbols = 2 ** this.symbolNBits;
74
+ if (this.symbols.length > maxSymbols) {
75
+ throw new error.ProsopoError("DEVELOPER.GENERAL", {
76
+ context: {
77
+ error: `Cannot encode more than ${maxSymbols} symbols`,
78
+ context: "only built to encode 64 symbols. Need to adjust the encoding and decoding scheme for more symbols"
79
+ }
80
+ });
81
+ }
82
+ const symbols = this.getSymbols();
83
+ if (symbols.length !== new Set(symbols).size) {
84
+ throw new error.ProsopoError("DEVELOPER.GENERAL", {
85
+ context: { error: "Symbols must be unique" }
86
+ });
87
+ }
88
+ }
89
+ symbolToNum(symb) {
90
+ const num = this.symbolToNumNull(symb);
91
+ if (num === void 0) {
92
+ throw new error.ProsopoError("DEVELOPER.GENERAL", {
93
+ context: { error: `Could not find number for symbol '${symb}'` }
94
+ });
95
+ }
96
+ return num;
97
+ }
98
+ symbolToNumNull(symb) {
99
+ symb = symb.toLowerCase();
100
+ const num = this.symbolToNumMap[symb];
101
+ return num;
102
+ }
103
+ numToSymbol(num) {
104
+ const symb = this.numToSymbolNull(num);
105
+ if (symb === void 0) {
106
+ throw new error.ProsopoError("DEVELOPER.GENERAL", {
107
+ context: { error: `Could not find symbol for number ${num}` }
108
+ });
109
+ }
110
+ return symb;
111
+ }
112
+ numToSymbolNull(num) {
113
+ const symb = this.numToSymbolMap[num];
114
+ return symb;
115
+ }
116
+ encode(url) {
117
+ url = url.toLowerCase();
118
+ const nums = [];
119
+ const origUrl = url;
120
+ while (url.length > 0) {
121
+ let len = Math.min(url.length, this.longestSymbolLength);
122
+ let num = void 0;
123
+ while (num === void 0 && len > 0) {
124
+ const str = url.slice(0, len);
125
+ num = this.symbolToNumNull(str);
126
+ if (num === void 0) {
127
+ len--;
128
+ }
129
+ }
130
+ if (num === void 0) {
131
+ throw new error.ProsopoError("DEVELOPER.GENERAL", {
132
+ context: {
133
+ error: `Could not find symbol at '${url}' of '${origUrl}'`
134
+ }
135
+ });
136
+ }
137
+ nums.push(num);
138
+ url = url.slice(len);
139
+ }
140
+ const nBits = nums.length * this.symbolNBits;
141
+ const nBytes = Math.ceil(nBits / this.byteNBits);
142
+ const bytes = new Uint8Array(nBytes);
143
+ for (let bitCount = 0; bitCount < nBits; ) {
144
+ const numIndex = bitCount / this.symbolNBits | 0;
145
+ const num = nums[numIndex];
146
+ if (num === void 0) {
147
+ throw new error.ProsopoError("DEVELOPER.GENERAL", {
148
+ context: {
149
+ error: `Could not find number at index ${numIndex} of '${nums}'`
150
+ }
151
+ });
152
+ }
153
+ const byteIndex = bitCount / this.byteNBits | 0;
154
+ const usedBitsInByte = bitCount % this.byteNBits;
155
+ const unusedBitsInByte = this.byteNBits - usedBitsInByte;
156
+ const shift = this.symbolNBits - unusedBitsInByte;
157
+ if (shift < 0) {
158
+ const usedBitsInSymbol = bitCount % this.symbolNBits;
159
+ const unusedBitsInSymbol = this.symbolNBits - usedBitsInSymbol;
160
+ const max = 2 ** unusedBitsInSymbol;
161
+ const remNum = num % max;
162
+ const shift2 = this.byteNBits - unusedBitsInSymbol;
163
+ const shiftedNum = remNum << shift2;
164
+ bytes[byteIndex] |= shiftedNum;
165
+ bitCount += unusedBitsInSymbol;
166
+ } else {
167
+ bytes[byteIndex] |= num >> shift;
168
+ bitCount += unusedBitsInByte;
169
+ }
170
+ }
171
+ return bytes;
172
+ }
173
+ decode(bytes) {
174
+ const arr = [];
175
+ const nBits = bytes.length * this.byteNBits;
176
+ let num = 0;
177
+ let nBitsNum = 0;
178
+ for (let bitCount = 0; bitCount < nBits; ) {
179
+ const byteIndex = bitCount / this.byteNBits | 0;
180
+ const byte = bytes[byteIndex];
181
+ if (byte === void 0) {
182
+ throw new error.ProsopoError("DEVELOPER.GENERAL", {
183
+ context: {
184
+ error: `Could not find byte at index ${byteIndex} of '${bytes}'`
185
+ }
186
+ });
187
+ }
188
+ const usedBitsInByte = bitCount % this.byteNBits;
189
+ const unusedBitsInByte = this.byteNBits - usedBitsInByte;
190
+ const unusedBitsInSymbol = this.symbolNBits - nBitsNum;
191
+ const consumeNBits = Math.min(unusedBitsInByte, unusedBitsInSymbol);
192
+ const slice = this.bitSlice(byte, usedBitsInByte, consumeNBits);
193
+ num = num << consumeNBits | slice;
194
+ nBitsNum += consumeNBits;
195
+ if (nBitsNum >= this.symbolNBits) {
196
+ const symbol = this.numToSymbol(num);
197
+ arr.push(symbol);
198
+ num = 0;
199
+ nBitsNum = 0;
200
+ }
201
+ bitCount += consumeNBits;
202
+ }
203
+ return arr.join("");
204
+ }
205
+ bitSlice(num, startBit, lenBit) {
206
+ const truncedLeft = this.bitTruncLeft(num, startBit);
207
+ const truncedLen = this.bitTruncRight(truncedLeft, Math.max(0, this.byteNBits - lenBit - startBit));
208
+ return truncedLen;
209
+ }
210
+ bitTruncRight(num, nBits) {
211
+ return num >> nBits;
212
+ }
213
+ bitTruncLeft(num, nBits) {
214
+ const threshNBits = this.byteNBits - nBits;
215
+ const thresh = 2 ** threshNBits;
216
+ return thresh <= 0 ? 0 : num % thresh;
217
+ }
218
+ getSymbols() {
219
+ return this.symbols;
220
+ }
221
+ }
222
+ exports.UrlConverter = UrlConverter;
223
+ exports.default = UrlConverter;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ const i18nextHttpMiddleware = require("i18next-http-middleware");
3
+ require("../i18n.cjs");
4
+ const i18n = require("i18next");
5
+ function i18nMiddleware(options) {
6
+ return i18nextHttpMiddleware.handle(i18n, { ...options });
7
+ }
8
+ module.exports = i18nMiddleware;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const i18nMiddleware = require("./i18nMiddleware.cjs");
4
+ exports.i18nMiddleware = i18nMiddleware;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const useTranslation = require("./useTranslation.cjs");
4
+ exports.useTranslation = useTranslation;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ const reactI18next = require("react-i18next");
3
+ require("../i18n.cjs");
4
+ const i18n = require("i18next");
5
+ function useTranslation(options) {
6
+ return reactI18next.useTranslation("translation", { i18n, ...options });
7
+ }
8
+ module.exports = useTranslation;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function capitaliseFirstLetter(s) {
4
+ return s.charAt(0).toUpperCase() + s.slice(1);
5
+ }
6
+ exports.capitaliseFirstLetter = capitaliseFirstLetter;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const error = require("./error.cjs");
4
+ const en = require("./locales/en.json.cjs");
5
+ const zod = require("zod");
6
+ function isClientSide() {
7
+ return !!(typeof window !== "undefined" && window.document && window.document.createElement);
8
+ }
9
+ function getLeafFieldPath(obj) {
10
+ if (typeof obj === "string") {
11
+ return [];
12
+ }
13
+ return Object.keys(obj).reduce((arr, key) => {
14
+ const value = obj[key];
15
+ if (value === void 0) {
16
+ throw new error.ProsopoError("DEVELOPER.KEY_ERROR", {
17
+ context: { error: `Undefined value for key ${key}` }
18
+ });
19
+ }
20
+ const children = getLeafFieldPath(value);
21
+ return arr.concat(children.map((child) => {
22
+ return `${key}.${child}`;
23
+ }));
24
+ }, []);
25
+ }
26
+ const TranslationKeysSchema = zod.z.enum(getLeafFieldPath(en.default));
27
+ const TranslationFileSchema = zod.z.record(TranslationKeysSchema, zod.z.record(TranslationKeysSchema, zod.z.string()));
28
+ function reverseHexString(str) {
29
+ return `0x${str.match(/.{1,2}/g)?.reverse().join("") || ""}`;
30
+ }
31
+ exports.TranslationKeysSchema = TranslationKeysSchema;
32
+ exports.isClientSide = isClientSide;
33
+ exports.reverseHexString = reverseHexString;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const path = require("node:path");
4
+ const node_url = require("node:url");
5
+ require("./common/dist/index.cjs");
6
+ const dotenv = require("dotenv");
7
+ const findUp = require("find-up");
8
+ const logger$1 = require("./common/dist/logger.cjs");
9
+ const __filename$1 = node_url.fileURLToPath(module);
10
+ const __dirname$1 = path.dirname(__filename$1);
11
+ const logger = logger$1.getLogger(
12
+ process.env.PROSOPO_LOG_LEVEL || logger$1.LogLevel.enum.info,
13
+ "env"
14
+ );
15
+ function getEnv() {
16
+ if (process.env.NODE_ENV) {
17
+ return process.env.NODE_ENV.replace(/\W/g, "");
18
+ }
19
+ return "development";
20
+ }
21
+ function loadEnv(rootDir, filename, filePath) {
22
+ const envPath = getEnvFile(path.resolve(rootDir || "."), filename, filePath);
23
+ const args = { path: envPath };
24
+ logger.info(`Loading env from ${envPath}`);
25
+ dotenv.config(args);
26
+ return envPath;
27
+ }
28
+ function getEnvFile(rootDir, filename = ".env", filepath = path.join(__dirname$1, "../..")) {
29
+ const env = getEnv();
30
+ const fileNameFull = `${filename}.${env}`;
31
+ return findUp.findUpSync(fileNameFull, { type: "file" }) || path.join(rootDir || filepath, fileNameFull);
32
+ }
33
+ exports.getEnv = getEnv;
34
+ exports.getEnvFile = getEnvFile;
35
+ exports.loadEnv = loadEnv;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const env = require("./env.cjs");
4
+ exports.getEnv = env.getEnv;
5
+ exports.getEnvFile = env.getEnvFile;
6
+ exports.loadEnv = env.loadEnv;
package/dist/env.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare function getEnv(): string;
2
+ export declare function loadEnv(rootDir?: string, filename?: string, filePath?: string): string;
3
+ export declare function getEnvFile(rootDir?: string, filename?: string, filepath?: string): string;
4
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AA2BA,wBAAgB,MAAM,WAKrB;AAED,wBAAgB,OAAO,CACrB,OAAO,CAAC,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAMR;AASD,wBAAgB,UAAU,CACxB,OAAO,CAAC,EAAE,MAAM,EAChB,QAAQ,SAAS,EACjB,QAAQ,SAAgC,UASzC"}
package/dist/env.js ADDED
@@ -0,0 +1,28 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import { LogLevel, getLogger } from "@prosopo/common";
4
+ import dotenv from "dotenv";
5
+ import { findUpSync } from "find-up";
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+ const logger = getLogger(process.env.PROSOPO_LOG_LEVEL || LogLevel.enum.info, "env");
9
+ export function getEnv() {
10
+ if (process.env.NODE_ENV) {
11
+ return process.env.NODE_ENV.replace(/\W/g, "");
12
+ }
13
+ return "development";
14
+ }
15
+ export function loadEnv(rootDir, filename, filePath) {
16
+ const envPath = getEnvFile(path.resolve(rootDir || "."), filename, filePath);
17
+ const args = { path: envPath };
18
+ logger.info(`Loading env from ${envPath}`);
19
+ dotenv.config(args);
20
+ return envPath;
21
+ }
22
+ export function getEnvFile(rootDir, filename = ".env", filepath = path.join(__dirname, "../..")) {
23
+ const env = getEnv();
24
+ const fileNameFull = `${filename}.${env}`;
25
+ return (findUpSync(fileNameFull, { type: "file" }) ||
26
+ path.join(rootDir || filepath, fileNameFull));
27
+ }
28
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAcA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAC3C,MAAM,MAAM,GAAG,SAAS,CACtB,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,EACnD,KAAK,CACN,CAAC;AAEF,MAAM,UAAU,MAAM;IACpB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE;QACxB,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;KAChD;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,OAAO,CACrB,OAAgB,EAChB,QAAiB,EACjB,QAAiB;IAEjB,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,GAAG,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC7E,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC/B,MAAM,CAAC,IAAI,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;IAC3C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpB,OAAO,OAAO,CAAC;AACjB,CAAC;AASD,MAAM,UAAU,UAAU,CACxB,OAAgB,EAChB,QAAQ,GAAG,MAAM,EACjB,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC;IAExC,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,YAAY,GAAG,GAAG,QAAQ,IAAI,GAAG,EAAE,CAAC;IAE1C,OAAO,CACL,UAAU,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC1C,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,QAAQ,EAAE,YAAY,CAAC,CAC7C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./env.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./env.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@prosopo/dotenv",
3
+ "version": "2.0.2",
4
+ "author": "PROSOPO LIMITED <info@prosopo.io>",
5
+ "license": "Apache-2.0",
6
+ "private": false,
7
+ "engines": {
8
+ "node": ">=20",
9
+ "npm": ">=9"
10
+ },
11
+ "scripts": {
12
+ "clean": "tsc --build --clean",
13
+ "build": "tsc --build --verbose",
14
+ "build:cjs": "npx vite --config vite.cjs.config.ts build",
15
+ "cli": "node ./dist/js/cli.js",
16
+ "test": "echo \"No test specified\""
17
+ },
18
+ "main": "./dist/index.js",
19
+ "type": "module",
20
+ "exports": {
21
+ ".": {
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/cjs/index.cjs"
24
+ }
25
+ },
26
+ "types": "./dist/index.d.ts",
27
+ "dependencies": {
28
+ "dotenv": "^16.0.1",
29
+ "find-up": "^7.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "tslib": "2.6.2",
33
+ "typescript": "5.1.6"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/prosopo/captcha.git"
38
+ },
39
+ "bugs": {
40
+ "url": "https://github.com/prosopo/captcha/issues"
41
+ },
42
+ "homepage": "https://github.com/prosopo/captcha#readme",
43
+ "publishConfig": {
44
+ "registry": "https://registry.npmjs.org"
45
+ },
46
+ "description": "Package to handle environment discovery and loading",
47
+ "sideEffects": false
48
+ }
@@ -0,0 +1,19 @@
1
+ import path from "node:path";
2
+ // Copyright 2021-2024 Prosopo (UK) Ltd.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ import { ViteCommonJSConfig } from "@prosopo/config";
16
+
17
+ export default function () {
18
+ return ViteCommonJSConfig("util", path.resolve("./tsconfig.cjs.json"));
19
+ }
@@ -0,0 +1,32 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ // Copyright 2021-2024 Prosopo (UK) Ltd.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 (the "License");
6
+ // you may not use this file except in compliance with the License.
7
+ // You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing, software
12
+ // distributed under the License is distributed on an "AS IS" BASIS,
13
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ // See the License for the specific language governing permissions and
15
+ // limitations under the License.
16
+ import { ViteTestConfig } from "@prosopo/config";
17
+ import dotenv from "dotenv";
18
+ process.env.NODE_ENV = "test";
19
+ // if .env.test exists at this level, use it, otherwise use the one at the root
20
+ const envFile = `.env.${process.env.NODE_ENV || "development"}`;
21
+ let envPath = envFile;
22
+ if (fs.existsSync(envFile)) {
23
+ envPath = path.resolve(envFile);
24
+ } else if (fs.existsSync(`../../${envFile}`)) {
25
+ envPath = path.resolve(`../../${envFile}`);
26
+ } else {
27
+ throw new Error(`No ${envFile} file found`);
28
+ }
29
+
30
+ dotenv.config({ path: envPath });
31
+
32
+ export default ViteTestConfig;