@keetanetwork/anchor 0.0.1

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.
Files changed (76) hide show
  1. package/.done +0 -0
  2. package/LICENSE +35 -0
  3. package/client/index.d.ts +10 -0
  4. package/client/index.d.ts.map +1 -0
  5. package/client/index.js +11 -0
  6. package/client/index.js.map +1 -0
  7. package/config.d.ts +10 -0
  8. package/config.d.ts.map +1 -0
  9. package/config.js +36 -0
  10. package/config.js.map +1 -0
  11. package/lib/certificates.d.ts +106 -0
  12. package/lib/certificates.d.ts.map +1 -0
  13. package/lib/certificates.js +463 -0
  14. package/lib/certificates.js.map +1 -0
  15. package/lib/encrypted-container.d.ts +106 -0
  16. package/lib/encrypted-container.d.ts.map +1 -0
  17. package/lib/encrypted-container.js +594 -0
  18. package/lib/encrypted-container.js.map +1 -0
  19. package/lib/index.d.ts +5 -0
  20. package/lib/index.d.ts.map +1 -0
  21. package/lib/index.js +5 -0
  22. package/lib/index.js.map +1 -0
  23. package/lib/log/common.d.ts +35 -0
  24. package/lib/log/common.d.ts.map +1 -0
  25. package/lib/log/common.js +19 -0
  26. package/lib/log/common.js.map +1 -0
  27. package/lib/log/index.d.ts +59 -0
  28. package/lib/log/index.d.ts.map +1 -0
  29. package/lib/log/index.js +207 -0
  30. package/lib/log/index.js.map +1 -0
  31. package/lib/log/target_console.d.ts +13 -0
  32. package/lib/log/target_console.d.ts.map +1 -0
  33. package/lib/log/target_console.js +44 -0
  34. package/lib/log/target_console.js.map +1 -0
  35. package/lib/resolver.d.ts +308 -0
  36. package/lib/resolver.d.ts.map +1 -0
  37. package/lib/resolver.js +1429 -0
  38. package/lib/resolver.js.map +1 -0
  39. package/lib/utils/array.d.ts +10 -0
  40. package/lib/utils/array.d.ts.map +1 -0
  41. package/lib/utils/array.js +12 -0
  42. package/lib/utils/array.js.map +1 -0
  43. package/lib/utils/asn1.d.ts +13 -0
  44. package/lib/utils/asn1.d.ts.map +1 -0
  45. package/lib/utils/asn1.js +8 -0
  46. package/lib/utils/asn1.js.map +1 -0
  47. package/lib/utils/buffer.d.ts +4 -0
  48. package/lib/utils/buffer.d.ts.map +1 -0
  49. package/lib/utils/buffer.js +3 -0
  50. package/lib/utils/buffer.js.map +1 -0
  51. package/lib/utils/crypto.d.ts +4 -0
  52. package/lib/utils/crypto.d.ts.map +1 -0
  53. package/lib/utils/crypto.js +4 -0
  54. package/lib/utils/crypto.js.map +1 -0
  55. package/lib/utils/index.d.ts +5 -0
  56. package/lib/utils/index.d.ts.map +1 -0
  57. package/lib/utils/index.js +5 -0
  58. package/lib/utils/index.js.map +1 -0
  59. package/lib/utils/json.d.ts +8 -0
  60. package/lib/utils/json.d.ts.map +1 -0
  61. package/lib/utils/json.js +164 -0
  62. package/lib/utils/json.js.map +1 -0
  63. package/lib/utils/never.d.ts +8 -0
  64. package/lib/utils/never.d.ts.map +1 -0
  65. package/lib/utils/never.js +14 -0
  66. package/lib/utils/never.js.map +1 -0
  67. package/npm-shrinkwrap.json +16517 -0
  68. package/package.json +42 -0
  69. package/services/kyc/client.d.ts +139 -0
  70. package/services/kyc/client.d.ts.map +1 -0
  71. package/services/kyc/client.js +390 -0
  72. package/services/kyc/client.js.map +1 -0
  73. package/services/kyc/common.d.ts +65 -0
  74. package/services/kyc/common.d.ts.map +1 -0
  75. package/services/kyc/common.js +2 -0
  76. package/services/kyc/common.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encrypted-container.js","sourceRoot":"","sources":["../../src/lib/encrypted-container.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAKnE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,MAAM,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,MAAM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,EAAE,EAAE,CAAC;YAC1B,MAAK,CAAC,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC,CAAC;QACpE,CAAC;QAED,OAAM,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;;AAGF,gBAAgB;AAChB,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB,SAAS,EAAE,SAAS;IACpB,SAAS,EAAE,SAAS;CACpB,CAAC;AAEF,eAAe,kBAAkB,CAAC","sourcesContent":["import crypto from './utils/crypto.js';\nimport { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';\n\nimport type {\n\tASN1OID\n} from '@keetanetwork/keetanet-client/lib/utils/asn1.js';\nimport { Buffer } from './utils/buffer.js';\nimport { isArray } from './utils/array.js';\n\nconst zlibDeflate = KeetaNetLib.Utils.Buffer.ZlibDeflate; /* XXX:TODO: Change this to ZlibDeflateAsync when merged in */\nconst zlibInflate = KeetaNetLib.Utils.Buffer.ZlibInflate; /* XXX:TODO: Change this to ZlibInflateAsync when merged in */\nconst ASN1toJS = KeetaNetLib.Utils.ASN1.ASN1toJS;\nconst JStoASN1 = KeetaNetLib.Utils.ASN1.JStoASN1;\nconst Account: typeof KeetaNetLib.Account = KeetaNetLib.Account;\ntype Account = InstanceType<typeof KeetaNetLib.Account>;\nconst bufferToArrayBuffer = KeetaNetLib.Utils.Helper.bufferToArrayBuffer;\n\n/*\n * ASN.1 Schema\n *\n * EncryptedContainer DEFINITIONS ::=\n * BEGIN\n * Version ::= INTEGER { v2(1) }\n *\n * KeyStore ::= SEQUENCE {\n * publicKey OCTET STRING,\n * encryptedSymmetricKey OCTET STRING,\n * ...\n * }\n *\n * EncryptedContainerBox ::= SEQUENCE {\n * keys SEQUENCE OF KeyStore,\n * encryptionAlgorithm OBJECT IDENTIFIER,\n * initializationVector OCTET STRING,\n * encryptedValue OCTET STRING,\n * ...\n * }\n *\n * PlaintextContainerBox ::= SEQUENCE {\n * plainValue OCTET STRING,\n * ...\n * }\n *\n * ContainerPackage ::= SEQUENCE {\n * version Version (v2),\n * encryptedContainer [0] EXPLICIT EncryptedContainerBox OPTIONAL,\n * plaintextContainer [1] EXPLICIT PlaintextContainerBox OPTIONAL,\n * ...\n * } (WITH COMPONENTS {\n * encryptedContainer PRESENT,\n * plaintextContainer ABSENT\n * } |\n * WITH COMPONENTS {\n * encryptedContainer ABSENT,\n * plaintextContainer PRESENT\n * })\n * END\n *\n */\n\ntype EncryptedContainerKeyStore = [\n\t/* publicKey */\n\tBuffer,\n\n\t/* encryptedSymmetricKey */\n\tBuffer\n];\n\ntype EncryptedContainerBoxEncrypted = [\n\t/* keys */\n\tEncryptedContainerKeyStore[],\n\n\t/* encryptionAlgorithm */\n\tASN1OID,\n\n\t/* initializationVector */\n\tBuffer,\n\n\t/* value */\n\tBuffer\n];\n\ntype EncryptedContainerBoxPlaintext = [\n\t/* value */\n\tBuffer\n];\n\ntype ContainerPackage = [\n\t/* version */\n\tnumber,\n\n\t{\n\t\ttype: 'context'\n\t\tvalue: 0,\n\t\tkind: 'explicit',\n\t\tcontains: EncryptedContainerBoxEncrypted\n\t} | {\n\t\ttype: 'context',\n\t\tvalue: 1,\n\t\tkind: 'explicit',\n\t\tcontains: EncryptedContainerBoxPlaintext\n\t}\n];\n\ntype CipherOptions = {\n\t/**\n\t * The symmetric cipher key (if any)\n\t */\n\tcipherKey: Buffer | undefined;\n\t/**\n\t * The symmetric cipher IV (if any)\n\t */\n\tcipherIV: Buffer | undefined;\n\t/**\n\t * The symmetric cipher algorithm\n\t */\n\tcipherAlgo: string;\n}\n\ntype ASN1Options = Required<CipherOptions> & {\n\t/**\n\t * The set of accounts to encrypt the formatted data\n\t */\n\tkeys: Account[];\n}\n\nconst oidDB = {\n\t'aes-256-cbc': '2.16.840.1.101.3.4.1.42'\n} as const;\n\n/**\n* Compiles the ASN.1 for the container\n*\n* @returns The ASN.1 DER data\n*/\nasync function buildASN1(plaintext: Buffer, encryptionOptions?: ASN1Options): Promise<Buffer> {\n\tconst compressedPlaintext = Buffer.from(zlibDeflate(plaintext));\n\n\tconst sequence: Partial<ContainerPackage> = [];\n\n\t/*\n\t * Version v2 (1)\n\t */\n\tsequence[0] = 1;\n\n\t/*\n\t * Encrypted container box\n\t */\n\tif (encryptionOptions) {\n\t\tconst { keys, cipherKey, cipherIV, cipherAlgo } = encryptionOptions;\n\n\t\tif (keys === undefined || keys.length === 0 || cipherKey === undefined || cipherIV === undefined || cipherAlgo === undefined) {\n\t\t\tthrow(new Error('internal error: Unsupported method invocation'));\n\t\t}\n\n\t\tif (!(cipherAlgo in oidDB)) {\n\t\t\tthrow(new Error(`Unsupported algorithm: ${cipherAlgo}`));\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst algorithmOID = oidDB[cipherAlgo as keyof typeof oidDB];\n\n\t\tconst cipher = crypto.createCipheriv(\n\t\t\tcipherAlgo,\n\t\t\tcipherKey,\n\t\t\tcipherIV\n\t\t);\n\n\t\tconst encryptedData = Buffer.concat([\n\t\t\tcipher.update(compressedPlaintext),\n\t\t\tcipher.final()\n\t\t]);\n\n\t\tconst cipherKeyArrayBuffer = bufferToArrayBuffer(cipherKey);\n\n\t\tconst encryptionKeysSequence = await Promise.all(keys.map(async function(key) {\n\t\t\tconst encryptedSymmetricKey = Buffer.from(await key.encrypt(cipherKeyArrayBuffer));\n\t\t\tconst retval: EncryptedContainerKeyStore = [\n\t\t\t\tkey.publicKeyAndType,\n\t\t\t\tencryptedSymmetricKey\n\t\t\t];\n\n\t\t\treturn(retval);\n\t\t}));\n\n\t\tsequence[1] = {\n\t\t\ttype: 'context',\n\t\t\tvalue: 0,\n\t\t\tkind: 'explicit',\n\t\t\tcontains: [\n\t\t\t\tencryptionKeysSequence,\n\t\t\t\t{ type: 'oid', oid: algorithmOID },\n\t\t\t\tcipherIV,\n\t\t\t\tencryptedData\n\t\t\t]\n\t\t};\n\t} else {\n\t\t/*\n\t\t * Otherwise we simply pass in the compressed data\n\t\t */\n\t\tsequence[1] = {\n\t\t\ttype: 'context',\n\t\t\tvalue: 1,\n\t\t\tkind: 'explicit',\n\t\t\tcontains: [compressedPlaintext]\n\t\t};\n\t}\n\n\tconst outputASN1 = JStoASN1(sequence);\n\tconst outputDER = Buffer.from(outputASN1.toBER(false));\n\n\treturn(outputDER);\n}\n\nfunction parseASN1Bare(input: Buffer, acceptableEncryptionAlgorithms = ['aes-256-cbc', 'null']) {\n\tconst inputSequence = ASN1toJS(bufferToArrayBuffer(input));\n\tif (!isArray(inputSequence, 2)) {\n\t\tthrow(new Error('Malformed data detected (incorrect base format)'));\n\t}\n\n\tconst version = inputSequence[0];\n\tif (typeof version !== 'bigint') {\n\t\tthrow(new Error('Malformed data detected (version expected at position 0)'));\n\t}\n\n\tif (version !== 1n) {\n\t\tthrow(new Error('Malformed data detected (unsupported version)'));\n\t}\n\n\tconst valueBox = inputSequence[1];\n\tif (typeof valueBox !== 'object' || valueBox === null) {\n\t\tthrow(new Error('Malformed data detected (data expected at position 1)'));\n\t}\n\n\tif (!('type' in valueBox) || typeof valueBox.type !== 'string') {\n\t\tthrow(new Error('Malformed data detected (expected type at position 1)'));\n\t}\n\n\tif (valueBox.type !== 'context') {\n\t\tthrow(new Error('Malformed data detected (expected context at position 1)'));\n\t}\n\n\tif (!('value' in valueBox) || typeof valueBox.value !== 'number') {\n\t\tthrow(new Error('Malformed data detected (expected context value at position 1)'));\n\t}\n\n\tif (valueBox.value !== 0 && valueBox.value !== 1) {\n\t\tthrow(new Error('Malformed data detected (expected context value of 0 or 1)'));\n\t}\n\n\tif (!('contains' in valueBox) || typeof valueBox.contains !== 'object' || valueBox.contains === null) {\n\t\tthrow(new Error('Malformed data detected (expected contents at position 1)'));\n\t}\n\n\tlet isEncrypted;\n\tif (valueBox.value === 0) {\n\t\tisEncrypted = true;\n\t} else {\n\t\tisEncrypted = false;\n\t}\n\n\tconst value = valueBox.contains;\n\tlet containedCompressed: Buffer;\n\tlet cipherInfo;\n\tif (isEncrypted) {\n\t\tif (!isArray(value, 4)) {\n\t\t\tthrow(new Error('Malformed data (incorrect number of elements within position 1 -- expected 4)'));\n\t\t}\n\n\t\tconst keyInfoUnchecked = value[0];\n\t\tif (!isArray(keyInfoUnchecked)) {\n\t\t\tthrow(new Error('Malformed data (expected sequence at position 2.0)'));\n\t\t}\n\n\t\tconst keyInfo = keyInfoUnchecked.map(function(checkKeyInfo) {\n\t\t\tif (!isArray(checkKeyInfo, 2)) {\n\t\t\t\tthrow(new Error('Malformed key information (expected sequence of 2 at position 1.0.x)'));\n\t\t\t}\n\n\t\t\tconst publicKeyBuffer = checkKeyInfo[0];\n\t\t\tif (!Buffer.isBuffer(publicKeyBuffer)) {\n\t\t\t\tthrow(new Error('Malformed key information (expected octet string for public key at position 1.0.x)'));\n\t\t\t}\n\t\t\tconst publicKey = Account.fromPublicKeyAndType(publicKeyBuffer);\n\n\t\t\tconst encryptedSymmetricKey = checkKeyInfo[1];\n\t\t\tif (!Buffer.isBuffer(encryptedSymmetricKey)) {\n\t\t\t\tthrow(new Error('Malformed key information (expected octet string for cipher key at position 1.0.x)'));\n\t\t\t}\n\n\t\t\treturn({\n\t\t\t\tpublicKey,\n\t\t\t\tencryptedSymmetricKey\n\t\t\t});\n\t\t});\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\tconst encryptionAlgorithmOID = value[1];\n\t\t/* XXX:TODO: Lookup the encryption algorithm from the OID */\n\t\tconst encryptionAlgorithm = 'aes-256-cbc';\n\n\t\tconst cipherIV = value[2];\n\t\tif (!Buffer.isBuffer(cipherIV)) {\n\t\t\tthrow(new Error('Malformed data (cipher IV expected at position 1.2)'));\n\t\t}\n\n\t\tconst encryptedCompressedValue = value[3];\n\t\tif (!Buffer.isBuffer(encryptedCompressedValue)) {\n\t\t\tthrow(new Error('Malformed data (encrypted compressed buffer expected at position 1.3)'));\n\t\t}\n\n\t\tcipherInfo = {\n\t\t\tkeys: keyInfo,\n\t\t\tcipherIV: cipherIV,\n\t\t\tencryptedData: encryptedCompressedValue,\n\t\t\tencryptionAlgorithm: encryptionAlgorithm\n\t\t};\n\n\t\tcontainedCompressed = encryptedCompressedValue;\n\t} else {\n\t\tif (!isArray(value, 1)) {\n\t\t\tthrow(new Error('Malformed data (incorrect number of elements within position 1 -- expected 1)'));\n\t\t}\n\n\t\tconst containedCompressedUnchecked = value[0];\n\t\tif (!Buffer.isBuffer(containedCompressedUnchecked)) {\n\t\t\tthrow(new Error('Malformed data (compressed buffer expected at position 1.0)'));\n\t\t}\n\n\t\tif (!acceptableEncryptionAlgorithms.includes('null')) {\n\t\t\tthrow(new Error('Malformed data (plaintext found but the null encryption algorithm is not acceptable)'));\n\t\t}\n\n\t\tcontainedCompressed = containedCompressedUnchecked;\n\t}\n\n\treturn({\n\t\tversion: version,\n\t\tisEncrypted: isEncrypted,\n\t\tinnerValue: containedCompressed,\n\t\t...cipherInfo\n\t});\n}\n\nasync function parseASN1Decrypt(inputInfo: ReturnType<typeof parseASN1Bare>, keys?: Account[]) {\n\tlet containedCompressed: Buffer;\n\tlet cipherInfo;\n\tif (inputInfo.isEncrypted) {\n\t\tif (keys === undefined || keys.length === 0) {\n\t\t\tthrow(new Error('Encrypted Container found with encryption but no keys for decryption supplied'));\n\t\t}\n\n\t\tconst algorithm = inputInfo.encryptionAlgorithm;\n\t\tif (algorithm === undefined) {\n\t\t\tthrow(new Error('Encrypted Container found with encryption but no algorithm supplied'));\n\t\t}\n\n\t\tconst keyInfo = inputInfo.keys;\n\t\tif (keyInfo === undefined) {\n\t\t\tthrow(new Error('internal error: Encrypted container found with missing keys'));\n\t\t}\n\n\t\tlet decryptionKeyInfo;\n\t\tfor (const checkKeyInfo of keyInfo) {\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (!key.hasPrivateKey) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (key.comparePublicKey(checkKeyInfo.publicKey)) {\n\t\t\t\t\tdecryptionKeyInfo = {\n\t\t\t\t\t\t...checkKeyInfo,\n\t\t\t\t\t\tprivateKey: key\n\t\t\t\t\t};\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (decryptionKeyInfo === undefined) {\n\t\t\tthrow(new Error('No keys found which can perform decryption on the supplied encryption box'));\n\t\t}\n\n\t\tconst cipherKey = Buffer.from(await decryptionKeyInfo.privateKey.decrypt(bufferToArrayBuffer(decryptionKeyInfo.encryptedSymmetricKey)));\n\n\t\tconst cipherIV = inputInfo.cipherIV;\n\t\tif (cipherIV === undefined) {\n\t\t\tthrow(new Error('internal error: No Cipher IV found'));\n\t\t}\n\n\t\tconst encryptedCompressedValue = inputInfo.innerValue;\n\t\tconst decipher = crypto.createDecipheriv(algorithm, cipherKey, cipherIV);\n\t\tcontainedCompressed = Buffer.concat([\n\t\t\tdecipher.update(encryptedCompressedValue),\n\t\t\tdecipher.final()\n\t\t]);\n\n\t\tcipherInfo = {\n\t\t\tisEncrypted: true,\n\t\t\tkeys: keyInfo,\n\t\t\tcipherIV: cipherIV,\n\t\t\tcipherKey: cipherKey,\n\t\t\tencryptedData: encryptedCompressedValue\n\t\t};\n\t} else {\n\t\tcontainedCompressed = inputInfo.innerValue;\n\t\tcipherInfo = {\n\t\t\tisEncrypted: false\n\t\t};\n\t}\n\n\tconst plaintext = Buffer.from(zlibInflate(containedCompressed));\n\n\treturn({\n\t\tversion: inputInfo.version,\n\t\tplaintext: plaintext,\n\t\t...cipherInfo\n\t});\n\n}\n\nasync function parseASN1(input: Buffer, keys?: Account[]) {\n\tconst inputInfo = parseASN1Bare(input);\n\tconst retval = await parseASN1Decrypt(inputInfo, keys);\n\n\treturn(retval);\n}\n\n\n\ntype EncryptedContainerInfo = Pick<CipherOptions, 'cipherAlgo'> & {\n\t/**\n\t * Set of accounts which can access the data\n\t */\n\tprincipals: Account[];\n}\n\ntype UnencryptedContainerInfo = {\n\t/**\n\t * Unencrypted container should not have any principals\n\t */\n\tprincipals: null;\n}\n\nexport class EncryptedContainer {\n\tprivate static readonly algorithm = 'aes-256-cbc';\n\n\t/**\n\t * Flag indicating whether we support exporting the plaintext\n\t */\n\t#mayAccessPlaintext = true;\n\n\t/**\n\t * Encryption details\n\t */\n\tprotected _internalState: EncryptedContainerInfo | UnencryptedContainerInfo;\n\n\t/**\n\t * The plaintext or encoded (and possibly encrypted) data\n\t */\n\t#data:\n\t\t{ plaintext: Buffer } |\n\t\t{ encoded: Buffer } |\n\t\t{ plaintext: Buffer, encoded: Buffer };\n\n\tconstructor(principals: Account[] | null) {\n\t\tif (principals === null) {\n\t\t\tthis._internalState = {\n\t\t\t\tprincipals: null\n\t\t\t};\n\t\t} else {\n\t\t\tthis._internalState = {\n\t\t\t\tprincipals: principals,\n\t\t\t\tcipherAlgo: EncryptedContainer.algorithm\n\t\t\t}\n\t\t};\n\t\tthis.#data = { plaintext: Buffer.alloc(0) };\n\t}\n\n\tget encrypted(): boolean {\n\t\treturn(this._internalState.principals !== null);\n\t}\n\n\t#isEncrypted(): this is { _internalState: EncryptedContainerInfo } {\n\t\treturn(this.encrypted);\n\t}\n\n\t/**\n\t * Create an instance of the EncryptedContainer from an encrypted blob,\n\t * it will need to be decryptable with one of the specified principals\n\t *\n\t * After decryption happens, the list of principals with access to the\n\t * resource will be reset to what is contained within the encrypted\n\t * container\n\t */\n\tstatic fromEncryptedBuffer(data: Buffer, principals: Account[]): EncryptedContainer {\n\t\tconst retval = new EncryptedContainer(principals);\n\n\t\tretval.#setEncodedBuffer(data);\n\t\tretval.#computeAndSetKeyInfo(true);\n\n\t\treturn(retval);\n\t}\n\n\tstatic fromEncodedBuffer(data: Buffer, principals: Account[] | null): EncryptedContainer {\n\t\tconst retval = new EncryptedContainer(principals);\n\n\t\tretval.#setEncodedBuffer(data);\n\t\tretval.#computeAndSetKeyInfo(false);\n\n\t\treturn(retval);\n\t}\n\n\t/**\n\t * Create an instance of the EncryptedContainer from a plaintext.\n\t *\n\t * It will be decryptable by any one of the specified principals\n\t *\n\t * @param data The plaintext data to encrypt or encode\n\t * @param principals The list of principals who can access the data if it is null then the data is not encrypted\n\t * @param locked If true, the plaintext data will not be accessible from this instance; otherwise it will be -- default depends on principals\n\t * @returns The EncryptedContainer instance with the plaintext data and principals set\n\t */\n\tstatic fromPlaintext(data: string | Buffer, principals: Account[] | null, locked?: boolean): EncryptedContainer {\n\t\tconst retval = new EncryptedContainer(principals);\n\n\t\tif (locked === undefined) {\n\t\t\tlocked = true;\n\t\t\tif (principals === null) {\n\t\t\t\tlocked = false;\n\t\t\t}\n\t\t}\n\n\t\tif (locked) {\n\t\t\tretval.disablePlaintext();\n\t\t}\n\n\t\tretval.setPlaintext(data);\n\n\t\treturn(retval);\n\t}\n\n\t/**\n\t * Set the plaintext buffer to the specified value\n\t */\n\tsetPlaintext(data: string | Buffer): void {\n\t\tif (typeof data === 'string') {\n\t\t\tdata = Buffer.from(data, 'utf-8');\n\t\t}\n\n\t\tthis.#data = { plaintext: data };\n\t}\n\n\t/**\n\t * Set the encoded blob to the specified value\n\t */\n\t#setEncodedBuffer(data: Buffer): void {\n\t\tthis.#data = { encoded: data };\n\t}\n\n\tprivate get _encoded(): Buffer | undefined {\n\t\tif ('encoded' in this.#data && this.#data.encoded !== undefined) {\n\t\t\treturn(this.#data.encoded);\n\t\t}\n\n\t\treturn(undefined);\n\t}\n\n\tprivate get _plaintext(): Buffer | undefined {\n\t\tif ('plaintext' in this.#data && this.#data.plaintext !== undefined) {\n\t\t\treturn(this.#data.plaintext);\n\t\t}\n\n\t\treturn(undefined);\n\t}\n\n\t/*\n\t * Return the decoded data from the encoded blob\n\t * and populate the symmetric key parameters from the encoded blob if it is encrypted\n\t */\n\t#computeAndSetKeyInfo(mustBeEncrypted: boolean) {\n\t\tif (this._encoded === undefined) {\n\t\t\tthrow(new Error('No encoded data available'));\n\t\t}\n\n\t\tconst plaintextWrapper = parseASN1Bare(this._encoded);\n\n\t\tif (mustBeEncrypted && !plaintextWrapper.isEncrypted) {\n\t\t\tthrow(new Error('Unable to set key information from plaintext -- it is not encrypted but that was required'));\n\t\t}\n\n\t\tif (plaintextWrapper.isEncrypted) {\n\t\t\tconst principals = this._internalState.principals;\n\t\t\tif (principals === null) {\n\t\t\t\tthrow(new Error('May not encrypt data with a null set of principals'));\n\t\t\t}\n\n\t\t\t/*\n\t\t\t * Compute the new accounts by merging the input from the\n\t\t\t * data and the existing list of principals\n\t\t\t */\n\t\t\t/**\n\t\t\t * The existing principals from the blob, with existing\n\t\t\t * principals substituted in where appropriate\n\t\t\t */\n\t\t\tconst blobPrincipals = (plaintextWrapper.keys ?? []).map((keyInfo) => {\n\t\t\t\tconst currentPublicKey = keyInfo.publicKey;\n\t\t\t\tif (!currentPublicKey.isAccount()) {\n\t\t\t\t\tthrow(new Error('internal error: Non-account found within the encryption key list'));\n\t\t\t\t}\n\n\t\t\t\tfor (const checkExistingKey of principals) {\n\t\t\t\t\tif (checkExistingKey.comparePublicKey(currentPublicKey)) {\n\t\t\t\t\t\treturn(checkExistingKey);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn(currentPublicKey);\n\t\t\t});\n\n\t\t\tthis._internalState.principals = blobPrincipals;\n\n\t\t\t// Confirm updated principals are populated correctly which sets container to encrypted\n\t\t\tif (!this.encrypted) {\n\t\t\t\tthrow(new Error('internal error: Encrypted data found but not marked as encrypted'));\n\t\t\t}\n\t\t} else {\n\t\t\tthis._internalState.principals = null;\n\n\t\t\tif (this.encrypted) {\n\t\t\t\tthrow(new Error('internal error: Plaintext data found but marked as encrypted'));\n\t\t\t}\n\t\t}\n\n\t\treturn(plaintextWrapper);\n\t}\n\n\t/**\n\t * Populate the plaintext (as well as symmetric key parameters) from\n\t * the encoded blob\n\t */\n\tasync #computePlaintext() {\n\t\tif (this._plaintext) {\n\t\t\treturn(this._plaintext);\n\t\t}\n\n\t\tif (this._encoded === undefined) {\n\t\t\tthrow(new Error('No plaintext or encoded data available'));\n\t\t}\n\n\n\t\tconst info = this.#computeAndSetKeyInfo(this.encrypted);\n\n\t\tlet principals = this._internalState.principals;\n\t\tif (info.isEncrypted) {\n\t\t\tif (principals === null) {\n\t\t\t\tthrow(new Error('May not decrypt data with a null set of principals'));\n\t\t\t}\n\t\t} else {\n\t\t\tprincipals = [];\n\t\t}\n\n\t\tconst plaintextWrapper = await parseASN1Decrypt(info, principals);\n\t\tconst plaintext = plaintextWrapper.plaintext;\n\n\t\tthis.#data = { ...this.#data, plaintext };\n\n\t\treturn(plaintext);\n\t}\n\n\t/**\n\t * Compute the encoded version of the plaintext data\n\t */\n\tasync #computePlaintextEncoded() {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new Error('No plaintext data available'));\n\t\t}\n\n\t\tconst structuredData = await buildASN1(\n\t\t\tthis._plaintext\n\t\t);\n\n\t\treturn(structuredData);\n\t}\n\n\t/**\n\t * Populate the encrypted blob from the plaintext and symmetric key\n\t * parameters. If the symmetric key parameters have not been\n\t * initialized they will be initialized at this time.\n\t */\n\tasync #computeEncryptedEncoded() {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new Error('No encrypted nor plaintext data available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new Error('internal error: Asked to encrypt a plaintext buffer'));\n\t\t}\n\n\t\t/**\n\t\t * structured data is the ASN.1 encoded structure\n\t\t */\n\t\tconst structuredData = await buildASN1(\n\t\t\tthis._plaintext,\n\t\t\t{\n\t\t\t\tkeys: this._internalState.principals,\n\t\t\t\tcipherKey: crypto.randomBytes(32),\n\t\t\t\tcipherIV: crypto.randomBytes(16),\n\t\t\t\tcipherAlgo: this._internalState.cipherAlgo\n\t\t\t}\n\t\t);\n\n\t\treturn(structuredData);\n\t}\n\n\tasync #computeEncoded() {\n\t\tif (this._encoded !== undefined) {\n\t\t\treturn(this._encoded);\n\t\t}\n\n\t\tlet computed: Buffer;\n\t\tif (!this.encrypted) {\n\t\t\tcomputed = await this.#computePlaintextEncoded();\n\t\t} else {\n\t\t\tcomputed = await this.#computeEncryptedEncoded();\n\t\t}\n\n\t\tthis.#data = { ...this.#data, encoded: computed };\n\n\t\treturn(computed);\n\t}\n\n\t/**\n\t * Grant access to the secret for account(s) synchronously. This\n\t * assumes the plaintext has already been computed and will fail\n\t * if it is not\n\t */\n\tgrantAccessSync(accounts: Account[] | Account): void {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new Error('Unable to grant access, plaintext not available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new Error('May not manage access to a plaintext container'));\n\t\t}\n\n\t\tif (!Array.isArray(accounts)) {\n\t\t\taccounts = [accounts];\n\t\t}\n\n\t\t// Encoded data is invalidated with the new permissions so set only the plaintext data\n\t\tthis.setPlaintext(this._plaintext);\n\n\t\tthis._internalState.principals.push(...accounts);\n\t}\n\n\t/**\n\t * Grant access to the secret for account(s).\n\t */\n\tasync grantAccess(accounts: Account[] | Account): Promise<void> {\n\t\tawait this.#computePlaintext();\n\n\t\tthis.grantAccessSync(accounts);\n\t}\n\n\t/**\n\t * Revoke access to the secret for an account synchronously. This\n\t * assumes the plaintext has already been computed and will fail\n\t * if it is not\n\t */\n\trevokeAccessSync(account: Account): void {\n\t\tif (this._plaintext === undefined) {\n\t\t\tthrow(new Error('Unable to revoke access, plaintext not available'));\n\t\t}\n\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new Error('May not manage access to a plaintext container'));\n\t\t}\n\n\t\t// Encoded data is invalidated with the new permissions so set only the plaintext data\n\t\tthis.setPlaintext(this._plaintext);\n\n\t\tthis._internalState.principals = this._internalState.principals.filter(function(checkAccount) {\n\t\t\treturn(!checkAccount.comparePublicKey(account));\n\t\t});\n\t}\n\n\t/**\n\t * Revoke access to the secret for an account\n\t */\n\tasync revokeAccess(account: Account): Promise<void> {\n\t\tawait this.#computePlaintext();\n\n\t\tthis.revokeAccessSync(account);\n\t}\n\n\t/**\n\t * Disable access to the plaintext from this instance\n\t */\n\tdisablePlaintext(): void {\n\t\tthis.#mayAccessPlaintext = false;\n\t}\n\n\t/**\n\t * Get the plaintext for this instance\n\t */\n\tasync getPlaintext(): Promise<Buffer> {\n\t\tif (!this.#mayAccessPlaintext) {\n\t\t\tthrow(new Error('May not access plaintext'));\n\t\t}\n\n\t\tconst plaintext = await this.#computePlaintext();\n\n\t\tif (plaintext === undefined) {\n\t\t\tthrow(new Error('internal error: Plaintext could not be decoded'));\n\t\t}\n\n\t\t/*\n\t\t * Make a copy of our internal buffer so that any changes made\n\t\t * to either our internal buffer or by our caller do not\n\t\t * interfere\n\t\t */\n\t\treturn(Buffer.from(plaintext));\n\t}\n\n\t/**\n\t * Get the serializable buffer which can be stored and reconstructed\n\t */\n\tasync getEncodedBuffer(): Promise<Buffer> {\n\t\tconst serialized = await this.#computeEncoded();\n\n\t\tif (serialized === undefined) {\n\t\t\tthrow(new Error('internal error: Could not encode data'));\n\t\t}\n\n\t\t/*\n\t\t * Make a copy of our internal buffer so that any changes made\n\t\t * to either our internal buffer or by our caller do not\n\t\t * interfere\n\t\t */\n\t\treturn(Buffer.from(serialized));\n\t}\n\n\t/**\n\t * Get the list of accounts which have access to read the plaintext of\n\t * this container\n\t */\n\tget principals(): Account[] {\n\t\tif (!this.#isEncrypted()) {\n\t\t\tthrow(new Error('May not manage access to a plaintext container'));\n\t\t}\n\n\t\treturn(this._internalState.principals);\n\t}\n}\n\n/** @internal */\nexport const _Testing = {\n\tbuildASN1: buildASN1,\n\tparseASN1: parseASN1\n};\n\nexport default EncryptedContainer;\n"]}
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import * as Certificates from './certificates.js';
2
+ import { EncryptedContainer } from './encrypted-container.js';
3
+ import Resolver from './resolver.js';
4
+ export { Certificates, EncryptedContainer, Resolver };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EACN,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,CAAA"}
package/lib/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import * as Certificates from './certificates.js';
2
+ import { EncryptedContainer } from './encrypted-container.js';
3
+ import Resolver from './resolver.js';
4
+ export { Certificates, EncryptedContainer, Resolver };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EACN,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,CAAA","sourcesContent":["import * as Certificates from './certificates.js';\nimport { EncryptedContainer } from './encrypted-container.js';\n\nimport Resolver from './resolver.js';\nexport {\n\tCertificates,\n\tEncryptedContainer,\n\tResolver\n}\n"]}
@@ -0,0 +1,35 @@
1
+ export type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
2
+ export type LogTargetLevel = 'ALL' | LogLevel | 'NONE';
3
+ type LogCurrentRequest = {
4
+ id: string;
5
+ };
6
+ export type LogEntry = {
7
+ options: {
8
+ userVisible?: boolean;
9
+ currentRequestInfo?: LogCurrentRequest;
10
+ };
11
+ level: LogLevel;
12
+ from: string;
13
+ args: unknown[];
14
+ trace?: string;
15
+ };
16
+ export interface LogTarget {
17
+ readonly logLevel: LogTargetLevel;
18
+ emitLogs(logs: LogEntry[]): Promise<void>;
19
+ }
20
+ export interface Logger {
21
+ log(options: LogEntry['options'], from: string, ...args: unknown[]): void;
22
+ log(from: string, ...args: unknown[]): void;
23
+ debug(options: LogEntry['options'], from: string, ...args: unknown[]): void;
24
+ debug(from: string, ...args: unknown[]): void;
25
+ info(options: LogEntry['options'], from: string, ...args: unknown[]): void;
26
+ info(from: string, ...args: unknown[]): void;
27
+ warn(options: LogEntry['options'], from: string, ...args: unknown[]): void;
28
+ warn(from: string, ...args: unknown[]): void;
29
+ error(options: LogEntry['options'], from: string, ...args: unknown[]): void;
30
+ error(from: string, ...args: unknown[]): void;
31
+ }
32
+ export declare function canLogForLevel(level: LogLevel, currentLevel: LogLevel): boolean;
33
+ export declare function canLogForTargetLevel(level: LogLevel, targetLevel: LogTargetLevel): boolean;
34
+ export {};
35
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/lib/log/common.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAC3D,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAUvD,KAAK,iBAAiB,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACtB,OAAO,EAAE;QACR,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,kBAAkB,CAAC,EAAE,iBAAiB,CAAC;KACvC,CAAC;IACF,KAAK,EAAE,QAAQ,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,MAAM;IACtB,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,SAAS,CAA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EAAE,cAAc,GAAG,OAAO,CAU1F"}
@@ -0,0 +1,19 @@
1
+ const numericLogLevels = {
2
+ DEBUG: 0,
3
+ INFO: 1,
4
+ WARN: 2,
5
+ ERROR: 3
6
+ };
7
+ export function canLogForLevel(level, currentLevel) {
8
+ return (numericLogLevels[level] >= numericLogLevels[currentLevel]);
9
+ }
10
+ export function canLogForTargetLevel(level, targetLevel) {
11
+ if (targetLevel === 'ALL') {
12
+ return (true);
13
+ }
14
+ if (targetLevel === 'NONE') {
15
+ return (false);
16
+ }
17
+ return (canLogForLevel(level, targetLevel));
18
+ }
19
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/lib/log/common.ts"],"names":[],"mappings":"AAGA,MAAM,gBAAgB,GAAG;IACxB,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACC,CAAC;AAoCX,MAAM,UAAU,cAAc,CAAC,KAAe,EAAE,YAAsB;IACrE,OAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAe,EAAE,WAA2B;IAChF,IAAI,WAAW,KAAK,KAAK,EAAE,CAAC;QAC3B,OAAM,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAED,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;QAC5B,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC;IAED,OAAM,CAAC,cAAc,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["export type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';\nexport type LogTargetLevel = 'ALL' | LogLevel | 'NONE';\n\nconst numericLogLevels = {\n\tDEBUG: 0,\n\tINFO: 1,\n\tWARN: 2,\n\tERROR: 3\n} as const;\n\n/* XXX:TODO -- Do something with this */\ntype LogCurrentRequest = {\n\tid: string;\n};\n\nexport type LogEntry = {\n\toptions: {\n\t\tuserVisible?: boolean;\n\t\tcurrentRequestInfo?: LogCurrentRequest;\n\t};\n\tlevel: LogLevel;\n\tfrom: string;\n\targs: unknown[];\n\ttrace?: string;\n};\n\nexport interface LogTarget {\n\treadonly logLevel: LogTargetLevel;\n\temitLogs(logs: LogEntry[]): Promise<void>;\n}\n\nexport interface Logger {\n\tlog(options: LogEntry['options'], from: string, ...args: unknown[]): void;\n\tlog(from: string, ...args: unknown[]): void;\n\tdebug(options: LogEntry['options'], from: string, ...args: unknown[]): void;\n\tdebug(from: string, ...args: unknown[]): void;\n\tinfo(options: LogEntry['options'], from: string, ...args: unknown[]): void;\n\tinfo(from: string, ...args: unknown[]): void;\n\twarn(options: LogEntry['options'], from: string, ...args: unknown[]): void;\n\twarn(from: string, ...args: unknown[]): void;\n\terror(options: LogEntry['options'], from: string, ...args: unknown[]): void;\n\terror(from: string, ...args: unknown[]): void;\n}\n\nexport function canLogForLevel(level: LogLevel, currentLevel: LogLevel): boolean {\n\treturn(numericLogLevels[level] >= numericLogLevels[currentLevel]);\n}\n\nexport function canLogForTargetLevel(level: LogLevel, targetLevel: LogTargetLevel): boolean {\n\tif (targetLevel === 'ALL') {\n\t\treturn(true);\n\t}\n\n\tif (targetLevel === 'NONE') {\n\t\treturn(false);\n\t}\n\n\treturn(canLogForLevel(level, targetLevel));\n}\n"]}
@@ -0,0 +1,59 @@
1
+ import type { LogTargetLevel, LogEntry, Logger, LogTarget } from './common.js';
2
+ export type { Logger };
3
+ /**
4
+ * Options for a Log instance
5
+ */
6
+ type LogOptions = {
7
+ /**
8
+ * Whether to generate debug tracing information for each log entry
9
+ */
10
+ logDebugTracing?: boolean;
11
+ };
12
+ type LogOptionsParam = LogEntry['options'];
13
+ type LogTargetID = symbol & {
14
+ _branded: 'LogTargetID';
15
+ };
16
+ export declare class Log implements Logger {
17
+ #private;
18
+ /**
19
+ * The default log level, used for new instances of the logger
20
+ */
21
+ static readonly defaultLevel: LogTargetLevel;
22
+ constructor(options?: LogOptions);
23
+ log(options: LogOptionsParam, from: string, ...args: unknown[]): void;
24
+ log(from: string, ...args: unknown[]): void;
25
+ info(options: LogOptionsParam, from: string, ...args: unknown[]): void;
26
+ info(from: string, ...args: unknown[]): void;
27
+ debug(options: LogOptionsParam, from: string, ...args: unknown[]): void;
28
+ debug(from: string, ...args: unknown[]): void;
29
+ warn(options: LogOptionsParam, from: string, ...args: unknown[]): void;
30
+ warn(from: string, ...args: unknown[]): void;
31
+ error(options: LogOptionsParam, from: string, ...args: unknown[]): void;
32
+ error(from: string, ...args: unknown[]): void;
33
+ /**
34
+ * Register a new logging target (sink) to send logs to
35
+ */
36
+ registerTarget(target: LogTarget): LogTargetID;
37
+ /**
38
+ * Unregister a logging target (sink) to stop sending logs to
39
+ */
40
+ unregisterTarget(id: LogTargetID): void;
41
+ /**
42
+ * Emit a set of logs to all registered targets
43
+ */
44
+ private emitLogs;
45
+ /**
46
+ * Start a timer to periodically sync logs to all targets
47
+ */
48
+ startAutoSync(rate?: number): void;
49
+ /**
50
+ * If a timer was started with `startAutoSync()`, stop it
51
+ */
52
+ stopAutoSync(): void;
53
+ /**
54
+ * Sync all currently enqueued logs to all targets
55
+ */
56
+ sync(): Promise<void>;
57
+ }
58
+ export default Log;
59
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/log/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEzF,YAAY,EAAE,MAAM,EAAE,CAAC;AAQvB;;GAEG;AACH,KAAK,UAAU,GAAG;IACjB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,KAAK,eAAe,GAAG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ACH,cAAc,CAAC,MAAM,EAAE,SAAS,GAAG,WAAW;IAS9C;;OAEG;IACH,gBAAgB,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI;IAIvC;;OAEG;YACW,QAAQ;IAMtB;;OAEG;IACH,aAAa,CAAC,IAAI,SAAM,GAAG,IAAI;IAc/B;;OAEG;IACH,YAAY,IAAI,IAAI;IASpB;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAmD3B;AAED,eAAe,GAAG,CAAC"}
@@ -0,0 +1,207 @@
1
+ import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
2
+ import { createAssert } from 'typia';
3
+ /**
4
+ * Maximum number of logs to enqueue when there are no targets assigned to a
5
+ * Log instance
6
+ */
7
+ const MAX_LOGS_TO_ENQUEUE_WITH_NO_TARGETS = 131072;
8
+ const assertLogOptionsParam = (() => { const _io0 = input => (undefined === input.userVisible || "boolean" === typeof input.userVisible) && (undefined === input.currentRequestInfo || "object" === typeof input.currentRequestInfo && null !== input.currentRequestInfo && _io1(input.currentRequestInfo)); const _io1 = input => "string" === typeof input.id; const _ao0 = (input, _path, _exceptionable = true) => (undefined === input.userVisible || "boolean" === typeof input.userVisible || __typia_transform__assertGuard._assertGuard(_exceptionable, {
9
+ method: "createAssert",
10
+ path: _path + ".userVisible",
11
+ expected: "(boolean | undefined)",
12
+ value: input.userVisible
13
+ }, _errorFactory)) && (undefined === input.currentRequestInfo || ("object" === typeof input.currentRequestInfo && null !== input.currentRequestInfo || __typia_transform__assertGuard._assertGuard(_exceptionable, {
14
+ method: "createAssert",
15
+ path: _path + ".currentRequestInfo",
16
+ expected: "(LogCurrentRequest | undefined)",
17
+ value: input.currentRequestInfo
18
+ }, _errorFactory)) && _ao1(input.currentRequestInfo, _path + ".currentRequestInfo", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
19
+ method: "createAssert",
20
+ path: _path + ".currentRequestInfo",
21
+ expected: "(LogCurrentRequest | undefined)",
22
+ value: input.currentRequestInfo
23
+ }, _errorFactory)); const _ao1 = (input, _path, _exceptionable = true) => "string" === typeof input.id || __typia_transform__assertGuard._assertGuard(_exceptionable, {
24
+ method: "createAssert",
25
+ path: _path + ".id",
26
+ expected: "string",
27
+ value: input.id
28
+ }, _errorFactory); const __is = input => "object" === typeof input && null !== input && false === Array.isArray(input) && _io0(input); let _errorFactory; return (input, errorFactory) => {
29
+ if (false === __is(input)) {
30
+ _errorFactory = errorFactory;
31
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input && false === Array.isArray(input) || __typia_transform__assertGuard._assertGuard(true, {
32
+ method: "createAssert",
33
+ path: _path + "",
34
+ expected: "__type",
35
+ value: input
36
+ }, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
37
+ method: "createAssert",
38
+ path: _path + "",
39
+ expected: "__type",
40
+ value: input
41
+ }, _errorFactory))(input, "$input", true);
42
+ }
43
+ return input;
44
+ }; })();
45
+ export class Log {
46
+ /**
47
+ * The default log level, used for new instances of the logger
48
+ */
49
+ static defaultLevel = 'DEBUG';
50
+ /**
51
+ * Queued logs to be sent
52
+ */
53
+ #logs = [];
54
+ /**
55
+ * Interval holding the current autoSync process
56
+ */
57
+ #autoSyncInterval = undefined;
58
+ /**
59
+ * Keep track of whether or not we are currently syncing
60
+ */
61
+ #isSyncing = false;
62
+ /**
63
+ * If `sync()` is called while we are syncing, we should sync again
64
+ * to ensure all logs are sent
65
+ */
66
+ #shouldSyncAgain = false;
67
+ #logDebugTracing = false;
68
+ #targets = new Map();
69
+ constructor(options) {
70
+ if (options?.logDebugTracing !== undefined) {
71
+ this.#logDebugTracing = options.logDebugTracing;
72
+ }
73
+ }
74
+ #log(level, options, from, ...args) {
75
+ const log = { options, level, from, args };
76
+ if (this.#logDebugTracing) {
77
+ log.trace = new Error().stack?.split('\n').slice(2).join('\n') ?? '[No stack trace available]';
78
+ }
79
+ this.#logs.push(log);
80
+ }
81
+ #extractArguments(args) {
82
+ const options = assertLogOptionsParam((args[0] instanceof Object ? args.shift() : {}));
83
+ const from = args.shift();
84
+ if (typeof from !== 'string') {
85
+ throw (new Error(`Expected string for 'from', got ${typeof from}`));
86
+ }
87
+ return ({ options, from });
88
+ }
89
+ log(...args) {
90
+ const { options, from } = this.#extractArguments(args);
91
+ this.#log('INFO', options, from, ...args);
92
+ }
93
+ info(...args) {
94
+ const { options, from } = this.#extractArguments(args);
95
+ this.#log('INFO', options, from, ...args);
96
+ }
97
+ debug(...args) {
98
+ const { options, from } = this.#extractArguments(args);
99
+ this.#log('DEBUG', options, from, ...args);
100
+ }
101
+ warn(...args) {
102
+ const { options, from } = this.#extractArguments(args);
103
+ this.#log('WARN', options, from, ...args);
104
+ }
105
+ error(...args) {
106
+ const { options, from } = this.#extractArguments(args);
107
+ this.#log('ERROR', options, from, ...args);
108
+ }
109
+ /**
110
+ * Register a new logging target (sink) to send logs to
111
+ */
112
+ registerTarget(target) {
113
+ const id = Symbol('LogTargetID');
114
+ this.#targets.set(id, target);
115
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
116
+ return id;
117
+ }
118
+ /**
119
+ * Unregister a logging target (sink) to stop sending logs to
120
+ */
121
+ unregisterTarget(id) {
122
+ this.#targets.delete(id);
123
+ }
124
+ /**
125
+ * Emit a set of logs to all registered targets
126
+ */
127
+ async emitLogs(logs, targets) {
128
+ await Promise.allSettled(targets.map(async function (target) {
129
+ await target.emitLogs(logs);
130
+ }));
131
+ }
132
+ /**
133
+ * Start a timer to periodically sync logs to all targets
134
+ */
135
+ startAutoSync(rate = 100) {
136
+ if (this.#autoSyncInterval) {
137
+ return;
138
+ }
139
+ this.#autoSyncInterval = setInterval(async () => {
140
+ try {
141
+ await this.sync();
142
+ }
143
+ catch {
144
+ /* Ignored */
145
+ }
146
+ }, rate);
147
+ }
148
+ /**
149
+ * If a timer was started with `startAutoSync()`, stop it
150
+ */
151
+ stopAutoSync() {
152
+ if (!this.#autoSyncInterval) {
153
+ return;
154
+ }
155
+ clearInterval(this.#autoSyncInterval);
156
+ this.#autoSyncInterval = undefined;
157
+ }
158
+ /**
159
+ * Sync all currently enqueued logs to all targets
160
+ */
161
+ async sync() {
162
+ /*
163
+ * If there are currently no targets, do not dequeue logs
164
+ * in case a target is added later; However, if there are
165
+ * too many logs, drop the oldest ones
166
+ */
167
+ if (this.#targets.size === 0) {
168
+ if (this.#logs.length > MAX_LOGS_TO_ENQUEUE_WITH_NO_TARGETS) {
169
+ this.#logs.splice(0, this.#logs.length - MAX_LOGS_TO_ENQUEUE_WITH_NO_TARGETS);
170
+ }
171
+ return;
172
+ }
173
+ /*
174
+ * If we are already syncing, set a flag to sync again after the current sync is done
175
+ */
176
+ if (this.#isSyncing) {
177
+ this.#shouldSyncAgain = true;
178
+ return;
179
+ }
180
+ this.#isSyncing = true;
181
+ /*
182
+ * Create a copy of the currently registered targets in case
183
+ * they are modified while a sync is on-going, we use the
184
+ * same targets until the sync is complete
185
+ *
186
+ * This ensures no messages are lost if all targets are removed
187
+ * while a sync is in progress -- they will continue to be sent
188
+ * to the registered targets at the time of the sync
189
+ */
190
+ const targets = Array.from(this.#targets.values());
191
+ do {
192
+ try {
193
+ while (this.#logs.length > 0) {
194
+ this.#shouldSyncAgain = false;
195
+ const logs = this.#logs.splice(0, 10);
196
+ await this.emitLogs(logs, targets);
197
+ }
198
+ }
199
+ catch {
200
+ /* Ignore errors */
201
+ }
202
+ } while (this.#shouldSyncAgain);
203
+ this.#isSyncing = false;
204
+ }
205
+ }
206
+ export default Log;
207
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/log/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAGrC;;;GAGG;AACH,MAAM,mCAAmC,GAAG,MAAM,CAAC;AAanD,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAAkC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;;WAIG;QACH,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAC9B,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,mCAAmC,EAAE,CAAC;gBAC7D,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,mCAAmC,CAAC,CAAC;YAC/E,CAAC;YAED,OAAO;QACR,CAAC;QAED;;WAEG;QACH,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAE7B,OAAO;QACR,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QAEvB;;;;;;;;WAQG;QACH,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;QAEnD,GAAG,CAAC;YACH,IAAI,CAAC;gBACJ,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC9B,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC;oBAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBAEtC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBACpC,CAAC;YACF,CAAC;YAAC,MAAM,CAAC;gBACR,mBAAmB;YACpB,CAAC;QACF,CAAC,QAAQ,IAAI,CAAC,gBAAgB,EAAE;QAEhC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IACzB,CAAC;;AAGF,eAAe,GAAG,CAAC","sourcesContent":["import type { LogLevel, LogTargetLevel, LogEntry, Logger, LogTarget } from './common.js';\nimport { createAssert } from 'typia';\nexport type { Logger };\n\n/**\n * Maximum number of logs to enqueue when there are no targets assigned to a\n * Log instance\n */\nconst MAX_LOGS_TO_ENQUEUE_WITH_NO_TARGETS = 131072;\n\n/**\n * Options for a Log instance\n */\ntype LogOptions = {\n\t/**\n\t * Whether to generate debug tracing information for each log entry\n\t */\n\tlogDebugTracing?: boolean;\n};\n\ntype LogOptionsParam = LogEntry['options'];\nconst assertLogOptionsParam = createAssert<LogOptionsParam>();\n\ntype LogTargetID = symbol & { _branded: 'LogTargetID' };\n\nexport class Log implements Logger {\n\t/**\n\t * The default log level, used for new instances of the logger\n\t */\n\tstatic readonly defaultLevel: LogTargetLevel = 'DEBUG';\n\n\t/**\n\t * Queued logs to be sent\n\t */\n\t#logs: LogEntry[] = [];\n\n\t/**\n\t * Interval holding the current autoSync process\n\t */\n\t#autoSyncInterval: NodeJS.Timeout | undefined = undefined;\n\n\t/**\n\t * Keep track of whether or not we are currently syncing\n\t */\n\t#isSyncing = false;\n\n\t/**\n\t * If `sync()` is called while we are syncing, we should sync again\n\t * to ensure all logs are sent\n\t */\n\t#shouldSyncAgain = false;\n\n\t#logDebugTracing = false;\n\t#targets = new Map<symbol, LogTarget>();\n\n\tconstructor(options?: LogOptions) {\n\t\tif (options?.logDebugTracing !== undefined) {\n\t\t\tthis.#logDebugTracing = options.logDebugTracing;\n\t\t}\n\t}\n\n\t#log(level: LogLevel, options: LogOptionsParam, from: string, ...args: unknown[]): void {\n\t\tconst log: LogEntry = { options, level, from, args };\n\t\tif (this.#logDebugTracing) {\n\t\t\tlog.trace = new Error().stack?.split('\\n').slice(2).join('\\n') ?? '[No stack trace available]';\n\t\t}\n\t\tthis.#logs.push(log);\n\t}\n\n\t#extractArguments(args: unknown[]): { options: LogOptionsParam, from: string } {\n\t\tconst options = assertLogOptionsParam((args[0] instanceof Object ? args.shift() : {}));\n\t\tconst from = args.shift();\n\t\tif (typeof from !== 'string') {\n\t\t\tthrow(new Error(`Expected string for 'from', got ${typeof from}`));\n\t\t}\n\n\t\treturn({ options, from });\n\t}\n\n\tlog(options: LogOptionsParam, from: string, ...args: unknown[]): void;\n\tlog(from: string, ...args: unknown[]): void;\n\tlog(...args: unknown[]) {\n\t\tconst { options, from } = this.#extractArguments(args);\n\n\t\tthis.#log('INFO', options, from, ...args);\n\t}\n\n\tinfo(options: LogOptionsParam, from: string, ...args: unknown[]): void;\n\tinfo(from: string, ...args: unknown[]): void;\n\tinfo(...args: unknown[]) {\n\t\tconst { options, from } = this.#extractArguments(args);\n\n\t\tthis.#log('INFO', options, from, ...args);\n\t}\n\n\tdebug(options: LogOptionsParam, from: string, ...args: unknown[]): void;\n\tdebug(from: string, ...args: unknown[]): void;\n\tdebug(...args: unknown[]) {\n\t\tconst { options, from } = this.#extractArguments(args);\n\n\t\tthis.#log('DEBUG', options, from, ...args);\n\t}\n\n\twarn(options: LogOptionsParam, from: string, ...args: unknown[]): void;\n\twarn(from: string, ...args: unknown[]): void;\n\twarn(...args: unknown[]) {\n\t\tconst { options, from } = this.#extractArguments(args);\n\n\t\tthis.#log('WARN', options, from, ...args);\n\t}\n\n\terror(options: LogOptionsParam, from: string, ...args: unknown[]): void;\n\terror(from: string, ...args: unknown[]): void;\n\terror(...args: unknown[]) {\n\t\tconst { options, from } = this.#extractArguments(args);\n\n\t\tthis.#log('ERROR', options, from, ...args);\n\t}\n\n\t/**\n\t * Register a new logging target (sink) to send logs to\n\t */\n\tregisterTarget(target: LogTarget): LogTargetID {\n\t\tconst id = Symbol('LogTargetID');\n\n\t\tthis.#targets.set(id, target);\n\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\treturn(id as unknown as LogTargetID);\n\t}\n\n\t/**\n\t * Unregister a logging target (sink) to stop sending logs to\n\t */\n\tunregisterTarget(id: LogTargetID): void {\n\t\tthis.#targets.delete(id);\n\t}\n\n\t/**\n\t * Emit a set of logs to all registered targets\n\t */\n\tprivate async emitLogs(logs: LogEntry[], targets: LogTarget[]) {\n\t\tawait Promise.allSettled(targets.map(async function(target) {\n\t\t\tawait target.emitLogs(logs);\n\t\t}));\n\t}\n\n\t/**\n\t * Start a timer to periodically sync logs to all targets\n\t */\n\tstartAutoSync(rate = 100): void {\n\t\tif (this.#autoSyncInterval) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#autoSyncInterval = setInterval(async () => {\n\t\t\ttry {\n\t\t\t\tawait this.sync();\n\t\t\t} catch {\n\t\t\t\t/* Ignored */\n\t\t\t}\n\t\t}, rate);\n\t}\n\n\t/**\n\t * If a timer was started with `startAutoSync()`, stop it\n\t */\n\tstopAutoSync(): void {\n\t\tif (!this.#autoSyncInterval) {\n\t\t\treturn;\n\t\t}\n\n\t\tclearInterval(this.#autoSyncInterval);\n\t\tthis.#autoSyncInterval = undefined;\n\t}\n\n\t/**\n\t * Sync all currently enqueued logs to all targets\n\t */\n\tasync sync(): Promise<void> {\n\t\t/*\n\t\t * If there are currently no targets, do not dequeue logs\n\t\t * in case a target is added later; However, if there are\n\t\t * too many logs, drop the oldest ones\n\t\t */\n\t\tif (this.#targets.size === 0) {\n\t\t\tif (this.#logs.length > MAX_LOGS_TO_ENQUEUE_WITH_NO_TARGETS) {\n\t\t\t\tthis.#logs.splice(0, this.#logs.length - MAX_LOGS_TO_ENQUEUE_WITH_NO_TARGETS);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\t/*\n\t\t * If we are already syncing, set a flag to sync again after the current sync is done\n\t\t */\n\t\tif (this.#isSyncing) {\n\t\t\tthis.#shouldSyncAgain = true;\n\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#isSyncing = true;\n\n\t\t/*\n\t\t * Create a copy of the currently registered targets in case\n\t\t * they are modified while a sync is on-going, we use the\n\t\t * same targets until the sync is complete\n\t\t *\n\t\t * This ensures no messages are lost if all targets are removed\n\t\t * while a sync is in progress -- they will continue to be sent\n\t\t * to the registered targets at the time of the sync\n\t\t */\n\t\tconst targets = Array.from(this.#targets.values());\n\n\t\tdo {\n\t\t\ttry {\n\t\t\t\twhile (this.#logs.length > 0) {\n\t\t\t\t\tthis.#shouldSyncAgain = false;\n\t\t\t\t\tconst logs = this.#logs.splice(0, 10);\n\n\t\t\t\t\tawait this.emitLogs(logs, targets);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t/* Ignore errors */\n\t\t\t}\n\t\t} while (this.#shouldSyncAgain);\n\n\t\tthis.#isSyncing = false;\n\t}\n}\n\nexport default Log;\n"]}
@@ -0,0 +1,13 @@
1
+ import type { LogEntry, LogTargetLevel, LogTarget } from './common.js';
2
+ type LogTargetConsoleConfig = {
3
+ logLevel?: LogTargetLevel;
4
+ console?: Pick<typeof console, 'debug' | 'info' | 'warn' | 'error'>;
5
+ };
6
+ export declare class LogTargetConsole implements LogTarget {
7
+ #private;
8
+ readonly logLevel: LogTargetLevel;
9
+ constructor(config?: LogTargetConsoleConfig);
10
+ emitLogs(logs: LogEntry[]): Promise<void>;
11
+ }
12
+ export default LogTargetConsole;
13
+ //# sourceMappingURL=target_console.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"target_console.d.ts","sourceRoot":"","sources":["../../../src/lib/log/target_console.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIvE,KAAK,sBAAsB,GAAG;IAC7B,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CACpE,CAAC;AAEF,qBAAa,gBAAiB,YAAW,SAAS;;IACjD,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;gBAGtB,MAAM,CAAC,EAAE,sBAAsB;IAKrC,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAoC/C;AAED,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { canLogForTargetLevel } from './common.js';
2
+ import { assertNever } from '../utils/never.js';
3
+ export class LogTargetConsole {
4
+ logLevel;
5
+ #console;
6
+ constructor(config) {
7
+ this.logLevel = config?.logLevel ?? 'ALL';
8
+ this.#console = config?.console ?? console;
9
+ }
10
+ async emitLogs(logs) {
11
+ for (const log of logs) {
12
+ if (!canLogForTargetLevel(log.level, this.logLevel)) {
13
+ continue;
14
+ }
15
+ let method;
16
+ switch (log.level) {
17
+ case 'ERROR':
18
+ method = 'error';
19
+ break;
20
+ case 'WARN':
21
+ method = 'warn';
22
+ break;
23
+ case 'INFO':
24
+ method = 'info';
25
+ break;
26
+ case 'DEBUG':
27
+ method = 'debug';
28
+ break;
29
+ default:
30
+ assertNever(log.level);
31
+ }
32
+ let requestID = log.options?.currentRequestInfo?.id;
33
+ if (requestID === undefined) {
34
+ requestID = '<NO_REQUEST_ID>';
35
+ }
36
+ this.#console[method](`[${requestID}] ${log.level} ${log.from}:`, ...log.args);
37
+ if (log.trace !== undefined) {
38
+ this.#console[method](`[${requestID}] ${log.level} ${log.from} TRACE:`, log.trace);
39
+ }
40
+ }
41
+ }
42
+ }
43
+ export default LogTargetConsole;
44
+ //# sourceMappingURL=target_console.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"target_console.js","sourceRoot":"","sources":["../../../src/lib/log/target_console.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD,MAAM,OAAO,gBAAgB;IACnB,QAAQ,CAAiB;IAClC,QAAQ,CAAiD;IAEzD,YAAY,MAA+B;QAC1C,IAAI,CAAC,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,KAAK,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,MAAM,EAAE,OAAO,IAAI,OAAO,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAgB;QAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACrD,SAAS;YACV,CAAC;YAED,IAAI,MAA2C,CAAC;YAEhD,QAAQ,GAAG,CAAC,KAAK,EAAE,CAAC;gBACnB,KAAK,OAAO;oBACX,MAAM,GAAG,OAAO,CAAC;oBACjB,MAAM;gBACP,KAAK,MAAM;oBACV,MAAM,GAAG,MAAM,CAAC;oBAChB,MAAM;gBACP,KAAK,MAAM;oBACV,MAAM,GAAG,MAAM,CAAC;oBAChB,MAAM;gBACP,KAAK,OAAO;oBACX,MAAM,GAAG,OAAO,CAAC;oBACjB,MAAM;gBACP;oBACC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;YAED,IAAI,SAAS,GAAG,GAAG,CAAC,OAAO,EAAE,kBAAkB,EAAE,EAAE,CAAC;YACpD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC7B,SAAS,GAAG,iBAAiB,CAAC;YAC/B,CAAC;YAED,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,SAAS,KAAK,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;YAC/E,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC7B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,SAAS,KAAK,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,IAAI,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;YACpF,CAAC;QACF,CAAC;IACF,CAAC;CACD;AAED,eAAe,gBAAgB,CAAC","sourcesContent":["import type { LogEntry, LogTargetLevel, LogTarget } from './common.js';\nimport { canLogForTargetLevel } from './common.js';\nimport { assertNever } from '../utils/never.js';\n\ntype LogTargetConsoleConfig = {\n\tlogLevel?: LogTargetLevel;\n\tconsole?: Pick<typeof console, 'debug' | 'info' | 'warn' | 'error'>;\n};\n\nexport class LogTargetConsole implements LogTarget {\n\treadonly logLevel: LogTargetLevel;\n\t#console: NonNullable<LogTargetConsoleConfig['console']>;\n\n\tconstructor(config?: LogTargetConsoleConfig) {\n\t\tthis.logLevel = config?.logLevel ?? 'ALL';\n\t\tthis.#console = config?.console ?? console;\n\t}\n\n\tasync emitLogs(logs: LogEntry[]): Promise<void> {\n\t\tfor (const log of logs) {\n\t\t\tif (!canLogForTargetLevel(log.level, this.logLevel)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tlet method: 'debug' | 'info' | 'warn' | 'error';\n\n\t\t\tswitch (log.level) {\n\t\t\t\tcase 'ERROR':\n\t\t\t\t\tmethod = 'error';\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'WARN':\n\t\t\t\t\tmethod = 'warn';\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'INFO':\n\t\t\t\t\tmethod = 'info';\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'DEBUG':\n\t\t\t\t\tmethod = 'debug';\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(log.level);\n\t\t\t}\n\n\t\t\tlet requestID = log.options?.currentRequestInfo?.id;\n\t\t\tif (requestID === undefined) {\n\t\t\t\trequestID = '<NO_REQUEST_ID>';\n\t\t\t}\n\n\t\t\tthis.#console[method](`[${requestID}] ${log.level} ${log.from}:`, ...log.args);\n\t\t\tif (log.trace !== undefined) {\n\t\t\t\tthis.#console[method](`[${requestID}] ${log.level} ${log.from} TRACE:`, log.trace);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport default LogTargetConsole;\n"]}