diff --git a/README.md b/README.md index 5c692ef963..3408fddeab 100644 --- a/README.md +++ b/README.md @@ -67,41 +67,39 @@ For usage directly in the browser with a script tag -Package | Category | Version | Download ---- | --- | --- | --- -| [@lit-protocol/lit-node-client-nodejs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client-nodejs) | ![lit-node-client-nodejs](https://img.shields.io/badge/-nodejs-2E8B57 "lit-node-client-nodejs") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/lit-node-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client) | ![lit-node-client](https://img.shields.io/badge/-universal-8A6496 "lit-node-client") | 3.1.1 | npm
Vanilla JS (UMD) - +| Package | Category | Version | Download | +| -------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [@lit-protocol/lit-node-client-nodejs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client-nodejs) | ![lit-node-client-nodejs](https://img.shields.io/badge/-nodejs-2E8B57 'lit-node-client-nodejs') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/lit-node-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-node-client) | ![lit-node-client](https://img.shields.io/badge/-universal-8A6496 'lit-node-client') | 3.1.1 | npm
Vanilla JS (UMD) | If you're a tech-savvy user and wish to utilize only specific submodules that our main module relies upon, you can find individual packages listed below. This way, you can import only the necessary packages that cater to your specific use case:: - -Package | Category | Version | Download ---- | --- | --- | --- -| [@lit-protocol/access-control-conditions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions) | ![access-control-conditions](https://img.shields.io/badge/-universal-8A6496 "access-control-conditions") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/auth-helpers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-helpers) | ![auth-helpers](https://img.shields.io/badge/-universal-8A6496 "auth-helpers") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/bls-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/bls-sdk) | ![bls-sdk](https://img.shields.io/badge/-universal-8A6496 "bls-sdk") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/constants](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/constants) | ![constants](https://img.shields.io/badge/-universal-8A6496 "constants") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/contracts-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/contracts-sdk) | ![contracts-sdk](https://img.shields.io/badge/-universal-8A6496 "contracts-sdk") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/core](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/core) | ![core](https://img.shields.io/badge/-universal-8A6496 "core") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 "crypto") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/ecdsa-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/ecdsa-sdk) | ![ecdsa-sdk](https://img.shields.io/badge/-universal-8A6496 "ecdsa-sdk") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/encryption](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/encryption) | ![encryption](https://img.shields.io/badge/-universal-8A6496 "encryption") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/lit-third-party-libs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-third-party-libs) | ![lit-third-party-libs](https://img.shields.io/badge/-universal-8A6496 "lit-third-party-libs") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/logger](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/logger) | ![logger](https://img.shields.io/badge/-universal-8A6496 "logger") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/misc](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc) | ![misc](https://img.shields.io/badge/-universal-8A6496 "misc") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/nacl](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/nacl) | ![nacl](https://img.shields.io/badge/-universal-8A6496 "nacl") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/pkp-base](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-base) | ![pkp-base](https://img.shields.io/badge/-universal-8A6496 "pkp-base") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/pkp-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-client) | ![pkp-client](https://img.shields.io/badge/-universal-8A6496 "pkp-client") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/pkp-cosmos](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-cosmos) | ![pkp-cosmos](https://img.shields.io/badge/-universal-8A6496 "pkp-cosmos") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/pkp-ethers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-ethers) | ![pkp-ethers](https://img.shields.io/badge/-universal-8A6496 "pkp-ethers") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/pkp-sui](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-sui) | ![pkp-sui](https://img.shields.io/badge/-universal-8A6496 "pkp-sui") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/pkp-walletconnect](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-walletconnect) | ![pkp-walletconnect](https://img.shields.io/badge/-universal-8A6496 "pkp-walletconnect") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/sev-snp-utils-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/sev-snp-utils-sdk) | ![sev-snp-utils-sdk](https://img.shields.io/badge/-universal-8A6496 "sev-snp-utils-sdk") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 "types") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/uint8arrays](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/uint8arrays) | ![uint8arrays](https://img.shields.io/badge/-universal-8A6496 "uint8arrays") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/auth-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-browser) | ![auth-browser](https://img.shields.io/badge/-browser-E98869 "auth-browser") | 3.1.1 | npm
Vanilla JS (UMD) -| [@lit-protocol/misc-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc-browser) | ![misc-browser](https://img.shields.io/badge/-browser-E98869 "misc-browser") | 3.1.1 | npm
Vanilla JS (UMD) +| Package | Category | Version | Download | +| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [@lit-protocol/access-control-conditions](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/access-control-conditions) | ![access-control-conditions](https://img.shields.io/badge/-universal-8A6496 'access-control-conditions') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/auth-helpers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-helpers) | ![auth-helpers](https://img.shields.io/badge/-universal-8A6496 'auth-helpers') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/bls-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/bls-sdk) | ![bls-sdk](https://img.shields.io/badge/-universal-8A6496 'bls-sdk') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/constants](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/constants) | ![constants](https://img.shields.io/badge/-universal-8A6496 'constants') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/contracts-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/contracts-sdk) | ![contracts-sdk](https://img.shields.io/badge/-universal-8A6496 'contracts-sdk') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/core](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/core) | ![core](https://img.shields.io/badge/-universal-8A6496 'core') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/crypto](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/crypto) | ![crypto](https://img.shields.io/badge/-universal-8A6496 'crypto') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/ecdsa-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/ecdsa-sdk) | ![ecdsa-sdk](https://img.shields.io/badge/-universal-8A6496 'ecdsa-sdk') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/encryption](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/encryption) | ![encryption](https://img.shields.io/badge/-universal-8A6496 'encryption') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/lit-third-party-libs](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/lit-third-party-libs) | ![lit-third-party-libs](https://img.shields.io/badge/-universal-8A6496 'lit-third-party-libs') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/logger](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/logger) | ![logger](https://img.shields.io/badge/-universal-8A6496 'logger') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/misc](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc) | ![misc](https://img.shields.io/badge/-universal-8A6496 'misc') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/nacl](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/nacl) | ![nacl](https://img.shields.io/badge/-universal-8A6496 'nacl') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/pkp-base](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-base) | ![pkp-base](https://img.shields.io/badge/-universal-8A6496 'pkp-base') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/pkp-client](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-client) | ![pkp-client](https://img.shields.io/badge/-universal-8A6496 'pkp-client') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/pkp-cosmos](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-cosmos) | ![pkp-cosmos](https://img.shields.io/badge/-universal-8A6496 'pkp-cosmos') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/pkp-ethers](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-ethers) | ![pkp-ethers](https://img.shields.io/badge/-universal-8A6496 'pkp-ethers') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/pkp-sui](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-sui) | ![pkp-sui](https://img.shields.io/badge/-universal-8A6496 'pkp-sui') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/pkp-walletconnect](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/pkp-walletconnect) | ![pkp-walletconnect](https://img.shields.io/badge/-universal-8A6496 'pkp-walletconnect') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/sev-snp-utils-sdk](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/sev-snp-utils-sdk) | ![sev-snp-utils-sdk](https://img.shields.io/badge/-universal-8A6496 'sev-snp-utils-sdk') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/types](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/types) | ![types](https://img.shields.io/badge/-universal-8A6496 'types') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/uint8arrays](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/uint8arrays) | ![uint8arrays](https://img.shields.io/badge/-universal-8A6496 'uint8arrays') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/auth-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/auth-browser) | ![auth-browser](https://img.shields.io/badge/-browser-E98869 'auth-browser') | 3.1.1 | npm
Vanilla JS (UMD) | +| [@lit-protocol/misc-browser](https://github.com/LIT-Protocol/js-sdk/tree/master/packages/misc-browser) | ![misc-browser](https://img.shields.io/badge/-browser-E98869 'misc-browser') | 3.1.1 | npm
Vanilla JS (UMD) | diff --git a/apps/html/index.html b/apps/html/index.html index b463411794..8e4577c88e 100644 --- a/apps/html/index.html +++ b/apps/html/index.html @@ -1,4 +1,4 @@ - + @@ -62,7 +62,7 @@ - (HTML) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-html.mjs Thu, 01 Feb 2024 20:59:26 GMT + (HTML) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-html.mjs Wed, 31 Jan 2024 14:30:15 GMT diff --git a/apps/react/src/app/app.tsx b/apps/react/src/app/app.tsx index e51977dacf..0e7e7873b9 100644 --- a/apps/react/src/app/app.tsx +++ b/apps/react/src/app/app.tsx @@ -1879,7 +1879,7 @@ pre { `, }} /> - (REACT) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-react.mjs Thu, 01 Feb 2024 20:59:26 GMT + (REACT) THIS FILE IS AUTOMATICALLY GENERATED FROM tools/scripts/gen-react.mjs Wed, 31 Jan 2024 14:30:16 GMT
diff --git a/lit.config.json b/lit.config.json index 6cd9a9e4ba..e5f3b40d87 100644 --- a/lit.config.json +++ b/lit.config.json @@ -42,13 +42,13 @@ "address": "0xeF71c2604f17Ec6Fc13409DF24EfdC440D240d37" }, "CACHE": { - "network": "cayenne", - "debug": true, + "network": "manzano", + "debug": false, "sevAttestation": false, "CONTROLLER_AUTHSIG": { - "sig": "0x1620fb611ab3dc6ac1388feea6edc4cec973a23b280ed0f41440ca602807914e2c57238bf72695b9f6971a470a871d10fe17d9fc6c11ce5ed5f00489dd456dfe1c", + "sig": "0x96ddc8d8c043fa2dd5e3add2c0147a841efdcba41b385a9c2f06b3e30af2581d14c8c14beafa4fa9f928f0e5d41bf6c244297c6beb123096c4bb3f27dbdaa6f01b", "derivedVia": "web3.eth.personal.sign", - "signedMessage": "localhost wants you to sign in with your Ethereum account:\n0xeF71c2604f17Ec6Fc13409DF24EfdC440D240d37\n\nThis is a test statement. You can put anything you want here.\n\nURI: https://localhost/login\nVersion: 1\nChain ID: 1\nNonce: 0xb75ade4f99b009febf749ec834cf50a98a1adb620cdc8b36815af17360f2038e\nIssued At: 2024-01-26T19:47:49.093Z\nExpiration Time: 2024-01-26T20:47:49.090Z", + "signedMessage": "localhost wants you to sign in with your Ethereum account:\n0xeF71c2604f17Ec6Fc13409DF24EfdC440D240d37\n\nThis is a test statement. You can put anything you want here.\n\nURI: https://localhost/login\nVersion: 1\nChain ID: 1\nNonce: 0x6e94513fa67e0a7afb47d1a9542b2ddb17f2c733ac80e16a30e9c862e46b088c\nIssued At: 2024-01-31T21:38:08.528Z\nExpiration Time: 2024-01-31T22:38:08.521Z", "address": "0xeF71c2604f17Ec6Fc13409DF24EfdC440D240d37" }, "CONTROLLER_WALLET": { @@ -58,9 +58,7 @@ "_isProvider": true, "_events": [], "_emitted": { - "block": -2, - "t:0x462949f6b15916679ee0064c8c8727be8fccfe8f0152961b0e84058ce09c67fe": 1603412, - "t:0x614657b89a19ed2f67a214da6c9643e5ec964c1d2ea8a874a50b64778b586133": 1603413 + "block": -2 }, "disableCcipRead": false, "formatter": { @@ -77,41 +75,27 @@ }, "anyNetwork": false, "_networkPromise": {}, - "_maxInternalBlockNumber": 1603411, + "_maxInternalBlockNumber": -1024, "_lastBlockNumber": -2, "_maxFilterBlockRange": 10, "_pollingInterval": 4000, - "_fastQueryDate": 1706298471023, + "_fastQueryDate": 0, "connection": { "url": "https://chain-rpc.litprotocol.com/http" }, - "_nextId": 73, + "_nextId": 43, "_eventLoopCache": { "detectNetwork": null, - "eth_chainId": null, - "eth_blockNumber": null + "eth_chainId": null }, "_network": { "chainId": 175177, "name": "unknown" - }, - "_internalBlockNumber": {}, - "_fastBlockNumber": 1603411, - "_fastBlockNumberPromise": {} + } } }, "PKP_INFO": { - "tokenId": "0x3e3c60f0463a34bd09a44718981bd730690472e2599e050efa92d4969598bed8", - "publicKey": "04de7a670e32bd9cf043f29ea259e5ba50d5ed85fc146478bca9552bfd5f7d6fee9bb377438c25c8fffd5874eb0ede9ea7e594da0f49221d7024b5fdf0577c212a", - "ethAddress": "0xE7cF6e45927E36D70dc727cAD96240217aBC7A9D" - }, - "AUTH_METHOD_PKP_INFO": { - "publicKey": "04d92c9302266d6c9ac5b66feb1355fb910910d43664ef15e52925fd9dcd8228f224956633ab30be19b5293a9d3c1bc2e7a8d110d33757de32ed505911ecafdc38", - "ethAddress": "0xAdd686B8A662Ed22dDAF3966b95fF7eeC34B363f", - "authMethod": { - "authMethodId": "0x170d13600caea2933912f39a0334eca3d22e472be203f937c4bad0213d92ed71", - "authMethodType": 1 - } + "publicKey": "04b5caf00c9f5adc9b22ca460b88482bad44ed4fac8ee63014b727cf60efc568dbdfe498a94fbd9cd294d651529f9fe76e057e9736150eea038415b06f64a87939" } } } diff --git a/packages/constants/src/lib/constants/autogen_internal.ts b/packages/constants/src/lib/constants/autogen_internal.ts index 3014db787a..a1bdee2506 100644 --- a/packages/constants/src/lib/constants/autogen_internal.ts +++ b/packages/constants/src/lib/constants/autogen_internal.ts @@ -1,4 +1,4 @@ -// Last Modified: 2024-02-01 20:57:50 +// Last Modified: 2024-01-31 14:28:38 // This file is auto-generated by tools/scripts/gen-internal-dev.mjs export const INTERNAL_DEV = [ 'https://167.114.17.204:443', diff --git a/packages/constants/src/lib/constants/constants.ts b/packages/constants/src/lib/constants/constants.ts index 8cd3767300..6efee028a1 100644 --- a/packages/constants/src/lib/constants/constants.ts +++ b/packages/constants/src/lib/constants/constants.ts @@ -468,7 +468,7 @@ export const LIT_CHAINS: LITChain = { contractAddress: null, chainId: 175177, name: 'Chronicle - Lit Protocol Testnet', - symbol: 'testLIT', + symbol: 'testLPX', decimals: 18, rpcUrls: ['https://chain-rpc.litprotocol.com/http'], blockExplorerUrls: ['https://chain.litprotocol.com/'], diff --git a/packages/logger/src/lib/logger.spec.ts b/packages/logger/src/lib/logger.spec.ts index d756565e41..c11b6540d0 100644 --- a/packages/logger/src/lib/logger.spec.ts +++ b/packages/logger/src/lib/logger.spec.ts @@ -68,4 +68,36 @@ describe('logger', () => { console.log(lm.getLogsForId('foo3')); expect(lm.getLogsForId('foo3').length).toEqual(1); }); + + it('should trace logs through multiple categories', () => { + const logger = lm.get('info-logger', 'foo4'); + logger.setLevel(LogLevel.DEBUG); + const logger2 = lm.get('debug-logger', 'foo4'); + logger2.setLevel(LogLevel.DEBUG); + logger2.debug('foo'); + logger.debug('bar'); + expect(lm.getLogsForId('foo4').length).toEqual(2); + }); + + it('should not persist logs if level set to OFF', () => { + const count = 1_000; + for (let i = 0; i < count; i++) { + const logger = lm.get('' + i, 'foo4'); + logger.setLevel(LogLevel.OFF); + logger.debug(i + ''); + } + + expect(lm.getLogsForId('foo4').length).toEqual(0); + }); + + it('should persist logs across categories', async () => { + const count = 1_000; + for (let i = 0; i < count; i++) { + const logger = lm.get('' + i, 'foo4'); + logger.setLevel(LogLevel.DEBUG); + logger.debug(i + ''); + } + + expect(lm.getLogsForId('foo4').length).toEqual(count); + }); }); diff --git a/packages/logger/src/lib/logger.ts b/packages/logger/src/lib/logger.ts index 7b9ec19bf0..6f6164f75c 100644 --- a/packages/logger/src/lib/logger.ts +++ b/packages/logger/src/lib/logger.ts @@ -11,7 +11,7 @@ export enum LogLevel { FATAL = 4, TIMING_START = 5, TIMING_END = 6, - OFF = 5, + OFF = 7, } const colours = { @@ -206,20 +206,24 @@ export class Logger { private _logs: Log[] = []; private _logHashes: Map = new Map(); private _config: Record | undefined; + private _isParent: boolean; + private _children: Map; public static createLogger( category: string, level: LogLevel, id: string, + isParent: boolean, config?: Record ): Logger { - return new Logger(category, level, id, config); + return new Logger(category, level, id, isParent, config); } private constructor( category: string, level: LogLevel, id: string, + isParent: boolean, config?: Record ) { this._category = category; @@ -227,6 +231,8 @@ export class Logger { this._id = id; this._consoleHandler = _resolveLoggingHandler(this._level); this._config = config; + this._children = new Map(); + this._isParent = isParent; } get id(): string { @@ -249,6 +255,10 @@ export class Logger { return this._config; } + get Children(): Map { + return this._children; + } + public setLevel(level: LogLevel): void { this._level = level; } @@ -302,19 +312,19 @@ export class Logger { const arrayLog = log.toArray(); if (this._config?.['condenseLogs'] && !this._checkHash(log)) { - (this._level >= level || level === LogLevel.ERROR) && + (this._level <= level || level === LogLevel.ERROR) && this._consoleHandler(...arrayLog); - (this._level >= level || level === LogLevel.ERROR) && + (this._level <= level || level === LogLevel.ERROR) && this._handler && this._handler(log); - (this._level >= level || level === LogLevel.ERROR) && this._addLog(log); + (this._level <= level || level === LogLevel.ERROR) && this._addLog(log); } else if (!this._config?.['condenseLogs']) { - (this._level >= level || level === LogLevel.ERROR) && + (this._level <= level || level === LogLevel.ERROR) && this._consoleHandler(...arrayLog); - (this._level >= level || level === LogLevel.ERROR) && + (this._level <= level || level === LogLevel.ERROR) && this._handler && this._handler(log); - (this._level >= level || level === LogLevel.ERROR) && this._addLog(log); + (this._level <= level || level === LogLevel.ERROR) && this._addLog(log); } } @@ -332,23 +342,24 @@ export class Logger { private _addLog(log: Log) { this._logs.push(log); - this._addToLocalStorage(log); + log.id && this._addToLocalStorage(log); } private _addToLocalStorage(log: Log) { if (globalThis.localStorage) { - let bucket: any = globalThis.localStorage.getItem(log.id); + let bucket: { [index: string]: string[] } | string | null = + globalThis.localStorage.getItem(log.category); if (bucket) { - bucket = JSON.parse(bucket); - bucket?.logs.push(log.toString()); - globalThis.localStorage.setItem(log.id, _safeStringify(bucket)); + bucket = JSON.parse(bucket) as { [index: string]: string[] }; + if (!bucket[log.id]) { + bucket[log.id] = []; + } + bucket[log.id].push(log.toString()); + globalThis.localStorage.setItem(log.category, _safeStringify(bucket)); } else { - globalThis.localStorage.setItem( - log.id, - _safeStringify({ - logs: [log.toString()], - }) - ); + const bucket: { [index: string]: string[] } = {}; + bucket[log.id] = [log.toString()]; + globalThis.localStorage.setItem(log.category, _safeStringify(bucket)); } } } @@ -397,49 +408,95 @@ export class LogManager { // if a logger is given an id it will persist logs under its logger instance public get(category: string, id?: string): Logger { - let instance = this._loggers.get(`${category}${id}`); - if (instance !== undefined) { + let instance = this._loggers.get(category); + if (!instance && !id) { + this._loggers.set( + category, + Logger.createLogger(category, this._level ?? LogLevel.INFO, '', true) + ); + + instance = this._loggers.get(category) as Logger; + instance.Config = this._config; return instance; } - const logger = Logger.createLogger( - category, - this._level ?? LogLevel.INFO, - id ?? '' - ); + if (id) { + if (!instance) { + this._loggers.set( + category, + Logger.createLogger(category, this._level ?? LogLevel.INFO, '', true) + ); - logger.Config = this._config as Record; + instance = this._loggers.get(category) as Logger; + instance.Config = this._config; + } + let children = instance?.Children; + let child = children?.get(id); + if (child) { + return child; + } + children?.set( + id, + Logger.createLogger( + category, + this._level ?? LogLevel.INFO, + id ?? '', + true + ) + ); + + child = children?.get(id) as Logger; + child.Config = this._config; + return children?.get(id) as Logger; + // fall through condition for if there is no id for the logger and the category is not yet created. + // ex: LogManager.Instance.get('foo'); + } else if (!instance) { + this._loggers.set( + category, + Logger.createLogger(category, this._level ?? LogLevel.INFO, '', true) + ); + + instance = this._loggers.get(category) as Logger; + instance.Config = this._config; + } - this._loggers.set(`${category}${id}`, logger); - return logger; + return instance as Logger; } - getById(id: string): Logger | undefined { - for (const logger of this._loggers) { - if (logger[1].id == id) { - return logger[1]; + getById(id: string): string[] { + let logStrs: string[] = []; + for (const category of this._loggers.entries()) { + let logger = category[1].Children.get(id); + if (logger) { + let logStr = []; + for (const log of logger.Logs) { + logStr.push(log.toString()); + } + logStrs = logStrs.concat(logStr); } } - return undefined; + return logStrs; } public getLogsForId(id: string): string[] { - if (globalThis.localStorage) { - let bucket: string | null = globalThis.localStorage.getItem(id); - if (bucket !== null) { - let data = JSON.parse(bucket as string); - return data.logs as string[]; - } - } else { - let logs = this.getById(id)?.Logs; - let logsStrs = []; - for (const log of logs as Log[]) { - logsStrs.push(log.toString()); + let logsForRequest: string[] = this.getById(id); + if (logsForRequest.length < 1 && globalThis.localStorage) { + for (const category of this._loggers.keys()) { + let bucketStr: string | null = + globalThis.localStorage.getItem(category); + let bucket: { [key: string]: string[] } = JSON.parse( + bucketStr as string + ); + if (bucket && bucket[id]) { + const logsForId: string[] = bucket[id].filter((log: string) => + log.includes(id) + ); + logsForRequest = logsForId.concat(logsForRequest); + } } - return logsStrs; } - return []; + return logsForRequest; } } diff --git a/packages/types/src/lib/interfaces.ts b/packages/types/src/lib/interfaces.ts index a928e43074..2da521b71b 100644 --- a/packages/types/src/lib/interfaces.ts +++ b/packages/types/src/lib/interfaces.ts @@ -1063,7 +1063,7 @@ export interface GetSessionSigsProps { sessionKey?: any; // rateLimitAuthSig: AuthSig; - + // Used for delegation of Capacity Credit. This signature will be checked for proof of capacity credit. // on both manzano and habanero networks capacity credit proof is required. // see more here: https://developer.litprotocol.com/v3/sdk/capacity-credits