@lyxa.ai/core 1.0.240 → 1.0.242

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.
@@ -14,6 +14,12 @@ async function initGlobalConnection(uri, environment) {
14
14
  console.log(`Initializing global connection for environment: ${environment}`);
15
15
  const connection = (0, mongoose_1.createConnection)(uri, {
16
16
  dbName: `lyxa-${environment}-global`,
17
+ maxPoolSize: 10,
18
+ minPoolSize: 2,
19
+ maxIdleTimeMS: 30000,
20
+ waitQueueTimeoutMS: 5000,
21
+ retryWrites: true,
22
+ w: 'majority',
17
23
  });
18
24
  await new Promise((connectResolve, connectReject) => {
19
25
  connection.once('connected', () => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/mongo/index.ts"],"names":[],"mappings":";;AAUA,oDA2BC;AAKD,sEAEC;AAKD,kDAKC;AAtDD,uCAAwD;AACxD,qCAAkD;AAGlD,IAAI,gBAAwC,CAAC;AAC7C,IAAI,iBAAiB,GAA+B,IAAI,CAAC;AAKlD,KAAK,UAAU,oBAAoB,CAAC,GAAW,EAAE,WAAmB;IAC1E,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACxB,iBAAiB,GAAG,IAAI,OAAO,CAAa,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;YACrE,IAAI,CAAC;gBACJ,OAAO,CAAC,GAAG,CAAC,mDAAmD,WAAW,EAAE,CAAC,CAAC;gBAC9E,MAAM,UAAU,GAAG,IAAA,2BAAgB,EAAC,GAAG,EAAE;oBACxC,MAAM,EAAE,QAAQ,WAAW,SAAS;iBACpC,CAAC,CAAC;gBAEH,MAAM,IAAI,OAAO,CAAO,CAAC,cAAc,EAAE,aAAa,EAAE,EAAE;oBACzD,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;wBACjC,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;wBAC1D,gBAAgB,GAAG,UAAU,CAAC;wBAC9B,cAAc,EAAE,CAAC;oBAClB,CAAC,CAAC,CAAC;oBACH,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;gBACzC,CAAC,CAAC,CAAC;gBAEH,IAAA,+BAAsB,EAAC,gBAAgB,CAAC,CAAC;gBAEzC,OAAO,CAAC,UAAU,CAAC,CAAC;YACrB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,MAAM,CAAC,KAAK,CAAC,CAAC;YACf,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC1B,CAAC;AAKD,SAAgB,6BAA6B;IAC5C,OAAO,CAAC,CAAC,gBAAgB,CAAC;AAC3B,CAAC;AAKD,SAAgB,mBAAmB;IAClC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;IAC1F,CAAC;IACD,OAAO,gBAAgB,CAAC;AACzB,CAAC","sourcesContent":["import { Connection, createConnection } from 'mongoose';\nimport { initializeGlobalModels } from './models';\n\n// Track connection status\nlet globalConnection: Connection | undefined;\nlet connectionPromise: Promise<Connection> | null = null;\n\n/**\n * Initialize the global database connection and create all global models\n */\nexport async function initGlobalConnection(uri: string, environment: string): Promise<Connection> {\n\tif (!connectionPromise) {\n\t\tconnectionPromise = new Promise<Connection>(async (resolve, reject) => {\n\t\t\ttry {\n\t\t\t\tconsole.log(`Initializing global connection for environment: ${environment}`);\n\t\t\t\tconst connection = createConnection(uri, {\n\t\t\t\t\tdbName: `lyxa-${environment}-global`,\n\t\t\t\t});\n\n\t\t\t\tawait new Promise<void>((connectResolve, connectReject) => {\n\t\t\t\t\tconnection.once('connected', () => {\n\t\t\t\t\t\tconsole.log('Global connection successfully established');\n\t\t\t\t\t\tglobalConnection = connection;\n\t\t\t\t\t\tconnectResolve();\n\t\t\t\t\t});\n\t\t\t\t\tconnection.once('error', connectReject);\n\t\t\t\t});\n\n\t\t\t\tinitializeGlobalModels(globalConnection);\n\n\t\t\t\tresolve(connection);\n\t\t\t} catch (error) {\n\t\t\t\treject(error);\n\t\t\t}\n\t\t});\n\t}\n\treturn connectionPromise;\n}\n\n/**\n * Check if the global connection is initialized\n */\nexport function isGlobalConnectionInitialized(): boolean {\n\treturn !!globalConnection;\n}\n\n/**\n * Get the global connection (throws if not initialized)\n */\nexport function getGlobalConnection(): Connection {\n\tif (!globalConnection) {\n\t\tthrow new Error('Global connection not initialized. Call initGlobalConnection() first.');\n\t}\n\treturn globalConnection;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/mongo/index.ts"],"names":[],"mappings":";;AAUA,oDAiCC;AAKD,sEAEC;AAKD,kDAKC;AA5DD,uCAAwD;AACxD,qCAAkD;AAGlD,IAAI,gBAAwC,CAAC;AAC7C,IAAI,iBAAiB,GAA+B,IAAI,CAAC;AAKlD,KAAK,UAAU,oBAAoB,CAAC,GAAW,EAAE,WAAmB;IAC1E,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACxB,iBAAiB,GAAG,IAAI,OAAO,CAAa,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;YACrE,IAAI,CAAC;gBACJ,OAAO,CAAC,GAAG,CAAC,mDAAmD,WAAW,EAAE,CAAC,CAAC;gBAC9E,MAAM,UAAU,GAAG,IAAA,2BAAgB,EAAC,GAAG,EAAE;oBACxC,MAAM,EAAE,QAAQ,WAAW,SAAS;oBACpC,WAAW,EAAE,EAAE;oBACf,WAAW,EAAE,CAAC;oBACd,aAAa,EAAE,KAAK;oBACpB,kBAAkB,EAAE,IAAI;oBACxB,WAAW,EAAE,IAAI;oBACjB,CAAC,EAAE,UAAU;iBACb,CAAC,CAAC;gBAEH,MAAM,IAAI,OAAO,CAAO,CAAC,cAAc,EAAE,aAAa,EAAE,EAAE;oBACzD,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;wBACjC,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;wBAC1D,gBAAgB,GAAG,UAAU,CAAC;wBAC9B,cAAc,EAAE,CAAC;oBAClB,CAAC,CAAC,CAAC;oBACH,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;gBACzC,CAAC,CAAC,CAAC;gBAEH,IAAA,+BAAsB,EAAC,gBAAgB,CAAC,CAAC;gBAEzC,OAAO,CAAC,UAAU,CAAC,CAAC;YACrB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,MAAM,CAAC,KAAK,CAAC,CAAC;YACf,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC1B,CAAC;AAKD,SAAgB,6BAA6B;IAC5C,OAAO,CAAC,CAAC,gBAAgB,CAAC;AAC3B,CAAC;AAKD,SAAgB,mBAAmB;IAClC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;IAC1F,CAAC;IACD,OAAO,gBAAgB,CAAC;AACzB,CAAC","sourcesContent":["import { Connection, createConnection } from 'mongoose';\nimport { initializeGlobalModels } from './models';\n\n// Track connection status\nlet globalConnection: Connection | undefined;\nlet connectionPromise: Promise<Connection> | null = null;\n\n/**\n * Initialize the global database connection and create all global models\n */\nexport async function initGlobalConnection(uri: string, environment: string): Promise<Connection> {\n\tif (!connectionPromise) {\n\t\tconnectionPromise = new Promise<Connection>(async (resolve, reject) => {\n\t\t\ttry {\n\t\t\t\tconsole.log(`Initializing global connection for environment: ${environment}`);\n\t\t\t\tconst connection = createConnection(uri, {\n\t\t\t\t\tdbName: `lyxa-${environment}-global`,\n\t\t\t\t\tmaxPoolSize: 10,\n\t\t\t\t\tminPoolSize: 2,\n\t\t\t\t\tmaxIdleTimeMS: 30000,\n\t\t\t\t\twaitQueueTimeoutMS: 5000,\n\t\t\t\t\tretryWrites: true,\n\t\t\t\t\tw: 'majority',\n\t\t\t\t});\n\n\t\t\t\tawait new Promise<void>((connectResolve, connectReject) => {\n\t\t\t\t\tconnection.once('connected', () => {\n\t\t\t\t\t\tconsole.log('Global connection successfully established');\n\t\t\t\t\t\tglobalConnection = connection;\n\t\t\t\t\t\tconnectResolve();\n\t\t\t\t\t});\n\t\t\t\t\tconnection.once('error', connectReject);\n\t\t\t\t});\n\n\t\t\t\tinitializeGlobalModels(globalConnection);\n\n\t\t\t\tresolve(connection);\n\t\t\t} catch (error) {\n\t\t\t\treject(error);\n\t\t\t}\n\t\t});\n\t}\n\treturn connectionPromise;\n}\n\n/**\n * Check if the global connection is initialized\n */\nexport function isGlobalConnectionInitialized(): boolean {\n\treturn !!globalConnection;\n}\n\n/**\n * Get the global connection (throws if not initialized)\n */\nexport function getGlobalConnection(): Connection {\n\tif (!globalConnection) {\n\t\tthrow new Error('Global connection not initialized. Call initGlobalConnection() first.');\n\t}\n\treturn globalConnection;\n}\n"]}
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.0.240
25
+ Version: 1.0.242
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.0.240",
3
+ "version": "1.0.242",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -2,4 +2,6 @@ import { PaidCurrency } from './enum';
2
2
  export declare const getRoundingFactor: (currency: PaidCurrency) => Promise<number>;
3
3
  export declare const getExchangeRate: () => Promise<number>;
4
4
  export declare const roundCurrency: (amount: number, currency: PaidCurrency, roundingFactor?: number) => Promise<number>;
5
+ export declare const roundCurrencySync: (amount: number, roundingFactor: number) => number;
5
6
  export declare const convertToSecondary: (amount: number, exchangeRate?: number, roundTo?: number) => Promise<number>;
7
+ export declare const convertToSecondarySync: (price: number, exchangeRate: number, roundTo: number) => number | null;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToSecondary = exports.roundCurrency = exports.getExchangeRate = exports.getRoundingFactor = void 0;
3
+ exports.convertToSecondarySync = exports.convertToSecondary = exports.roundCurrencySync = exports.roundCurrency = exports.getExchangeRate = exports.getRoundingFactor = void 0;
4
4
  const __1 = require("..");
5
5
  const enum_1 = require("./enum");
6
- const DEFAULT_ROUNDING_FACTOR = 0.01;
6
+ const DEFAULT_ROUNDING_FACTOR = 0.1;
7
7
  const DEFAULT_EXCHANGE_RATE = 1;
8
8
  const getRoundingFactor = async (currency) => {
9
9
  const setting = (await (0, __1.getLibraries)().getCachedSettingsService().getSettings());
@@ -33,12 +33,27 @@ const getExchangeRate = async () => {
33
33
  exports.getExchangeRate = getExchangeRate;
34
34
  const roundCurrency = async (amount, currency, roundingFactor) => {
35
35
  roundingFactor = roundingFactor ?? (await (0, exports.getRoundingFactor)(currency));
36
- return Math.ceil(amount / roundingFactor) * roundingFactor;
36
+ return (0, exports.roundCurrencySync)(amount, roundingFactor);
37
37
  };
38
38
  exports.roundCurrency = roundCurrency;
39
+ const roundCurrencySync = (amount, roundingFactor) => {
40
+ const rounded = Math.ceil(amount / roundingFactor) * roundingFactor;
41
+ const decimals = (roundingFactor.toString().split('.')[1] || '').length;
42
+ return Number(rounded.toFixed(decimals));
43
+ };
44
+ exports.roundCurrencySync = roundCurrencySync;
39
45
  const convertToSecondary = async (amount, exchangeRate, roundTo) => {
40
46
  exchangeRate = exchangeRate ?? (await (0, exports.getExchangeRate)());
41
47
  return (0, exports.roundCurrency)(amount * exchangeRate, enum_1.PaidCurrency.SECONDARY, roundTo);
42
48
  };
43
49
  exports.convertToSecondary = convertToSecondary;
50
+ const convertToSecondarySync = (price, exchangeRate, roundTo) => {
51
+ if (price == null)
52
+ return null;
53
+ const amount = price * exchangeRate;
54
+ if (!roundTo)
55
+ return amount;
56
+ return (0, exports.roundCurrencySync)(amount, roundTo);
57
+ };
58
+ exports.convertToSecondarySync = convertToSecondarySync;
44
59
  //# sourceMappingURL=currency.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/currency.ts"],"names":[],"mappings":";;;AAAA,0BAAkC;AAGlC,iCAAsC;AAEtC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEzB,MAAM,iBAAiB,GAAG,KAAK,EAAE,QAAsB,EAAmB,EAAE;IAClF,MAAM,OAAO,GAAG,CAAC,MAAM,IAAA,gBAAY,GAAE,CAAC,wBAAwB,EAAE,CAAC,WAAW,EAAE,CAAY,CAAC;IAC3F,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAChD,IAAI,cAAkC,CAAC;IACvC,IAAI,eAAe,EAAE,CAAC;QACrB,QAAQ,QAAQ,EAAE,CAAC;YAClB,KAAK,mBAAY,CAAC,IAAI;gBACrB,cAAc,GAAG,eAAe,CAAC,YAAY,EAAE,OAAO,CAAC;gBACvD,MAAM;YACP,KAAK,mBAAY,CAAC,SAAS;gBAC1B,cAAc,GAAG,eAAe,CAAC,iBAAiB,EAAE,OAAO,CAAC;gBAC5D,MAAM;YACP;gBACC,cAAc,GAAG,uBAAuB,CAAC;gBACzC,MAAM;QACR,CAAC;IACF,CAAC;IACD,OAAO,cAAc,IAAI,uBAAuB,CAAC;AAClD,CAAC,CAAC;AAlBW,QAAA,iBAAiB,qBAkB5B;AAEK,MAAM,eAAe,GAAG,KAAK,IAAqB,EAAE;IAC1D,MAAM,QAAQ,GAAG,CAAC,MAAM,IAAA,gBAAY,GAAE,CAAC,wBAAwB,EAAE,CAAC,WAAW,EAAE,CAAY,CAAC;IAC5F,MAAM,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;IACjD,OAAO,eAAe,EAAE,YAAY,IAAI,qBAAqB,CAAC;AAC/D,CAAC,CAAC;AAJW,QAAA,eAAe,mBAI1B;AAEK,MAAM,aAAa,GAAG,KAAK,EACjC,MAAc,EACd,QAAsB,EACtB,cAAuB,EACL,EAAE;IACpB,cAAc,GAAG,cAAc,IAAI,CAAC,MAAM,IAAA,yBAAiB,EAAC,QAAQ,CAAC,CAAC,CAAC;IACvE,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,GAAG,cAAc,CAAC;AAC5D,CAAC,CAAC;AAPW,QAAA,aAAa,iBAOxB;AAEK,MAAM,kBAAkB,GAAG,KAAK,EACtC,MAAc,EACd,YAAqB,EACrB,OAAgB,EACE,EAAE;IACpB,YAAY,GAAG,YAAY,IAAI,CAAC,MAAM,IAAA,uBAAe,GAAE,CAAC,CAAC;IACzD,OAAO,IAAA,qBAAa,EAAC,MAAM,GAAG,YAAY,EAAE,mBAAY,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAC9E,CAAC,CAAC;AAPW,QAAA,kBAAkB,sBAO7B","sourcesContent":["import { getLibraries } from '..';\n\nimport { Setting } from '../libraries/mongo/models';\nimport { PaidCurrency } from './enum';\n\nconst DEFAULT_ROUNDING_FACTOR = 0.01;\nconst DEFAULT_EXCHANGE_RATE = 1;\n\nexport const getRoundingFactor = async (currency: PaidCurrency): Promise<number> => {\n\tconst setting = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\tconst currencySetting = setting.currencySetting;\n\tlet roundingFactor: number | undefined;\n\tif (currencySetting) {\n\t\tswitch (currency) {\n\t\t\tcase PaidCurrency.BASE:\n\t\t\t\troundingFactor = currencySetting.baseCurrency?.roundTo;\n\t\t\t\tbreak;\n\t\t\tcase PaidCurrency.SECONDARY:\n\t\t\t\troundingFactor = currencySetting.secondaryCurrency?.roundTo;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\troundingFactor = DEFAULT_ROUNDING_FACTOR;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\treturn roundingFactor || DEFAULT_ROUNDING_FACTOR;\n};\n\nexport const getExchangeRate = async (): Promise<number> => {\n\tconst settings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\tconst currencySetting = settings.currencySetting;\n\treturn currencySetting?.exchangeRate || DEFAULT_EXCHANGE_RATE;\n};\n\nexport const roundCurrency = async (\n\tamount: number,\n\tcurrency: PaidCurrency,\n\troundingFactor?: number\n): Promise<number> => {\n\troundingFactor = roundingFactor ?? (await getRoundingFactor(currency));\n\treturn Math.ceil(amount / roundingFactor) * roundingFactor;\n};\n\nexport const convertToSecondary = async (\n\tamount: number,\n\texchangeRate?: number,\n\troundTo?: number\n): Promise<number> => {\n\texchangeRate = exchangeRate ?? (await getExchangeRate());\n\treturn roundCurrency(amount * exchangeRate, PaidCurrency.SECONDARY, roundTo);\n};\n"]}
1
+ {"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/currency.ts"],"names":[],"mappings":"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","sourcesContent":["import { getLibraries } from '..';\n\nimport { Setting } from '../libraries/mongo/models';\nimport { PaidCurrency } from './enum';\n\nconst DEFAULT_ROUNDING_FACTOR = 0.1;\nconst DEFAULT_EXCHANGE_RATE = 1;\n\nexport const getRoundingFactor = async (currency: PaidCurrency): Promise<number> => {\n\tconst setting = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\tconst currencySetting = setting.currencySetting;\n\tlet roundingFactor: number | undefined;\n\tif (currencySetting) {\n\t\tswitch (currency) {\n\t\t\tcase PaidCurrency.BASE:\n\t\t\t\troundingFactor = currencySetting.baseCurrency?.roundTo;\n\t\t\t\tbreak;\n\t\t\tcase PaidCurrency.SECONDARY:\n\t\t\t\troundingFactor = currencySetting.secondaryCurrency?.roundTo;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\troundingFactor = DEFAULT_ROUNDING_FACTOR;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\treturn roundingFactor || DEFAULT_ROUNDING_FACTOR;\n};\n\nexport const getExchangeRate = async (): Promise<number> => {\n\tconst settings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\tconst currencySetting = settings.currencySetting;\n\treturn currencySetting?.exchangeRate || DEFAULT_EXCHANGE_RATE;\n};\n\nexport const roundCurrency = async (\n\tamount: number,\n\tcurrency: PaidCurrency,\n\troundingFactor?: number\n): Promise<number> => {\n\troundingFactor = roundingFactor ?? (await getRoundingFactor(currency));\n\treturn roundCurrencySync(amount, roundingFactor);\n};\n\nexport const roundCurrencySync = (\n\tamount: number,\n\troundingFactor: number\n): number => {\n\tconst rounded = Math.ceil(amount / roundingFactor) * roundingFactor;\n\tconst decimals = (roundingFactor.toString().split('.')[1] || '').length;\n\treturn Number(rounded.toFixed(decimals));\n};\n\nexport const convertToSecondary = async (\n\tamount: number,\n\texchangeRate?: number,\n\troundTo?: number\n): Promise<number> => {\n\texchangeRate = exchangeRate ?? (await getExchangeRate());\n\treturn roundCurrency(amount * exchangeRate, PaidCurrency.SECONDARY, roundTo);\n};\n\nexport const convertToSecondarySync = (price: number, exchangeRate: number, roundTo: number) => {\n\tif (price == null) return null;\n\tconst amount = price * exchangeRate;\n\tif (!roundTo) return amount;\n\treturn roundCurrencySync(amount, roundTo);\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.0.240",
3
+ "version": "1.0.242",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",