@authup/server-kit 1.0.0-beta.35 → 1.0.0-beta.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -85,16 +85,16 @@ function decodePemToSpki(input) {
85
85
  * @see https://nodejs.org/api/webcrypto.html#cryptokeyusages
86
86
  */
87
87
  function getKeyUsagesForAsymmetricAlgorithm(name, format) {
88
- if (name === CryptoAsymmetricAlgorithm.RSA_PSS || name === CryptoAsymmetricAlgorithm.ECDSA || name === CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5) {
88
+ if (name === "RSA-PSS" || name === "ECDSA" || name === "RSASSA-PKCS1-v1_5") {
89
89
  if (format === "spki") return ["verify"];
90
90
  if (format === "pkcs8") return ["sign"];
91
91
  return ["sign", "verify"];
92
92
  }
93
- if (name === CryptoAsymmetricAlgorithm.ECDH) {
93
+ if (name === "ECDH") {
94
94
  if (format === "spki") return [];
95
95
  return ["deriveKey", "deriveBits"];
96
96
  }
97
- if (name === CryptoAsymmetricAlgorithm.RSA_OAEP) {
97
+ if (name === "RSA-OAEP") {
98
98
  if (format === "spki") return ["encrypt"];
99
99
  if (format === "pkcs8") return ["decrypt"];
100
100
  return ["encrypt", "decrypt"];
@@ -106,9 +106,9 @@ function getKeyUsagesForAsymmetricAlgorithm(name, format) {
106
106
  function normalizeAsymmetricKeyPairCreateOptions(options) {
107
107
  let optionsNormalized;
108
108
  switch (options.name) {
109
- case CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5:
110
- case CryptoAsymmetricAlgorithm.RSA_PSS:
111
- case CryptoAsymmetricAlgorithm.RSA_OAEP:
109
+ case "RSASSA-PKCS1-v1_5":
110
+ case "RSA-PSS":
111
+ case "RSA-OAEP":
112
112
  optionsNormalized = {
113
113
  modulusLength: 2048,
114
114
  publicExponent: new Uint8Array([
@@ -120,8 +120,8 @@ function normalizeAsymmetricKeyPairCreateOptions(options) {
120
120
  ...options
121
121
  };
122
122
  break;
123
- case CryptoAsymmetricAlgorithm.ECDSA:
124
- case CryptoAsymmetricAlgorithm.ECDH: optionsNormalized = {
123
+ case "ECDSA":
124
+ case "ECDH": optionsNormalized = {
125
125
  namedCurve: "P-256",
126
126
  ...options
127
127
  };
@@ -131,16 +131,16 @@ function normalizeAsymmetricKeyPairCreateOptions(options) {
131
131
  function normalizeAsymmetricKeyImportOptions(options) {
132
132
  let optionsNormalized;
133
133
  switch (options.name) {
134
- case CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5:
135
- case CryptoAsymmetricAlgorithm.RSA_PSS:
136
- case CryptoAsymmetricAlgorithm.RSA_OAEP:
134
+ case "RSASSA-PKCS1-v1_5":
135
+ case "RSA-PSS":
136
+ case "RSA-OAEP":
137
137
  optionsNormalized = {
138
138
  hash: "SHA-256",
139
139
  ...options
140
140
  };
141
141
  break;
142
- case CryptoAsymmetricAlgorithm.ECDSA:
143
- case CryptoAsymmetricAlgorithm.ECDH: optionsNormalized = {
142
+ case "ECDSA":
143
+ case "ECDH": optionsNormalized = {
144
144
  namedCurve: "P-256",
145
145
  ...options
146
146
  };
@@ -179,27 +179,27 @@ var AsymmetricKey = class AsymmetricKey extends BaseKey {
179
179
  }
180
180
  static buildImportOptionsForJWTAlgorithm(alg) {
181
181
  if (alg === JWTAlgorithm.RS256) return {
182
- name: CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5,
182
+ name: "RSASSA-PKCS1-v1_5",
183
183
  hash: "SHA-256"
184
184
  };
185
185
  if (alg === JWTAlgorithm.RS384) return {
186
- name: CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5,
186
+ name: "RSASSA-PKCS1-v1_5",
187
187
  hash: "SHA-384"
188
188
  };
189
189
  if (alg === JWTAlgorithm.RS512) return {
190
- name: CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5,
190
+ name: "RSASSA-PKCS1-v1_5",
191
191
  hash: "SHA-512"
192
192
  };
193
193
  if (alg === JWTAlgorithm.ES256) return {
194
- name: CryptoAsymmetricAlgorithm.ECDSA,
194
+ name: "ECDSA",
195
195
  namedCurve: "P-256"
196
196
  };
197
197
  if (alg === JWTAlgorithm.ES384) return {
198
- name: CryptoAsymmetricAlgorithm.ECDSA,
198
+ name: "ECDSA",
199
199
  namedCurve: "P-384"
200
200
  };
201
201
  if (alg === JWTAlgorithm.ES512) return {
202
- name: CryptoAsymmetricAlgorithm.ECDSA,
202
+ name: "ECDSA",
203
203
  namedCurve: "P-521"
204
204
  };
205
205
  throw new Error(`Signature algorithm ${alg} is not supported.`);
@@ -236,14 +236,14 @@ function getKeyUsagesForSymmetricAlgorithm(name) {
236
236
  /**
237
237
  * @see https://nodejs.org/api/webcrypto.html#cryptokeyusages
238
238
  */
239
- if (name === SymmetricAlgorithm.HMAC) return ["sign", "verify"];
240
- if (name === SymmetricAlgorithm.AES_CBC || name === SymmetricAlgorithm.AES_GCM || name === SymmetricAlgorithm.AES_CTR) return ["encrypt", "decrypt"];
239
+ if (name === "HMAC") return ["sign", "verify"];
240
+ if (name === "AES-CBC" || name === "AES-GCM" || name === "AES-CTR") return ["encrypt", "decrypt"];
241
241
  throw new SyntaxError(`Key usages can not be determined for symmetric algorithm: ${name}`);
242
242
  }
243
243
  //#endregion
244
244
  //#region src/crypto/key/symmetric/normalize.ts
245
245
  function normalizeSymmetricKeyCreateOptions(input) {
246
- if (input.name === SymmetricAlgorithm.HMAC) return {
246
+ if (input.name === "HMAC") return {
247
247
  hash: "SHA-256",
248
248
  ...input
249
249
  };
@@ -253,7 +253,7 @@ function normalizeSymmetricKeyCreateOptions(input) {
253
253
  };
254
254
  }
255
255
  function normalizeSymmetricKeyImportOptions(input) {
256
- if (input.name === SymmetricAlgorithm.HMAC) return {
256
+ if (input.name === "HMAC") return {
257
257
  hash: "SHA-256",
258
258
  ...input
259
259
  };
@@ -275,15 +275,15 @@ var SymmetricKey = class SymmetricKey extends BaseKey {
275
275
  }
276
276
  static buildImportOptionsForJWTAlgorithm(alg) {
277
277
  if (alg === JWTAlgorithm.HS256) return {
278
- name: SymmetricAlgorithm.HMAC,
278
+ name: "HMAC",
279
279
  hash: "SHA-256"
280
280
  };
281
281
  if (alg === JWTAlgorithm.HS384) return {
282
- name: SymmetricAlgorithm.HMAC,
282
+ name: "HMAC",
283
283
  hash: "SHA-384"
284
284
  };
285
285
  if (alg === JWTAlgorithm.HS512) return {
286
- name: SymmetricAlgorithm.HMAC,
286
+ name: "HMAC",
287
287
  hash: "SHA-512"
288
288
  };
289
289
  throw new Error(`Signature algorithm ${alg} is not supported.`);
@@ -699,7 +699,8 @@ var DomainEventRedisPublisher = class {
699
699
  var DomainEventSocketPublisher = class {
700
700
  driver;
701
701
  constructor(input) {
702
- this.driver = new Emitter(createRedisClient(input));
702
+ const client = createRedisClient(input);
703
+ this.driver = new Emitter(client);
703
704
  }
704
705
  async publish(ctx) {
705
706
  ctx.content = transformDomainEventData(ctx.content);
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["compareMethod","hashMethod","isObject","isObject","create","instance"],"sources":["../src/crypto/hash/compare.ts","../src/crypto/hash/hash.ts","../src/crypto/key/asymmetric/constants.ts","../src/crypto/key/base.ts","../src/crypto/key/asymmetric/helpers/wrap.ts","../src/crypto/key/asymmetric/key-usages.ts","../src/crypto/key/asymmetric/normalize.ts","../src/crypto/key/asymmetric/module.ts","../src/crypto/key/asymmetric/check.ts","../src/crypto/key/asymmetric/create.ts","../src/crypto/key/symmetric/constants.ts","../src/crypto/key/symmetric/check.ts","../src/crypto/key/symmetric/key-usages.ts","../src/crypto/key/symmetric/normalize.ts","../src/crypto/key/symmetric/module.ts","../src/crypto/key/symmetric/create.ts","../src/crypto/json-web-token/extract.ts","../src/crypto/json-web-token/utils.ts","../src/crypto/json-web-token/sign/module.ts","../src/crypto/json-web-token/verify/module.ts","../src/domain-event/module.ts","../src/services/cache/adapters/memory.ts","../src/services/redis/check.ts","../src/services/redis/factory.ts","../src/services/cache/adapters/redis.ts","../src/services/cache/helper.ts","../src/services/logger/module.ts","../src/services/logger/singleton.ts","../src/services/vault/singleton.ts","../src/domain-event/utils.ts","../src/domain-event/redis/module.ts","../src/domain-event/socket/module.ts","../src/utils/has-property.ts"],"sourcesContent":["/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { compare as compareMethod } from '@node-rs/bcrypt';\n\nexport async function compare(value: string, hashedValue: string) : Promise<boolean> {\n return compareMethod(value, hashedValue);\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hash as hashMethod } from '@node-rs/bcrypt';\n\nexport async function hash(str: string, rounds: number = 10) : Promise<string> {\n return hashMethod(str, rounds);\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum CryptoAsymmetricAlgorithm {\n RSA_PSS = 'RSA-PSS',\n RSASSA_PKCS1_V1_5 = 'RSASSA-PKCS1-v1_5',\n RSA_OAEP = 'RSA-OAEP',\n ECDSA = 'ECDSA',\n ECDH = 'ECDH',\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { arrayBufferToBase64 } from '@authup/kit';\nimport { subtle } from 'uncrypto';\n\nexport abstract class BaseKey {\n protected key : CryptoKey;\n\n // ----------------------------------------------\n\n constructor(cryptoKey : CryptoKey) {\n this.key = cryptoKey;\n }\n\n // ----------------------------------------------\n\n async toArrayBuffer(): Promise<ArrayBuffer> {\n if (this.key.type === 'private') {\n return subtle.exportKey('pkcs8', this.key);\n }\n\n if (this.key.type === 'public') {\n return subtle.exportKey('spki', this.key);\n }\n\n return subtle.exportKey('raw', this.key);\n }\n\n async toUint8Array(): Promise<Uint8Array> {\n const arrayBuffer = await this.toArrayBuffer();\n return new Uint8Array(arrayBuffer);\n }\n\n async toBase64() : Promise<string> {\n const arrayBuffer = await this.toArrayBuffer();\n return arrayBufferToBase64(arrayBuffer);\n }\n\n async toJWK() : Promise<JsonWebKey> {\n return subtle.exportKey('jwk', this.key);\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nfunction enc(\n type: 'PRIVATE KEY' | 'PUBLIC KEY',\n input: string,\n) {\n return `-----BEGIN ${type}-----\\n${input}\\n-----END ${type}-----`;\n}\n\nexport function encodePKCS8ToPEM(base64: string) {\n return enc('PRIVATE KEY', base64);\n}\n\nexport function encodeSPKIToPem(input: string) {\n return enc('PUBLIC KEY', input);\n}\n\n// ------------------------------------------------------------\n\nfunction dec(\n type: 'PRIVATE KEY' | 'PUBLIC KEY',\n input: string,\n) {\n input = input.replace(`-----BEGIN ${type}-----\\n`, '');\n\n input = input.replace(`\\n-----END ${type}-----\\n`, '');\n input = input.replace(`-----END ${type}-----\\n`, '');\n input = input.replace(`\\n-----END ${type}-----`, '');\n\n return input;\n}\n\nexport function decodePemToPKCS8(input: string) {\n return dec('PRIVATE KEY', input);\n}\n\nexport function decodePemToSpki(input: string) {\n return dec('PUBLIC KEY', input);\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { CryptoAsymmetricAlgorithm } from './constants';\n\n/**\n * @see https://nodejs.org/api/webcrypto.html#cryptokeyusages\n */\nexport function getKeyUsagesForAsymmetricAlgorithm(\n name: string,\n format?: Exclude<KeyFormat, 'jwk'>,\n) : KeyUsage[] {\n if (\n name === CryptoAsymmetricAlgorithm.RSA_PSS ||\n name === CryptoAsymmetricAlgorithm.ECDSA ||\n name === CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5\n ) {\n if (format === 'spki') {\n return ['verify'];\n } if (format === 'pkcs8') {\n return ['sign'];\n }\n\n return ['sign', 'verify'];\n }\n\n if (name === CryptoAsymmetricAlgorithm.ECDH) {\n if (format === 'spki') {\n return [];\n }\n\n return [\n 'deriveKey',\n 'deriveBits',\n ];\n }\n\n if (name === CryptoAsymmetricAlgorithm.RSA_OAEP) {\n if (format === 'spki') {\n return ['encrypt'];\n } if (format === 'pkcs8') {\n return ['decrypt'];\n }\n\n return ['encrypt', 'decrypt'];\n }\n\n throw new SyntaxError(`Key usages can not be determined for asymmetric algorithm: ${name}`);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { CryptoAsymmetricAlgorithm } from './constants';\nimport type {\n AsymmetricKeyImportOptionsInput,\n AsymmetricKeyPairCreateOptions,\n AsymmetricKeyPairCreateOptionsInput,\n AsymmetricKeyPairImportOptions,\n} from './types';\n\nexport function normalizeAsymmetricKeyPairCreateOptions(\n options: AsymmetricKeyPairCreateOptionsInput,\n) : AsymmetricKeyPairCreateOptions {\n let optionsNormalized : AsymmetricKeyPairCreateOptions;\n switch (options.name) {\n case CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5:\n case CryptoAsymmetricAlgorithm.RSA_PSS:\n case CryptoAsymmetricAlgorithm.RSA_OAEP: {\n optionsNormalized = {\n modulusLength: 2048,\n publicExponent: new Uint8Array([0x01, 0x00, 0x01]),\n hash: 'SHA-256',\n ...options,\n };\n break;\n }\n case CryptoAsymmetricAlgorithm.ECDSA:\n case CryptoAsymmetricAlgorithm.ECDH: {\n optionsNormalized = {\n namedCurve: 'P-256',\n ...options,\n };\n }\n }\n\n return optionsNormalized;\n}\n\nexport function normalizeAsymmetricKeyImportOptions(\n options: AsymmetricKeyImportOptionsInput,\n) : AsymmetricKeyPairImportOptions {\n let optionsNormalized : AsymmetricKeyPairImportOptions;\n switch (options.name) {\n case CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5:\n case CryptoAsymmetricAlgorithm.RSA_PSS:\n case CryptoAsymmetricAlgorithm.RSA_OAEP: {\n optionsNormalized = {\n hash: 'SHA-256',\n ...options,\n };\n break;\n }\n case CryptoAsymmetricAlgorithm.ECDSA:\n case CryptoAsymmetricAlgorithm.ECDH: {\n optionsNormalized = {\n namedCurve: 'P-256',\n ...options,\n };\n }\n }\n\n return optionsNormalized;\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { base64ToArrayBuffer } from '@authup/kit';\nimport { JWTAlgorithm } from '@authup/specs';\nimport { subtle } from 'uncrypto';\nimport { BaseKey } from '../base';\nimport { CryptoAsymmetricAlgorithm } from './constants';\nimport type { AsymmetricKeyImportContext } from './types';\nimport {\n decodePemToPKCS8, \n decodePemToSpki, \n encodePKCS8ToPEM, \n encodeSPKIToPem,\n} from './helpers';\nimport { getKeyUsagesForAsymmetricAlgorithm } from './key-usages';\nimport { normalizeAsymmetricKeyImportOptions } from './normalize';\n\nexport class AsymmetricKey extends BaseKey {\n async toPem(): Promise<string> {\n const base64 = await this.toBase64();\n\n if (this.key.type === 'public') {\n return encodeSPKIToPem(base64);\n }\n\n if (this.key.type === 'private') {\n return encodePKCS8ToPEM(base64);\n }\n\n throw new Error(`${this.key.type} can not be converted to pem.`);\n }\n\n // ----------------------------------------------------------------\n\n static async fromPem(ctx: AsymmetricKeyImportContext<string>): Promise<AsymmetricKey> {\n if (ctx.format === 'pkcs8') {\n return AsymmetricKey.fromBase64({\n ...ctx,\n key: decodePemToPKCS8(ctx.key), \n });\n }\n return AsymmetricKey.fromBase64({\n ...ctx,\n key: decodePemToSpki(ctx.key), \n });\n }\n\n static async fromBase64(\n ctx: AsymmetricKeyImportContext<string>,\n ) : Promise<AsymmetricKey> {\n const arrayBuffer = base64ToArrayBuffer(ctx.key);\n\n return AsymmetricKey.fromArrayBuffer({\n ...ctx,\n key: arrayBuffer,\n });\n }\n\n static async fromArrayBuffer(\n ctx: AsymmetricKeyImportContext<ArrayBuffer>,\n ) : Promise<AsymmetricKey> {\n const normalizedOptions = normalizeAsymmetricKeyImportOptions(ctx.options);\n\n const cryptoKey = await subtle.importKey(\n ctx.format,\n ctx.key,\n normalizedOptions,\n true,\n getKeyUsagesForAsymmetricAlgorithm(normalizedOptions.name, ctx.format),\n );\n\n return new AsymmetricKey(cryptoKey);\n }\n\n // ----------------------------------------------------------------\n\n static buildImportOptionsForJWTAlgorithm(alg: `${JWTAlgorithm}`) {\n if (alg === JWTAlgorithm.RS256) {\n return {\n name: CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5,\n hash: 'SHA-256',\n };\n }\n\n if (alg === JWTAlgorithm.RS384) {\n return {\n name: CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5,\n hash: 'SHA-384',\n };\n }\n\n if (alg === JWTAlgorithm.RS512) {\n return {\n name: CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5,\n hash: 'SHA-512',\n };\n }\n\n if (alg === JWTAlgorithm.ES256) {\n return {\n name: CryptoAsymmetricAlgorithm.ECDSA,\n namedCurve: 'P-256',\n };\n }\n\n if (alg === JWTAlgorithm.ES384) {\n return {\n name: CryptoAsymmetricAlgorithm.ECDSA,\n namedCurve: 'P-384',\n };\n }\n\n if (alg === JWTAlgorithm.ES512) {\n return {\n name: CryptoAsymmetricAlgorithm.ECDSA,\n namedCurve: 'P-521',\n };\n }\n\n throw new Error(`Signature algorithm ${alg} is not supported.`);\n }\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { CryptoAsymmetricAlgorithm } from './constants';\n\nexport function isAsymmetricAlgorithm(input: string) : input is CryptoAsymmetricAlgorithm {\n return (Object.values(CryptoAsymmetricAlgorithm) as string[]).includes(input);\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { subtle } from 'uncrypto';\nimport { getKeyUsagesForAsymmetricAlgorithm } from './key-usages';\nimport { normalizeAsymmetricKeyPairCreateOptions } from './normalize';\nimport type { AsymmetricKeyPairCreateOptionsInput } from './types';\n\nexport async function createAsymmetricKeyPair(options: AsymmetricKeyPairCreateOptionsInput) : Promise<CryptoKeyPair> {\n const optionsNormalized = normalizeAsymmetricKeyPairCreateOptions(options);\n return subtle.generateKey(\n optionsNormalized,\n true,\n getKeyUsagesForAsymmetricAlgorithm(optionsNormalized.name),\n );\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum SymmetricAlgorithm {\n HMAC = 'HMAC',\n AES_CTR = 'AES-CTR',\n AES_CBC = 'AES-CBC',\n AES_GCM = 'AES-GCM',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { SymmetricAlgorithm } from './constants';\n\nexport function isSymmetricAlgorithm(input: string) : input is SymmetricAlgorithm {\n return (Object.values(SymmetricAlgorithm) as string[]).includes(input);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { SymmetricAlgorithm } from './constants';\n\nexport function getKeyUsagesForSymmetricAlgorithm(name: string) : KeyUsage[] {\n /**\n * @see https://nodejs.org/api/webcrypto.html#cryptokeyusages\n */\n if (name === SymmetricAlgorithm.HMAC) {\n return [\n 'sign',\n 'verify',\n ];\n }\n\n if (\n name === SymmetricAlgorithm.AES_CBC ||\n name === SymmetricAlgorithm.AES_GCM ||\n name === SymmetricAlgorithm.AES_CTR\n ) {\n return [\n 'encrypt',\n 'decrypt',\n ];\n }\n\n throw new SyntaxError(`Key usages can not be determined for symmetric algorithm: ${name}`);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { SymmetricAlgorithm } from './constants';\nimport type {\n SymmetricKeyCreateOptions, \n SymmetricKeyCreateOptionsInput, \n SymmetricKeyImportOptions, \n SymmetricKeyImportOptionsInput,\n} from './types';\n\nexport function normalizeSymmetricKeyCreateOptions(\n input: SymmetricKeyCreateOptionsInput,\n) : SymmetricKeyCreateOptions {\n if (input.name === SymmetricAlgorithm.HMAC) {\n return {\n hash: 'SHA-256',\n ...input,\n };\n }\n\n return {\n length: 256,\n name: input.name,\n };\n}\n\nexport function normalizeSymmetricKeyImportOptions(\n input: SymmetricKeyImportOptionsInput,\n) : SymmetricKeyImportOptions {\n if (input.name === SymmetricAlgorithm.HMAC) {\n return {\n hash: 'SHA-256',\n ...input,\n };\n }\n\n return input;\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { base64ToArrayBuffer } from '@authup/kit';\nimport { JWTAlgorithm } from '@authup/specs';\nimport { subtle } from 'uncrypto';\nimport { BaseKey } from '../base';\nimport { SymmetricAlgorithm } from './constants';\nimport { getKeyUsagesForSymmetricAlgorithm } from './key-usages';\nimport { normalizeSymmetricKeyImportOptions } from './normalize';\nimport type { SymmetricKeyImportContext, SymmetricKeyImportOptions } from './types';\n\nexport class SymmetricKey extends BaseKey {\n static async fromBase64(\n ctx: SymmetricKeyImportContext<string>,\n ) : Promise<SymmetricKey> {\n const arrayBuffer = base64ToArrayBuffer(ctx.key);\n\n return SymmetricKey.fromArrayBuffer({\n ...ctx,\n key: arrayBuffer,\n });\n }\n\n static async fromArrayBuffer(\n ctx: SymmetricKeyImportContext<ArrayBuffer>,\n ) : Promise<SymmetricKey> {\n const normalizedOptions : SymmetricKeyImportOptions = normalizeSymmetricKeyImportOptions(ctx.options);\n\n const cryptoKey = await subtle.importKey(\n ctx.format,\n ctx.key,\n normalizedOptions,\n true,\n getKeyUsagesForSymmetricAlgorithm(normalizedOptions.name),\n );\n\n return new SymmetricKey(cryptoKey);\n }\n\n static buildImportOptionsForJWTAlgorithm(alg: `${JWTAlgorithm}`) {\n if (alg === JWTAlgorithm.HS256) {\n return {\n name: SymmetricAlgorithm.HMAC,\n hash: 'SHA-256',\n };\n }\n\n if (alg === JWTAlgorithm.HS384) {\n return {\n name: SymmetricAlgorithm.HMAC,\n hash: 'SHA-384',\n };\n }\n\n if (alg === JWTAlgorithm.HS512) {\n return {\n name: SymmetricAlgorithm.HMAC,\n hash: 'SHA-512',\n };\n }\n\n throw new Error(`Signature algorithm ${alg} is not supported.`);\n }\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { subtle } from 'uncrypto';\nimport { getKeyUsagesForSymmetricAlgorithm } from './key-usages';\nimport { normalizeSymmetricKeyCreateOptions } from './normalize';\nimport type { SymmetricKeyCreateOptionsInput } from './types';\n\nexport async function createSymmetricKey(input: SymmetricKeyCreateOptionsInput) : Promise<CryptoKey> {\n const optionsNormalized = normalizeSymmetricKeyCreateOptions(input);\n\n return subtle.generateKey(\n optionsNormalized,\n true,\n getKeyUsagesForSymmetricAlgorithm(optionsNormalized.name),\n );\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { JWTClaims, JWTHeader } from '@authup/specs';\nimport { JWTError } from '@authup/specs';\n\n/**\n * Decode a JWT token with no verification.\n *\n * @param token\n *\n * @throws JWTError\n */\nexport function extractTokenHeader(\n token: string,\n) : JWTHeader {\n const parts = token.split('.');\n if (parts.length !== 3) {\n throw JWTError.invalid();\n }\n\n const [headerBase64] = parts;\n\n try {\n const payload = atob(headerBase64);\n\n return JSON.parse(payload);\n\n /*\n return {\n typ: 'JWT',\n alg: transformInternalToJWTAlgorithm(header.algorithm),\n cty: header.contentType,\n jku: header.jsonKeyUrl,\n kid: header.keyId,\n x5u: header.x5Url,\n x5c: header.x5CertChain,\n x5t: header.x5CertThumbprint,\n 'x5t#S256': header.x5TS256CertThumbprint,\n };\n */\n } catch {\n throw JWTError.headerInvalid('The token header could not be extracted.');\n }\n}\n\n/**\n * @param token\n *\n * @throws JWTError\n */\nexport function extractTokenPayload(\n token: string,\n) : JWTClaims {\n const parts = token.split('.');\n if (parts.length !== 3) {\n throw JWTError.invalid();\n }\n\n const [, payloadBase64] = parts;\n\n try {\n const payload = atob(payloadBase64);\n\n return JSON.parse(payload);\n } catch {\n throw JWTError.payloadInvalid('The token payload could not be extracted.');\n }\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { JWTAlgorithm, JWTError } from '@authup/specs';\nimport { Algorithm } from '@node-rs/jsonwebtoken';\nimport { isObject } from 'smob';\n\nexport function createErrorForJWTError(e: unknown) : JWTError {\n if (isObject(e)) {\n if (typeof e.name === 'string') {\n switch (e.name) {\n case 'TokenExpiredError': {\n return JWTError.expired();\n }\n case 'NotBeforeError': {\n if (typeof e.date === 'string' || e.date instanceof Date) {\n return JWTError.notActiveBefore(e.date);\n }\n break;\n }\n case 'JsonWebTokenError': {\n if (typeof e.message === 'string') {\n return JWTError.payloadInvalid(e.message);\n }\n\n break;\n }\n }\n }\n\n // @see https://github.com/Keats/jsonwebtoken/blob/master/src/errors.rs\n switch (e.message) {\n case 'ExpiredSignature': {\n return JWTError.expired();\n }\n case 'ImmatureSignature': {\n return JWTError.notActiveBefore();\n }\n case 'InvalidToken':\n case 'InvalidSignature': {\n return JWTError.payloadInvalid();\n }\n }\n }\n\n return new JWTError({\n cause: e as Error,\n logMessage: true,\n message: 'The JWT error could not be determined.',\n });\n}\n\nexport function transformJWTAlgorithmToInternal(algorithm: `${JWTAlgorithm}`) : Algorithm {\n switch (algorithm) {\n case JWTAlgorithm.HS256: {\n return Algorithm.HS256;\n }\n case JWTAlgorithm.HS384: {\n return Algorithm.HS384;\n }\n case JWTAlgorithm.HS512: {\n return Algorithm.HS512;\n }\n case JWTAlgorithm.RS256: {\n return Algorithm.RS256;\n }\n case JWTAlgorithm.RS384: {\n return Algorithm.RS384;\n }\n case JWTAlgorithm.RS512: {\n return Algorithm.RS512;\n }\n case JWTAlgorithm.ES256: {\n return Algorithm.ES256;\n }\n case JWTAlgorithm.ES384: {\n return Algorithm.ES384;\n }\n case JWTAlgorithm.PS256: {\n return Algorithm.PS256;\n }\n case JWTAlgorithm.PS384: {\n return Algorithm.PS384;\n }\n case JWTAlgorithm.PS512: {\n return Algorithm.PS512;\n }\n }\n\n throw new Error(`The algorithm ${algorithm} is not supported.`);\n}\n\nexport function transformInternalToJWTAlgorithm(input: Algorithm) : JWTAlgorithm {\n switch (input) {\n case Algorithm.HS256:\n return JWTAlgorithm.HS256;\n case Algorithm.HS384:\n return JWTAlgorithm.HS384;\n case Algorithm.HS512:\n return JWTAlgorithm.HS512;\n case Algorithm.RS256:\n return JWTAlgorithm.RS256;\n case Algorithm.RS384:\n return JWTAlgorithm.RS384;\n case Algorithm.RS512:\n return JWTAlgorithm.RS512;\n case Algorithm.ES256:\n return JWTAlgorithm.ES256;\n case Algorithm.ES384:\n return JWTAlgorithm.ES384;\n case Algorithm.PS256:\n return JWTAlgorithm.PS256;\n case Algorithm.PS384:\n return JWTAlgorithm.PS384;\n case Algorithm.PS512:\n return JWTAlgorithm.PS512;\n }\n\n throw new SyntaxError(`The algorithm ${input} is not supported.`);\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { JWKType, JWTError } from '@authup/specs';\nimport type { JWTClaims } from '@authup/specs';\nimport { Algorithm, sign } from '@node-rs/jsonwebtoken';\nimport { AsymmetricKey, SymmetricKey, encodePKCS8ToPEM } from '../../key';\nimport { transformJWTAlgorithmToInternal } from '../utils';\nimport type { TokenSignOptions } from './types';\n\nconst getUtcTimestamp = () => Math.floor(new Date().getTime() / 1000);\n\nexport async function signToken(claims: JWTClaims, context: TokenSignOptions): Promise<string> {\n if (typeof claims.exp !== 'number') {\n claims.exp = getUtcTimestamp() + 3600;\n }\n if (typeof claims.iat !== 'number') {\n claims.iat = getUtcTimestamp();\n }\n\n switch (context.type) {\n case JWKType.RSA:\n case JWKType.EC: {\n let algorithm : Algorithm;\n\n let key : string;\n if (typeof context.key === 'string') {\n key = encodePKCS8ToPEM(context.key);\n } else {\n const keyContainer = new AsymmetricKey(context.key);\n key = await keyContainer.toPem();\n }\n\n if (context.type === JWKType.RSA) {\n algorithm = context.algorithm ?\n transformJWTAlgorithmToInternal(context.algorithm) :\n Algorithm.RS256;\n } else {\n algorithm = context.algorithm ?\n transformJWTAlgorithmToInternal(context.algorithm) :\n Algorithm.ES256;\n }\n\n return sign(claims, key, {\n algorithm,\n keyId: context.keyId,\n });\n }\n case JWKType.OCT: {\n const algorithm : Algorithm = context.algorithm ?\n transformJWTAlgorithmToInternal(context.algorithm) :\n Algorithm.HS256;\n\n let key : string | Uint8Array;\n if (typeof context.key === 'string') {\n key = context.key;\n } else {\n const keyContainer = new SymmetricKey(context.key);\n key = await keyContainer.toUint8Array();\n }\n\n return sign(claims, key, {\n algorithm,\n keyId: context.keyId,\n });\n }\n }\n\n throw new JWTError();\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { JWKType, JWTError } from '@authup/specs';\nimport type { JWTClaims, OAuth2TokenPayload } from '@authup/specs';\nimport { Algorithm, verify } from '@node-rs/jsonwebtoken';\nimport { AsymmetricKey, SymmetricKey, encodeSPKIToPem } from '../../key';\nimport { createErrorForJWTError, transformJWTAlgorithmToInternal } from '../utils';\nimport type { TokenVerifyOptions } from './types';\n\n/**\n * Verify JWT.\n *\n * @param token\n * @param context\n *\n * @throws OAuth2Error\n */\nexport async function verifyToken(\n token: string,\n context: TokenVerifyOptions,\n) : Promise<OAuth2TokenPayload> {\n let promise : Promise<JWTClaims> | undefined;\n\n let output : JWTClaims | undefined;\n\n try {\n switch (context.type) {\n case JWKType.RSA:\n case JWKType.EC: {\n let algorithms : Algorithm[];\n\n if (context.type === JWKType.RSA) {\n algorithms = context.algorithms ?\n context.algorithms.map((algorithm) => transformJWTAlgorithmToInternal(algorithm)) :\n [\n Algorithm.RS256,\n Algorithm.RS384,\n Algorithm.RS512,\n Algorithm.PS256,\n Algorithm.PS384,\n Algorithm.PS512,\n ];\n } else {\n algorithms = context.algorithms ?\n context.algorithms.map((algorithm) => transformJWTAlgorithmToInternal(algorithm)) :\n [\n Algorithm.ES256,\n Algorithm.ES384,\n ];\n }\n\n let key : string;\n if (typeof context.key === 'string') {\n key = encodeSPKIToPem(context.key);\n } else {\n const keyContainer = new AsymmetricKey(context.key);\n key = await keyContainer.toPem();\n }\n\n promise = verify(token, key, {\n algorithms,\n validateNbf: true,\n });\n break;\n }\n case JWKType.OCT: {\n const algorithms : Algorithm[] = context.algorithms ?\n context.algorithms.map((algorithm) => transformJWTAlgorithmToInternal(algorithm)) :\n [\n Algorithm.HS256,\n Algorithm.HS384,\n Algorithm.HS512,\n ];\n\n let key : string | Uint8Array;\n if (typeof context.key === 'string') {\n key = context.key;\n } else {\n const keyContainer = new SymmetricKey(context.key);\n key = await keyContainer.toUint8Array();\n }\n\n promise = verify(token, key, {\n algorithms,\n validateNbf: true,\n });\n }\n }\n\n if (promise) {\n output = await promise;\n }\n } catch (e) {\n throw createErrorForJWTError(e);\n }\n\n if (!output) {\n throw new JWTError();\n }\n\n return output as OAuth2TokenPayload;\n}\n","/*\n * Copyright (c) 2024-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { EventPayload } from '@authup/core-realtime-kit';\nimport type { DomainEventPublishContext, IDomainEventPublisher } from './type';\n\nexport class DomainEventPublisher implements IDomainEventPublisher {\n protected publishers : Set<IDomainEventPublisher>;\n\n constructor() {\n this.publishers = new Set<IDomainEventPublisher>();\n }\n\n mount(publisher: IDomainEventPublisher): void {\n this.publishers.add(publisher);\n }\n\n async publish<T extends EventPayload>(\n ctx: DomainEventPublishContext<T>,\n ) : Promise<void> {\n const publishers = this.publishers.values();\n while (true) {\n const it = publishers.next();\n if (it.done) {\n return;\n }\n\n await it.value.publish(ctx);\n }\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { TTLCacheOptions } from '@isaacs/ttlcache';\nimport { TTLCache } from '@isaacs/ttlcache';\nimport type { CacheClearOptions, CacheSetOptions, ICache } from '../types';\n\nexport class MemoryCache implements ICache {\n protected instance : TTLCache<string, unknown>;\n\n constructor(options: TTLCacheOptions<string, unknown> = {}) {\n this.instance = new TTLCache<string, unknown>({\n checkAgeOnGet: true,\n ttl: Infinity,\n ...(options || {}),\n });\n }\n\n async pop<T = unknown>(key: string): Promise<T | null> {\n if (this.instance.has(key)) {\n const output = this.instance.get(key);\n this.instance.delete(key);\n return output as T;\n }\n\n return null;\n }\n\n async has(key: string) : Promise<boolean> {\n return this.instance.has(key);\n }\n\n async get<T =unknown>(key: string): Promise<T | null> {\n const output = await this.instance.get(key);\n if (output) {\n return output as T;\n }\n\n return null;\n }\n\n async set(key: string, value: unknown, options: CacheSetOptions): Promise<void> {\n this.instance.set(key, value, { ttl: options.ttl });\n }\n\n async drop(key: string): Promise<void> {\n this.instance.delete(key);\n }\n\n async dropMany(keys: string[]) : Promise<void> {\n for (const key of keys) {\n this.instance.delete(key);\n }\n }\n\n async clear(options: CacheClearOptions = {}) : Promise<void> {\n if (options.prefix) {\n const keys = this.instance.keys();\n let iterator = keys.next();\n while (!iterator.done) {\n if (typeof iterator.value !== 'string') {\n continue;\n }\n\n if (iterator.value.startsWith(options.prefix)) {\n this.instance.delete(iterator.value);\n }\n\n iterator = keys.next();\n }\n\n return;\n }\n\n this.instance.clear();\n }\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isObject } from 'smob';\nimport type { RedisClient } from './module';\n\nexport function isRedisClient(data: unknown) : data is RedisClient {\n return isObject(data) &&\n typeof data.connect === 'function' &&\n typeof data.disconnect === 'function';\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createClient } from 'redis-extension';\nimport { isRedisClient } from './check';\nimport type { RedisClient, RedisClientOptions } from './module';\n\nexport type RedisClientCreateInput = string | boolean | RedisClient | RedisClientOptions;\n\nexport function createRedisClient(input: RedisClientCreateInput) {\n if (typeof input === 'boolean') {\n return createClient({ connectionString: 'redis://127.0.0.1' });\n }\n\n if (typeof input === 'string') {\n return createClient({ connectionString: input });\n }\n\n if (!isRedisClient(input)) {\n return createClient({ options: input });\n }\n\n return input;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { Client } from 'redis-extension';\nimport { JsonAdapter } from 'redis-extension';\nimport type { RedisClient, RedisClientOptions } from '../../redis';\nimport { createRedisClient } from '../../redis';\nimport type { CacheClearOptions, CacheSetOptions, ICache } from '../types';\n\nexport class RedisCache implements ICache {\n protected client : Client;\n\n protected jsonAdapter : JsonAdapter;\n\n constructor(input: string | boolean | RedisClient | RedisClientOptions) {\n this.client = createRedisClient(input);\n this.jsonAdapter = new JsonAdapter(this.client);\n }\n\n async get(key: string): Promise<any> {\n const output = await this.jsonAdapter.get(key);\n if (output) {\n return output;\n }\n\n return null;\n }\n\n async pop<T = unknown>(key: string): Promise<T | null> {\n const raw = await this.client.getdel(key);\n if (!raw) {\n return null;\n }\n\n try {\n return JSON.parse(raw) as T;\n } catch {\n return null;\n }\n }\n\n async has(key: string) : Promise<boolean> {\n const output = await this.get(key);\n\n return !!output;\n }\n\n async set(key: string, value: any, options: CacheSetOptions): Promise<void> {\n await this.jsonAdapter.set(key, value, { milliseconds: options.ttl });\n }\n\n async drop(key: string): Promise<void> {\n await this.jsonAdapter.drop(key);\n }\n\n async dropMany(keys: string[]) : Promise<void> {\n const pipeline = this.client.pipeline();\n\n for (const key of keys) {\n pipeline.del(key);\n }\n\n await pipeline.exec();\n }\n\n async clear(options: CacheClearOptions = {}) : Promise<void> {\n if (options.prefix) {\n const pipeline = this.client.pipeline();\n\n const keys = await this.client.keys(`${options.prefix}*`);\n for (const key of keys) {\n pipeline.del(key);\n }\n\n await pipeline.exec();\n\n return;\n }\n await this.client.flushdb();\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { buildRedisKeyPath } from '../redis';\nimport type { CacheKeyBuildOptions } from './types';\n\nexport function buildCacheKey(options: CacheKeyBuildOptions) {\n return buildRedisKeyPath(options);\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport process from 'node:process';\nimport type { LoggerOptions } from 'winston';\nimport { createLogger as create, format, transports } from 'winston';\nimport type { Logger, LoggerCreateContext } from './types';\n\nexport function createNoopLogger() : Logger {\n return create({ silent: true });\n}\n\nexport function createLogger(context: LoggerCreateContext) : Logger {\n let items : LoggerOptions['transports'];\n\n const cwd = context.directory || process.cwd();\n\n if (context.env === 'production') {\n items = [\n new transports.Console({ level: 'info' }),\n new transports.File({\n filename: path.join(cwd, 'http.log'),\n level: 'http',\n maxsize: 10 * 1024 * 1024, // 10MB\n maxFiles: 5,\n }),\n new transports.File({\n filename: path.join(cwd, 'error.log'),\n level: 'warn',\n maxsize: 10 * 1024 * 1024, // 10MB\n maxFiles: 5,\n }),\n ];\n } else {\n items = [\n new transports.Console({ level: 'debug' }),\n ];\n }\n\n // @see https://github.com/winstonjs/triple-beam/blob/master/config/npm.js\n return create({\n format: format.combine(\n format.errors({ stack: true }),\n format.timestamp(),\n format.colorize(),\n format.simple(),\n ),\n transports: items,\n });\n}\n","/*\n * Copyright (c) 2023-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { type Factory, singa } from 'singa';\nimport type { Logger } from 'winston';\n\nconst instance = singa<Logger>({ name: 'logger' });\n\nexport function setLoggerFactory(factory: Factory<Logger>) {\n instance.setFactory(factory);\n}\n\nexport function isLoggerUsable() {\n return instance.has() || instance.hasFactory();\n}\n\nexport function setLogger(input: Logger) {\n instance.set(input);\n}\n\nexport function useLogger() {\n return instance.use();\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { Factory } from 'singa';\nimport { singa } from 'singa';\nimport type { VaultClient } from '@hapic/vault';\n\nconst instance = singa<VaultClient>({ name: 'vault' });\n\nexport function setVaultFactory(factory: Factory<VaultClient>) {\n instance.setFactory(factory);\n}\n\nexport function isVaultClientUsable() {\n return instance.has() || instance.hasFactory();\n}\n\nexport function useVaultClient() {\n return instance.use();\n}\n","/*\n * Copyright (c) 2023-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { ObjectLiteral } from '@authup/kit';\nimport { isObject } from '@authup/kit';\nimport type { DomainEventChannelName } from './type';\n\nexport function transformDomainEventData<T extends ObjectLiteral>(input: T) : T {\n const keys = Object.keys(input);\n for (const key_ of keys) {\n const key = key_ as keyof T;\n\n const value = input[key] as T[keyof T];\n if (!isObject(value)) {\n continue;\n }\n\n if ((value as Record<string, any>) instanceof Date) {\n input[key] = value.toISOString() as T[keyof T];\n }\n }\n\n return input;\n}\n\nexport function buildDomainEventChannelName(\n input: DomainEventChannelName,\n id?: string | number,\n) : string {\n if (typeof input === 'string') {\n return input;\n }\n\n return input(id);\n}\n","/*\n * Copyright (c) 2023-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { Client } from 'redis-extension';\nimport type { RedisClientCreateInput } from '../../services';\nimport { createRedisClient } from '../../services';\nimport type { DomainEventPublishContext, IDomainEventPublisher } from '../type';\nimport { buildDomainEventChannelName, transformDomainEventData } from '../utils';\n\nexport class DomainEventRedisPublisher implements IDomainEventPublisher {\n protected driver : Client;\n\n constructor(input: RedisClientCreateInput) {\n this.driver = createRedisClient(input);\n }\n\n async publish(ctx: DomainEventPublishContext) : Promise<void> {\n const data = JSON.stringify(transformDomainEventData(ctx.content));\n\n const pipeline = this.driver.pipeline();\n for (let i = 0; i < ctx.destinations.length; i++) {\n const { namespace } = ctx.destinations[i];\n const keyPrefix = (namespace ? `${namespace}:` : '');\n\n let key = keyPrefix + buildDomainEventChannelName(ctx.destinations[i].channel);\n pipeline.publish(key, data);\n\n if (typeof ctx.destinations[i].channel === 'function') {\n key = keyPrefix + buildDomainEventChannelName(ctx.destinations[i].channel, ctx.content.data.id);\n pipeline.publish(key, data);\n }\n }\n\n await pipeline.exec();\n }\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { buildEventFullName } from '@authup/core-realtime-kit';\nimport { Emitter } from '@socket.io/redis-emitter';\nimport type { RedisClientCreateInput } from '../../services';\nimport { createRedisClient } from '../../services';\nimport type { DomainEventPublishContext, IDomainEventPublisher } from '../type';\nimport { buildDomainEventChannelName, transformDomainEventData } from '../utils';\n\nexport class DomainEventSocketPublisher implements IDomainEventPublisher {\n protected driver : Emitter;\n\n constructor(input: RedisClientCreateInput) {\n const client = createRedisClient(input);\n this.driver = new Emitter(client);\n }\n\n async publish(ctx: DomainEventPublishContext) : Promise<void> {\n ctx.content = transformDomainEventData(ctx.content);\n\n for (let i = 0; i < ctx.destinations.length; i++) {\n const destination = ctx.destinations[i];\n\n let emitter : Emitter;\n\n if (destination.namespace) {\n emitter = this.driver.of(destination.namespace);\n } else {\n emitter = this.driver;\n }\n\n let roomName = buildDomainEventChannelName(destination.channel);\n\n const fullEventName = buildEventFullName(ctx.content.type, ctx.content.event);\n\n emitter\n .in(roomName)\n .emit(fullEventName, {\n ...ctx.content,\n meta: { roomName },\n });\n\n if (typeof destination.channel === 'function') {\n roomName = buildDomainEventChannelName(destination.channel, ctx.content.data.id);\n\n emitter\n .in(roomName)\n .emit(fullEventName, {\n ...ctx.content,\n meta: {\n roomName,\n roomId: ctx.content.data.id,\n },\n });\n }\n }\n }\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(\n obj: X,\n prop: Y,\n): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AASA,eAAsB,QAAQ,OAAe,aAAwC;AACjF,QAAOA,UAAc,OAAO,YAAY;;;;ACD5C,eAAsB,KAAK,KAAa,SAAiB,IAAsB;AAC3E,QAAOC,OAAW,KAAK,OAAO;;;;ACHlC,IAAY,4BAAL,yBAAA,2BAAA;AACH,2BAAA,aAAA;AACA,2BAAA,uBAAA;AACA,2BAAA,cAAA;AACA,2BAAA,WAAA;AACA,2BAAA,UAAA;;KACH;;;ACHD,IAAsB,UAAtB,MAA8B;CAC1B;CAIA,YAAY,WA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6B;AAC7B,QAAO,OAAO,UAAU,eAAe,KAAK,KAAK,KAAK"}
1
+ {"version":3,"file":"index.mjs","names":["compareMethod","hashMethod","isObject","isObject","create","instance"],"sources":["../src/crypto/hash/compare.ts","../src/crypto/hash/hash.ts","../src/crypto/key/asymmetric/constants.ts","../src/crypto/key/base.ts","../src/crypto/key/asymmetric/helpers/wrap.ts","../src/crypto/key/asymmetric/key-usages.ts","../src/crypto/key/asymmetric/normalize.ts","../src/crypto/key/asymmetric/module.ts","../src/crypto/key/asymmetric/check.ts","../src/crypto/key/asymmetric/create.ts","../src/crypto/key/symmetric/constants.ts","../src/crypto/key/symmetric/check.ts","../src/crypto/key/symmetric/key-usages.ts","../src/crypto/key/symmetric/normalize.ts","../src/crypto/key/symmetric/module.ts","../src/crypto/key/symmetric/create.ts","../src/crypto/json-web-token/extract.ts","../src/crypto/json-web-token/utils.ts","../src/crypto/json-web-token/sign/module.ts","../src/crypto/json-web-token/verify/module.ts","../src/domain-event/module.ts","../src/services/cache/adapters/memory.ts","../src/services/redis/check.ts","../src/services/redis/factory.ts","../src/services/cache/adapters/redis.ts","../src/services/cache/helper.ts","../src/services/logger/module.ts","../src/services/logger/singleton.ts","../src/services/vault/singleton.ts","../src/domain-event/utils.ts","../src/domain-event/redis/module.ts","../src/domain-event/socket/module.ts","../src/utils/has-property.ts"],"sourcesContent":["/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { compare as compareMethod } from '@node-rs/bcrypt';\n\nexport async function compare(value: string, hashedValue: string) : Promise<boolean> {\n return compareMethod(value, hashedValue);\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hash as hashMethod } from '@node-rs/bcrypt';\n\nexport async function hash(str: string, rounds: number = 10) : Promise<string> {\n return hashMethod(str, rounds);\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum CryptoAsymmetricAlgorithm {\n RSA_PSS = 'RSA-PSS',\n RSASSA_PKCS1_V1_5 = 'RSASSA-PKCS1-v1_5',\n RSA_OAEP = 'RSA-OAEP',\n ECDSA = 'ECDSA',\n ECDH = 'ECDH',\n}\n","/*\n * Copyright (c) 2025-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { arrayBufferToBase64 } from '@authup/kit';\nimport { subtle } from 'uncrypto';\n\nexport abstract class BaseKey {\n protected key : CryptoKey;\n\n // ----------------------------------------------\n\n constructor(cryptoKey : CryptoKey) {\n this.key = cryptoKey;\n }\n\n // ----------------------------------------------\n\n async toArrayBuffer(): Promise<ArrayBuffer> {\n if (this.key.type === 'private') {\n return subtle.exportKey('pkcs8', this.key);\n }\n\n if (this.key.type === 'public') {\n return subtle.exportKey('spki', this.key);\n }\n\n return subtle.exportKey('raw', this.key);\n }\n\n async toUint8Array(): Promise<Uint8Array> {\n const arrayBuffer = await this.toArrayBuffer();\n return new Uint8Array(arrayBuffer);\n }\n\n async toBase64() : Promise<string> {\n const arrayBuffer = await this.toArrayBuffer();\n return arrayBufferToBase64(arrayBuffer);\n }\n\n async toJWK() : Promise<JsonWebKey> {\n return subtle.exportKey('jwk', this.key);\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nfunction enc(\n type: 'PRIVATE KEY' | 'PUBLIC KEY',\n input: string,\n) {\n return `-----BEGIN ${type}-----\\n${input}\\n-----END ${type}-----`;\n}\n\nexport function encodePKCS8ToPEM(base64: string) {\n return enc('PRIVATE KEY', base64);\n}\n\nexport function encodeSPKIToPem(input: string) {\n return enc('PUBLIC KEY', input);\n}\n\n// ------------------------------------------------------------\n\nfunction dec(\n type: 'PRIVATE KEY' | 'PUBLIC KEY',\n input: string,\n) {\n input = input.replace(`-----BEGIN ${type}-----\\n`, '');\n\n input = input.replace(`\\n-----END ${type}-----\\n`, '');\n input = input.replace(`-----END ${type}-----\\n`, '');\n input = input.replace(`\\n-----END ${type}-----`, '');\n\n return input;\n}\n\nexport function decodePemToPKCS8(input: string) {\n return dec('PRIVATE KEY', input);\n}\n\nexport function decodePemToSpki(input: string) {\n return dec('PUBLIC KEY', input);\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { CryptoAsymmetricAlgorithm } from './constants';\n\n/**\n * @see https://nodejs.org/api/webcrypto.html#cryptokeyusages\n */\nexport function getKeyUsagesForAsymmetricAlgorithm(\n name: string,\n format?: Exclude<KeyFormat, 'jwk'>,\n) : KeyUsage[] {\n if (\n name === CryptoAsymmetricAlgorithm.RSA_PSS ||\n name === CryptoAsymmetricAlgorithm.ECDSA ||\n name === CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5\n ) {\n if (format === 'spki') {\n return ['verify'];\n } if (format === 'pkcs8') {\n return ['sign'];\n }\n\n return ['sign', 'verify'];\n }\n\n if (name === CryptoAsymmetricAlgorithm.ECDH) {\n if (format === 'spki') {\n return [];\n }\n\n return [\n 'deriveKey',\n 'deriveBits',\n ];\n }\n\n if (name === CryptoAsymmetricAlgorithm.RSA_OAEP) {\n if (format === 'spki') {\n return ['encrypt'];\n } if (format === 'pkcs8') {\n return ['decrypt'];\n }\n\n return ['encrypt', 'decrypt'];\n }\n\n throw new SyntaxError(`Key usages can not be determined for asymmetric algorithm: ${name}`);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { CryptoAsymmetricAlgorithm } from './constants';\nimport type {\n AsymmetricKeyImportOptionsInput,\n AsymmetricKeyPairCreateOptions,\n AsymmetricKeyPairCreateOptionsInput,\n AsymmetricKeyPairImportOptions,\n} from './types';\n\nexport function normalizeAsymmetricKeyPairCreateOptions(\n options: AsymmetricKeyPairCreateOptionsInput,\n) : AsymmetricKeyPairCreateOptions {\n let optionsNormalized : AsymmetricKeyPairCreateOptions;\n switch (options.name) {\n case CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5:\n case CryptoAsymmetricAlgorithm.RSA_PSS:\n case CryptoAsymmetricAlgorithm.RSA_OAEP: {\n optionsNormalized = {\n modulusLength: 2048,\n publicExponent: new Uint8Array([0x01, 0x00, 0x01]),\n hash: 'SHA-256',\n ...options,\n };\n break;\n }\n case CryptoAsymmetricAlgorithm.ECDSA:\n case CryptoAsymmetricAlgorithm.ECDH: {\n optionsNormalized = {\n namedCurve: 'P-256',\n ...options,\n };\n }\n }\n\n return optionsNormalized;\n}\n\nexport function normalizeAsymmetricKeyImportOptions(\n options: AsymmetricKeyImportOptionsInput,\n) : AsymmetricKeyPairImportOptions {\n let optionsNormalized : AsymmetricKeyPairImportOptions;\n switch (options.name) {\n case CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5:\n case CryptoAsymmetricAlgorithm.RSA_PSS:\n case CryptoAsymmetricAlgorithm.RSA_OAEP: {\n optionsNormalized = {\n hash: 'SHA-256',\n ...options,\n };\n break;\n }\n case CryptoAsymmetricAlgorithm.ECDSA:\n case CryptoAsymmetricAlgorithm.ECDH: {\n optionsNormalized = {\n namedCurve: 'P-256',\n ...options,\n };\n }\n }\n\n return optionsNormalized;\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { base64ToArrayBuffer } from '@authup/kit';\nimport { JWTAlgorithm } from '@authup/specs';\nimport { subtle } from 'uncrypto';\nimport { BaseKey } from '../base';\nimport { CryptoAsymmetricAlgorithm } from './constants';\nimport type { AsymmetricKeyImportContext } from './types';\nimport {\n decodePemToPKCS8, \n decodePemToSpki, \n encodePKCS8ToPEM, \n encodeSPKIToPem,\n} from './helpers';\nimport { getKeyUsagesForAsymmetricAlgorithm } from './key-usages';\nimport { normalizeAsymmetricKeyImportOptions } from './normalize';\n\nexport class AsymmetricKey extends BaseKey {\n async toPem(): Promise<string> {\n const base64 = await this.toBase64();\n\n if (this.key.type === 'public') {\n return encodeSPKIToPem(base64);\n }\n\n if (this.key.type === 'private') {\n return encodePKCS8ToPEM(base64);\n }\n\n throw new Error(`${this.key.type} can not be converted to pem.`);\n }\n\n // ----------------------------------------------------------------\n\n static async fromPem(ctx: AsymmetricKeyImportContext<string>): Promise<AsymmetricKey> {\n if (ctx.format === 'pkcs8') {\n return AsymmetricKey.fromBase64({\n ...ctx,\n key: decodePemToPKCS8(ctx.key), \n });\n }\n return AsymmetricKey.fromBase64({\n ...ctx,\n key: decodePemToSpki(ctx.key), \n });\n }\n\n static async fromBase64(\n ctx: AsymmetricKeyImportContext<string>,\n ) : Promise<AsymmetricKey> {\n const arrayBuffer = base64ToArrayBuffer(ctx.key);\n\n return AsymmetricKey.fromArrayBuffer({\n ...ctx,\n key: arrayBuffer,\n });\n }\n\n static async fromArrayBuffer(\n ctx: AsymmetricKeyImportContext<ArrayBuffer>,\n ) : Promise<AsymmetricKey> {\n const normalizedOptions = normalizeAsymmetricKeyImportOptions(ctx.options);\n\n const cryptoKey = await subtle.importKey(\n ctx.format,\n ctx.key,\n normalizedOptions,\n true,\n getKeyUsagesForAsymmetricAlgorithm(normalizedOptions.name, ctx.format),\n );\n\n return new AsymmetricKey(cryptoKey);\n }\n\n // ----------------------------------------------------------------\n\n static buildImportOptionsForJWTAlgorithm(alg: `${JWTAlgorithm}`) {\n if (alg === JWTAlgorithm.RS256) {\n return {\n name: CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5,\n hash: 'SHA-256',\n };\n }\n\n if (alg === JWTAlgorithm.RS384) {\n return {\n name: CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5,\n hash: 'SHA-384',\n };\n }\n\n if (alg === JWTAlgorithm.RS512) {\n return {\n name: CryptoAsymmetricAlgorithm.RSASSA_PKCS1_V1_5,\n hash: 'SHA-512',\n };\n }\n\n if (alg === JWTAlgorithm.ES256) {\n return {\n name: CryptoAsymmetricAlgorithm.ECDSA,\n namedCurve: 'P-256',\n };\n }\n\n if (alg === JWTAlgorithm.ES384) {\n return {\n name: CryptoAsymmetricAlgorithm.ECDSA,\n namedCurve: 'P-384',\n };\n }\n\n if (alg === JWTAlgorithm.ES512) {\n return {\n name: CryptoAsymmetricAlgorithm.ECDSA,\n namedCurve: 'P-521',\n };\n }\n\n throw new Error(`Signature algorithm ${alg} is not supported.`);\n }\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { CryptoAsymmetricAlgorithm } from './constants';\n\nexport function isAsymmetricAlgorithm(input: string) : input is CryptoAsymmetricAlgorithm {\n return (Object.values(CryptoAsymmetricAlgorithm) as string[]).includes(input);\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { subtle } from 'uncrypto';\nimport { getKeyUsagesForAsymmetricAlgorithm } from './key-usages';\nimport { normalizeAsymmetricKeyPairCreateOptions } from './normalize';\nimport type { AsymmetricKeyPairCreateOptionsInput } from './types';\n\nexport async function createAsymmetricKeyPair(options: AsymmetricKeyPairCreateOptionsInput) : Promise<CryptoKeyPair> {\n const optionsNormalized = normalizeAsymmetricKeyPairCreateOptions(options);\n return subtle.generateKey(\n optionsNormalized,\n true,\n getKeyUsagesForAsymmetricAlgorithm(optionsNormalized.name),\n );\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum SymmetricAlgorithm {\n HMAC = 'HMAC',\n AES_CTR = 'AES-CTR',\n AES_CBC = 'AES-CBC',\n AES_GCM = 'AES-GCM',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { SymmetricAlgorithm } from './constants';\n\nexport function isSymmetricAlgorithm(input: string) : input is SymmetricAlgorithm {\n return (Object.values(SymmetricAlgorithm) as string[]).includes(input);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { SymmetricAlgorithm } from './constants';\n\nexport function getKeyUsagesForSymmetricAlgorithm(name: string) : KeyUsage[] {\n /**\n * @see https://nodejs.org/api/webcrypto.html#cryptokeyusages\n */\n if (name === SymmetricAlgorithm.HMAC) {\n return [\n 'sign',\n 'verify',\n ];\n }\n\n if (\n name === SymmetricAlgorithm.AES_CBC ||\n name === SymmetricAlgorithm.AES_GCM ||\n name === SymmetricAlgorithm.AES_CTR\n ) {\n return [\n 'encrypt',\n 'decrypt',\n ];\n }\n\n throw new SyntaxError(`Key usages can not be determined for symmetric algorithm: ${name}`);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { SymmetricAlgorithm } from './constants';\nimport type {\n SymmetricKeyCreateOptions, \n SymmetricKeyCreateOptionsInput, \n SymmetricKeyImportOptions, \n SymmetricKeyImportOptionsInput,\n} from './types';\n\nexport function normalizeSymmetricKeyCreateOptions(\n input: SymmetricKeyCreateOptionsInput,\n) : SymmetricKeyCreateOptions {\n if (input.name === SymmetricAlgorithm.HMAC) {\n return {\n hash: 'SHA-256',\n ...input,\n };\n }\n\n return {\n length: 256,\n name: input.name,\n };\n}\n\nexport function normalizeSymmetricKeyImportOptions(\n input: SymmetricKeyImportOptionsInput,\n) : SymmetricKeyImportOptions {\n if (input.name === SymmetricAlgorithm.HMAC) {\n return {\n hash: 'SHA-256',\n ...input,\n };\n }\n\n return input;\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { base64ToArrayBuffer } from '@authup/kit';\nimport { JWTAlgorithm } from '@authup/specs';\nimport { subtle } from 'uncrypto';\nimport { BaseKey } from '../base';\nimport { SymmetricAlgorithm } from './constants';\nimport { getKeyUsagesForSymmetricAlgorithm } from './key-usages';\nimport { normalizeSymmetricKeyImportOptions } from './normalize';\nimport type { SymmetricKeyImportContext, SymmetricKeyImportOptions } from './types';\n\nexport class SymmetricKey extends BaseKey {\n static async fromBase64(\n ctx: SymmetricKeyImportContext<string>,\n ) : Promise<SymmetricKey> {\n const arrayBuffer = base64ToArrayBuffer(ctx.key);\n\n return SymmetricKey.fromArrayBuffer({\n ...ctx,\n key: arrayBuffer,\n });\n }\n\n static async fromArrayBuffer(\n ctx: SymmetricKeyImportContext<ArrayBuffer>,\n ) : Promise<SymmetricKey> {\n const normalizedOptions : SymmetricKeyImportOptions = normalizeSymmetricKeyImportOptions(ctx.options);\n\n const cryptoKey = await subtle.importKey(\n ctx.format,\n ctx.key,\n normalizedOptions,\n true,\n getKeyUsagesForSymmetricAlgorithm(normalizedOptions.name),\n );\n\n return new SymmetricKey(cryptoKey);\n }\n\n static buildImportOptionsForJWTAlgorithm(alg: `${JWTAlgorithm}`) {\n if (alg === JWTAlgorithm.HS256) {\n return {\n name: SymmetricAlgorithm.HMAC,\n hash: 'SHA-256',\n };\n }\n\n if (alg === JWTAlgorithm.HS384) {\n return {\n name: SymmetricAlgorithm.HMAC,\n hash: 'SHA-384',\n };\n }\n\n if (alg === JWTAlgorithm.HS512) {\n return {\n name: SymmetricAlgorithm.HMAC,\n hash: 'SHA-512',\n };\n }\n\n throw new Error(`Signature algorithm ${alg} is not supported.`);\n }\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { subtle } from 'uncrypto';\nimport { getKeyUsagesForSymmetricAlgorithm } from './key-usages';\nimport { normalizeSymmetricKeyCreateOptions } from './normalize';\nimport type { SymmetricKeyCreateOptionsInput } from './types';\n\nexport async function createSymmetricKey(input: SymmetricKeyCreateOptionsInput) : Promise<CryptoKey> {\n const optionsNormalized = normalizeSymmetricKeyCreateOptions(input);\n\n return subtle.generateKey(\n optionsNormalized,\n true,\n getKeyUsagesForSymmetricAlgorithm(optionsNormalized.name),\n );\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { JWTClaims, JWTHeader } from '@authup/specs';\nimport { JWTError } from '@authup/specs';\n\n/**\n * Decode a JWT token with no verification.\n *\n * @param token\n *\n * @throws JWTError\n */\nexport function extractTokenHeader(\n token: string,\n) : JWTHeader {\n const parts = token.split('.');\n if (parts.length !== 3) {\n throw JWTError.invalid();\n }\n\n const [headerBase64] = parts;\n\n try {\n const payload = atob(headerBase64);\n\n return JSON.parse(payload);\n\n /*\n return {\n typ: 'JWT',\n alg: transformInternalToJWTAlgorithm(header.algorithm),\n cty: header.contentType,\n jku: header.jsonKeyUrl,\n kid: header.keyId,\n x5u: header.x5Url,\n x5c: header.x5CertChain,\n x5t: header.x5CertThumbprint,\n 'x5t#S256': header.x5TS256CertThumbprint,\n };\n */\n } catch {\n throw JWTError.headerInvalid('The token header could not be extracted.');\n }\n}\n\n/**\n * @param token\n *\n * @throws JWTError\n */\nexport function extractTokenPayload(\n token: string,\n) : JWTClaims {\n const parts = token.split('.');\n if (parts.length !== 3) {\n throw JWTError.invalid();\n }\n\n const [, payloadBase64] = parts;\n\n try {\n const payload = atob(payloadBase64);\n\n return JSON.parse(payload);\n } catch {\n throw JWTError.payloadInvalid('The token payload could not be extracted.');\n }\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { JWTAlgorithm, JWTError } from '@authup/specs';\nimport { Algorithm } from '@node-rs/jsonwebtoken';\nimport { isObject } from 'smob';\n\nexport function createErrorForJWTError(e: unknown) : JWTError {\n if (isObject(e)) {\n if (typeof e.name === 'string') {\n switch (e.name) {\n case 'TokenExpiredError': {\n return JWTError.expired();\n }\n case 'NotBeforeError': {\n if (typeof e.date === 'string' || e.date instanceof Date) {\n return JWTError.notActiveBefore(e.date);\n }\n break;\n }\n case 'JsonWebTokenError': {\n if (typeof e.message === 'string') {\n return JWTError.payloadInvalid(e.message);\n }\n\n break;\n }\n }\n }\n\n // @see https://github.com/Keats/jsonwebtoken/blob/master/src/errors.rs\n switch (e.message) {\n case 'ExpiredSignature': {\n return JWTError.expired();\n }\n case 'ImmatureSignature': {\n return JWTError.notActiveBefore();\n }\n case 'InvalidToken':\n case 'InvalidSignature': {\n return JWTError.payloadInvalid();\n }\n }\n }\n\n return new JWTError({\n cause: e as Error,\n logMessage: true,\n message: 'The JWT error could not be determined.',\n });\n}\n\nexport function transformJWTAlgorithmToInternal(algorithm: `${JWTAlgorithm}`) : Algorithm {\n switch (algorithm) {\n case JWTAlgorithm.HS256: {\n return Algorithm.HS256;\n }\n case JWTAlgorithm.HS384: {\n return Algorithm.HS384;\n }\n case JWTAlgorithm.HS512: {\n return Algorithm.HS512;\n }\n case JWTAlgorithm.RS256: {\n return Algorithm.RS256;\n }\n case JWTAlgorithm.RS384: {\n return Algorithm.RS384;\n }\n case JWTAlgorithm.RS512: {\n return Algorithm.RS512;\n }\n case JWTAlgorithm.ES256: {\n return Algorithm.ES256;\n }\n case JWTAlgorithm.ES384: {\n return Algorithm.ES384;\n }\n case JWTAlgorithm.PS256: {\n return Algorithm.PS256;\n }\n case JWTAlgorithm.PS384: {\n return Algorithm.PS384;\n }\n case JWTAlgorithm.PS512: {\n return Algorithm.PS512;\n }\n }\n\n throw new Error(`The algorithm ${algorithm} is not supported.`);\n}\n\nexport function transformInternalToJWTAlgorithm(input: Algorithm) : JWTAlgorithm {\n switch (input) {\n case Algorithm.HS256:\n return JWTAlgorithm.HS256;\n case Algorithm.HS384:\n return JWTAlgorithm.HS384;\n case Algorithm.HS512:\n return JWTAlgorithm.HS512;\n case Algorithm.RS256:\n return JWTAlgorithm.RS256;\n case Algorithm.RS384:\n return JWTAlgorithm.RS384;\n case Algorithm.RS512:\n return JWTAlgorithm.RS512;\n case Algorithm.ES256:\n return JWTAlgorithm.ES256;\n case Algorithm.ES384:\n return JWTAlgorithm.ES384;\n case Algorithm.PS256:\n return JWTAlgorithm.PS256;\n case Algorithm.PS384:\n return JWTAlgorithm.PS384;\n case Algorithm.PS512:\n return JWTAlgorithm.PS512;\n }\n\n throw new SyntaxError(`The algorithm ${input} is not supported.`);\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { JWKType, JWTError } from '@authup/specs';\nimport type { JWTClaims } from '@authup/specs';\nimport { Algorithm, sign } from '@node-rs/jsonwebtoken';\nimport { AsymmetricKey, SymmetricKey, encodePKCS8ToPEM } from '../../key';\nimport { transformJWTAlgorithmToInternal } from '../utils';\nimport type { TokenSignOptions } from './types';\n\nconst getUtcTimestamp = () => Math.floor(new Date().getTime() / 1000);\n\nexport async function signToken(claims: JWTClaims, context: TokenSignOptions): Promise<string> {\n if (typeof claims.exp !== 'number') {\n claims.exp = getUtcTimestamp() + 3600;\n }\n if (typeof claims.iat !== 'number') {\n claims.iat = getUtcTimestamp();\n }\n\n switch (context.type) {\n case JWKType.RSA:\n case JWKType.EC: {\n let algorithm : Algorithm;\n\n let key : string;\n if (typeof context.key === 'string') {\n key = encodePKCS8ToPEM(context.key);\n } else {\n const keyContainer = new AsymmetricKey(context.key);\n key = await keyContainer.toPem();\n }\n\n if (context.type === JWKType.RSA) {\n algorithm = context.algorithm ?\n transformJWTAlgorithmToInternal(context.algorithm) :\n Algorithm.RS256;\n } else {\n algorithm = context.algorithm ?\n transformJWTAlgorithmToInternal(context.algorithm) :\n Algorithm.ES256;\n }\n\n return sign(claims, key, {\n algorithm,\n keyId: context.keyId,\n });\n }\n case JWKType.OCT: {\n const algorithm : Algorithm = context.algorithm ?\n transformJWTAlgorithmToInternal(context.algorithm) :\n Algorithm.HS256;\n\n let key : string | Uint8Array;\n if (typeof context.key === 'string') {\n key = context.key;\n } else {\n const keyContainer = new SymmetricKey(context.key);\n key = await keyContainer.toUint8Array();\n }\n\n return sign(claims, key, {\n algorithm,\n keyId: context.keyId,\n });\n }\n }\n\n throw new JWTError();\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { JWKType, JWTError } from '@authup/specs';\nimport type { JWTClaims, OAuth2TokenPayload } from '@authup/specs';\nimport { Algorithm, verify } from '@node-rs/jsonwebtoken';\nimport { AsymmetricKey, SymmetricKey, encodeSPKIToPem } from '../../key';\nimport { createErrorForJWTError, transformJWTAlgorithmToInternal } from '../utils';\nimport type { TokenVerifyOptions } from './types';\n\n/**\n * Verify JWT.\n *\n * @param token\n * @param context\n *\n * @throws OAuth2Error\n */\nexport async function verifyToken(\n token: string,\n context: TokenVerifyOptions,\n) : Promise<OAuth2TokenPayload> {\n let promise : Promise<JWTClaims> | undefined;\n\n let output : JWTClaims | undefined;\n\n try {\n switch (context.type) {\n case JWKType.RSA:\n case JWKType.EC: {\n let algorithms : Algorithm[];\n\n if (context.type === JWKType.RSA) {\n algorithms = context.algorithms ?\n context.algorithms.map((algorithm) => transformJWTAlgorithmToInternal(algorithm)) :\n [\n Algorithm.RS256,\n Algorithm.RS384,\n Algorithm.RS512,\n Algorithm.PS256,\n Algorithm.PS384,\n Algorithm.PS512,\n ];\n } else {\n algorithms = context.algorithms ?\n context.algorithms.map((algorithm) => transformJWTAlgorithmToInternal(algorithm)) :\n [\n Algorithm.ES256,\n Algorithm.ES384,\n ];\n }\n\n let key : string;\n if (typeof context.key === 'string') {\n key = encodeSPKIToPem(context.key);\n } else {\n const keyContainer = new AsymmetricKey(context.key);\n key = await keyContainer.toPem();\n }\n\n promise = verify(token, key, {\n algorithms,\n validateNbf: true,\n });\n break;\n }\n case JWKType.OCT: {\n const algorithms : Algorithm[] = context.algorithms ?\n context.algorithms.map((algorithm) => transformJWTAlgorithmToInternal(algorithm)) :\n [\n Algorithm.HS256,\n Algorithm.HS384,\n Algorithm.HS512,\n ];\n\n let key : string | Uint8Array;\n if (typeof context.key === 'string') {\n key = context.key;\n } else {\n const keyContainer = new SymmetricKey(context.key);\n key = await keyContainer.toUint8Array();\n }\n\n promise = verify(token, key, {\n algorithms,\n validateNbf: true,\n });\n }\n }\n\n if (promise) {\n output = await promise;\n }\n } catch (e) {\n throw createErrorForJWTError(e);\n }\n\n if (!output) {\n throw new JWTError();\n }\n\n return output as OAuth2TokenPayload;\n}\n","/*\n * Copyright (c) 2024-2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { EventPayload } from '@authup/core-realtime-kit';\nimport type { DomainEventPublishContext, IDomainEventPublisher } from './type';\n\nexport class DomainEventPublisher implements IDomainEventPublisher {\n protected publishers : Set<IDomainEventPublisher>;\n\n constructor() {\n this.publishers = new Set<IDomainEventPublisher>();\n }\n\n mount(publisher: IDomainEventPublisher): void {\n this.publishers.add(publisher);\n }\n\n async publish<T extends EventPayload>(\n ctx: DomainEventPublishContext<T>,\n ) : Promise<void> {\n const publishers = this.publishers.values();\n while (true) {\n const it = publishers.next();\n if (it.done) {\n return;\n }\n\n await it.value.publish(ctx);\n }\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { TTLCacheOptions } from '@isaacs/ttlcache';\nimport { TTLCache } from '@isaacs/ttlcache';\nimport type { CacheClearOptions, CacheSetOptions, ICache } from '../types';\n\nexport class MemoryCache implements ICache {\n protected instance : TTLCache<string, unknown>;\n\n constructor(options: TTLCacheOptions<string, unknown> = {}) {\n this.instance = new TTLCache<string, unknown>({\n checkAgeOnGet: true,\n ttl: Infinity,\n ...(options || {}),\n });\n }\n\n async pop<T = unknown>(key: string): Promise<T | null> {\n if (this.instance.has(key)) {\n const output = this.instance.get(key);\n this.instance.delete(key);\n return output as T;\n }\n\n return null;\n }\n\n async has(key: string) : Promise<boolean> {\n return this.instance.has(key);\n }\n\n async get<T =unknown>(key: string): Promise<T | null> {\n const output = await this.instance.get(key);\n if (output) {\n return output as T;\n }\n\n return null;\n }\n\n async set(key: string, value: unknown, options: CacheSetOptions): Promise<void> {\n this.instance.set(key, value, { ttl: options.ttl });\n }\n\n async drop(key: string): Promise<void> {\n this.instance.delete(key);\n }\n\n async dropMany(keys: string[]) : Promise<void> {\n for (const key of keys) {\n this.instance.delete(key);\n }\n }\n\n async clear(options: CacheClearOptions = {}) : Promise<void> {\n if (options.prefix) {\n const keys = this.instance.keys();\n let iterator = keys.next();\n while (!iterator.done) {\n if (typeof iterator.value !== 'string') {\n continue;\n }\n\n if (iterator.value.startsWith(options.prefix)) {\n this.instance.delete(iterator.value);\n }\n\n iterator = keys.next();\n }\n\n return;\n }\n\n this.instance.clear();\n }\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isObject } from 'smob';\nimport type { RedisClient } from './module';\n\nexport function isRedisClient(data: unknown) : data is RedisClient {\n return isObject(data) &&\n typeof data.connect === 'function' &&\n typeof data.disconnect === 'function';\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { createClient } from 'redis-extension';\nimport { isRedisClient } from './check';\nimport type { RedisClient, RedisClientOptions } from './module';\n\nexport type RedisClientCreateInput = string | boolean | RedisClient | RedisClientOptions;\n\nexport function createRedisClient(input: RedisClientCreateInput) {\n if (typeof input === 'boolean') {\n return createClient({ connectionString: 'redis://127.0.0.1' });\n }\n\n if (typeof input === 'string') {\n return createClient({ connectionString: input });\n }\n\n if (!isRedisClient(input)) {\n return createClient({ options: input });\n }\n\n return input;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { Client } from 'redis-extension';\nimport { JsonAdapter } from 'redis-extension';\nimport type { RedisClient, RedisClientOptions } from '../../redis';\nimport { createRedisClient } from '../../redis';\nimport type { CacheClearOptions, CacheSetOptions, ICache } from '../types';\n\nexport class RedisCache implements ICache {\n protected client : Client;\n\n protected jsonAdapter : JsonAdapter;\n\n constructor(input: string | boolean | RedisClient | RedisClientOptions) {\n this.client = createRedisClient(input);\n this.jsonAdapter = new JsonAdapter(this.client);\n }\n\n async get(key: string): Promise<any> {\n const output = await this.jsonAdapter.get(key);\n if (output) {\n return output;\n }\n\n return null;\n }\n\n async pop<T = unknown>(key: string): Promise<T | null> {\n const raw = await this.client.getdel(key);\n if (!raw) {\n return null;\n }\n\n try {\n return JSON.parse(raw) as T;\n } catch {\n return null;\n }\n }\n\n async has(key: string) : Promise<boolean> {\n const output = await this.get(key);\n\n return !!output;\n }\n\n async set(key: string, value: any, options: CacheSetOptions): Promise<void> {\n await this.jsonAdapter.set(key, value, { milliseconds: options.ttl });\n }\n\n async drop(key: string): Promise<void> {\n await this.jsonAdapter.drop(key);\n }\n\n async dropMany(keys: string[]) : Promise<void> {\n const pipeline = this.client.pipeline();\n\n for (const key of keys) {\n pipeline.del(key);\n }\n\n await pipeline.exec();\n }\n\n async clear(options: CacheClearOptions = {}) : Promise<void> {\n if (options.prefix) {\n const pipeline = this.client.pipeline();\n\n const keys = await this.client.keys(`${options.prefix}*`);\n for (const key of keys) {\n pipeline.del(key);\n }\n\n await pipeline.exec();\n\n return;\n }\n await this.client.flushdb();\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { buildRedisKeyPath } from '../redis';\nimport type { CacheKeyBuildOptions } from './types';\n\nexport function buildCacheKey(options: CacheKeyBuildOptions) {\n return buildRedisKeyPath(options);\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport path from 'node:path';\nimport process from 'node:process';\nimport type { LoggerOptions } from 'winston';\nimport { createLogger as create, format, transports } from 'winston';\nimport type { Logger, LoggerCreateContext } from './types';\n\nexport function createNoopLogger() : Logger {\n return create({ silent: true });\n}\n\nexport function createLogger(context: LoggerCreateContext) : Logger {\n let items : LoggerOptions['transports'];\n\n const cwd = context.directory || process.cwd();\n\n if (context.env === 'production') {\n items = [\n new transports.Console({ level: 'info' }),\n new transports.File({\n filename: path.join(cwd, 'http.log'),\n level: 'http',\n maxsize: 10 * 1024 * 1024, // 10MB\n maxFiles: 5,\n }),\n new transports.File({\n filename: path.join(cwd, 'error.log'),\n level: 'warn',\n maxsize: 10 * 1024 * 1024, // 10MB\n maxFiles: 5,\n }),\n ];\n } else {\n items = [\n new transports.Console({ level: 'debug' }),\n ];\n }\n\n // @see https://github.com/winstonjs/triple-beam/blob/master/config/npm.js\n return create({\n format: format.combine(\n format.errors({ stack: true }),\n format.timestamp(),\n format.colorize(),\n format.simple(),\n ),\n transports: items,\n });\n}\n","/*\n * Copyright (c) 2023-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { type Factory, singa } from 'singa';\nimport type { Logger } from 'winston';\n\nconst instance = singa<Logger>({ name: 'logger' });\n\nexport function setLoggerFactory(factory: Factory<Logger>) {\n instance.setFactory(factory);\n}\n\nexport function isLoggerUsable() {\n return instance.has() || instance.hasFactory();\n}\n\nexport function setLogger(input: Logger) {\n instance.set(input);\n}\n\nexport function useLogger() {\n return instance.use();\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { Factory } from 'singa';\nimport { singa } from 'singa';\nimport type { VaultClient } from '@hapic/vault';\n\nconst instance = singa<VaultClient>({ name: 'vault' });\n\nexport function setVaultFactory(factory: Factory<VaultClient>) {\n instance.setFactory(factory);\n}\n\nexport function isVaultClientUsable() {\n return instance.has() || instance.hasFactory();\n}\n\nexport function useVaultClient() {\n return instance.use();\n}\n","/*\n * Copyright (c) 2023-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { ObjectLiteral } from '@authup/kit';\nimport { isObject } from '@authup/kit';\nimport type { DomainEventChannelName } from './type';\n\nexport function transformDomainEventData<T extends ObjectLiteral>(input: T) : T {\n const keys = Object.keys(input);\n for (const key_ of keys) {\n const key = key_ as keyof T;\n\n const value = input[key] as T[keyof T];\n if (!isObject(value)) {\n continue;\n }\n\n if ((value as Record<string, any>) instanceof Date) {\n input[key] = value.toISOString() as T[keyof T];\n }\n }\n\n return input;\n}\n\nexport function buildDomainEventChannelName(\n input: DomainEventChannelName,\n id?: string | number,\n) : string {\n if (typeof input === 'string') {\n return input;\n }\n\n return input(id);\n}\n","/*\n * Copyright (c) 2023-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { Client } from 'redis-extension';\nimport type { RedisClientCreateInput } from '../../services';\nimport { createRedisClient } from '../../services';\nimport type { DomainEventPublishContext, IDomainEventPublisher } from '../type';\nimport { buildDomainEventChannelName, transformDomainEventData } from '../utils';\n\nexport class DomainEventRedisPublisher implements IDomainEventPublisher {\n protected driver : Client;\n\n constructor(input: RedisClientCreateInput) {\n this.driver = createRedisClient(input);\n }\n\n async publish(ctx: DomainEventPublishContext) : Promise<void> {\n const data = JSON.stringify(transformDomainEventData(ctx.content));\n\n const pipeline = this.driver.pipeline();\n for (let i = 0; i < ctx.destinations.length; i++) {\n const { namespace } = ctx.destinations[i];\n const keyPrefix = (namespace ? `${namespace}:` : '');\n\n let key = keyPrefix + buildDomainEventChannelName(ctx.destinations[i].channel);\n pipeline.publish(key, data);\n\n if (typeof ctx.destinations[i].channel === 'function') {\n key = keyPrefix + buildDomainEventChannelName(ctx.destinations[i].channel, ctx.content.data.id);\n pipeline.publish(key, data);\n }\n }\n\n await pipeline.exec();\n }\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { buildEventFullName } from '@authup/core-realtime-kit';\nimport { Emitter } from '@socket.io/redis-emitter';\nimport type { RedisClientCreateInput } from '../../services';\nimport { createRedisClient } from '../../services';\nimport type { DomainEventPublishContext, IDomainEventPublisher } from '../type';\nimport { buildDomainEventChannelName, transformDomainEventData } from '../utils';\n\nexport class DomainEventSocketPublisher implements IDomainEventPublisher {\n protected driver : Emitter;\n\n constructor(input: RedisClientCreateInput) {\n const client = createRedisClient(input);\n this.driver = new Emitter(client);\n }\n\n async publish(ctx: DomainEventPublishContext) : Promise<void> {\n ctx.content = transformDomainEventData(ctx.content);\n\n for (let i = 0; i < ctx.destinations.length; i++) {\n const destination = ctx.destinations[i];\n\n let emitter : Emitter;\n\n if (destination.namespace) {\n emitter = this.driver.of(destination.namespace);\n } else {\n emitter = this.driver;\n }\n\n let roomName = buildDomainEventChannelName(destination.channel);\n\n const fullEventName = buildEventFullName(ctx.content.type, ctx.content.event);\n\n emitter\n .in(roomName)\n .emit(fullEventName, {\n ...ctx.content,\n meta: { roomName },\n });\n\n if (typeof destination.channel === 'function') {\n roomName = buildDomainEventChannelName(destination.channel, ctx.content.data.id);\n\n emitter\n .in(roomName)\n .emit(fullEventName, {\n ...ctx.content,\n meta: {\n roomName,\n roomId: ctx.content.data.id,\n },\n });\n }\n }\n }\n}\n","/*\n * Copyright (c) 2022-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(\n obj: X,\n prop: Y,\n): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AASA,eAAsB,QAAQ,OAAe,aAAwC;AACjF,QAAOA,UAAc,OAAO,YAAY;;;;ACD5C,eAAsB,KAAK,KAAa,SAAiB,IAAsB;AAC3E,QAAOC,OAAW,KAAK,OAAO;;;;ACHlC,IAAY,4BAAL,yBAAA,2BAAA;AACH,2BAAA,aAAA;AACA,2BAAA,uBAAA;AACA,2BAAA,cAAA;AACA,2BAAA,WAAA;AACA,2BAAA,UAAA;;KACH;;;ACHD,IAAsB,UAAtB,MAA8B;CAC1B;CAIA,YAAY,WAAuB;AAC/B,OAAK,MAAM;;CAKf,MAAM,gBAAsC;AACxC,MAAI,KAAK,IAAI,SAAS,UAClB,QAAO,OAAO,UAAU,SAAS,KAAK,IAAI;AAG9C,MAAI,KAAK,IAAI,SAAS,SAClB,QAAO,OAAO,UAAU,QAAQ,KAAK,IAAI;AAG7C,SAAO,OAAO,UAAU,OAAO,KAAK,IAAI;;CAG5C,MAAM,eAAoC;EACtC,MAAM,cAAc,MAAM,KAAK,eAAe;AAC9C,SAAO,IAAI,WAAW,YAAY;;CAGtC,MAAM,WAA6B;AAE/B,SAAO,oBADa,MAAM,KAAK,eAAe,CACP;;CAG3C,MAAM,QAA8B;AAChC,SAAO,OAAO,UAAU,OAAO,KAAK,IAAI;;;;;ACrChD,SAAS,IACL,MACA,OACF;AACE,QAAO,cAAc,KAAK,SAAS,MAAM,aAAa,KAAK;;AAG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,MAAM,gBAAgB,mBAAmB,IAAI,QAAQ,MAAM,IAAI,QAAQ,MAAM;AAE7E,WACK,GAAG,SAAS,CACZ,KAAK,eAAe;IACjB,GAAG,IAAI;IACP,MAAM,EAAE,UAAU;IACrB,CAAC;AAEN,OAAI,OAAO,YAAY,YAAY,YAAY;AAC3C,eAAW,4BAA4B,YAAY,SAAS,IAAI,QAAQ,KAAK,GAAG;AAEhF,YACK,GAAG,SAAS,CACZ,KAAK,eAAe;KACjB,GAAG,IAAI;KACP,MAAM;MACF;MACA,QAAQ,IAAI,QAAQ,KAAK;MAC5B;KACJ,CAAC;;;;;;;ACnDtB,SAAgB,eACZ,KACA,MAC6B;AAC7B,QAAO,OAAO,UAAU,eAAe,KAAK,KAAK,KAAK"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@authup/server-kit",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.35",
4
+ "version": "1.0.0-beta.36",
5
5
  "description": "A toolkit for server-side services.",
6
6
  "license": "Apache-2.0",
7
7
  "exports": {
@@ -70,17 +70,17 @@
70
70
  "winston": "^3.19.0"
71
71
  },
72
72
  "devDependencies": {
73
- "@authup/core-realtime-kit": "^1.0.0-beta.35",
74
- "@authup/kit": "^1.0.0-beta.35",
75
- "@authup/errors": "^1.0.0-beta.35",
76
- "@authup/specs": "^1.0.0-beta.35",
73
+ "@authup/core-realtime-kit": "^1.0.0-beta.36",
74
+ "@authup/kit": "^1.0.0-beta.36",
75
+ "@authup/errors": "^1.0.0-beta.36",
76
+ "@authup/specs": "^1.0.0-beta.36",
77
77
  "vitest": "^4.0.14"
78
78
  },
79
79
  "peerDependencies": {
80
- "@authup/core-realtime-kit": "^1.0.0-beta.35",
81
- "@authup/kit": "^1.0.0-beta.35",
82
- "@authup/errors": "^1.0.0-beta.35",
83
- "@authup/specs": "^1.0.0-beta.35"
80
+ "@authup/core-realtime-kit": "^1.0.0-beta.36",
81
+ "@authup/kit": "^1.0.0-beta.36",
82
+ "@authup/errors": "^1.0.0-beta.36",
83
+ "@authup/specs": "^1.0.0-beta.36"
84
84
  },
85
85
  "publishConfig": {
86
86
  "access": "public"