@arkstack/common 0.19.2 → 0.19.3

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.
@@ -1,2 +1,2 @@
1
- import { A as SecureChannel, C as Codec, D as Keys, E as KeyPair, O as NodeCipher, S as Cipher, T as EncryptionKey, _ as setModelResolver, a as use, c as abortIf, d as getModelSync, f as initializeGlobalContext, g as resolvePagination, h as perPage, i as trait, k as SealedBox, l as assertFound, m as normalizePositiveInteger, n as crc32, o as uses, p as isClass, r as getTraitMethods, s as abort, t as callTraitMethods, u as getModel, w as Encryption, x as Hash } from "../utils-CvlK2sYM.js";
1
+ import { A as SecureChannel, C as Codec, D as Keys, E as KeyPair, O as NodeCipher, S as Cipher, T as EncryptionKey, _ as setModelResolver, a as use, c as abortIf, d as getModelSync, f as initializeGlobalContext, g as resolvePagination, h as perPage, i as trait, k as SealedBox, l as assertFound, m as normalizePositiveInteger, n as crc32, o as uses, p as isClass, r as getTraitMethods, s as abort, t as callTraitMethods, u as getModel, w as Encryption, x as Hash } from "../utils-DwfM0lt4.js";
2
2
  export { Cipher, Codec, Encryption, EncryptionKey, Hash, KeyPair, Keys, NodeCipher, SealedBox, SecureChannel, abort, abortIf, assertFound, callTraitMethods, crc32, getModel, getModelSync, getTraitMethods, initializeGlobalContext, isClass, normalizePositiveInteger, perPage, resolvePagination, setModelResolver, trait, use, uses };
@@ -1,4 +1,4 @@
1
- import { a as env, t as appKey } from "./system-BH1phDBR.js";
1
+ import { a as env, t as appKey } from "./system-DzAzwH__.js";
2
2
  import { Cipher, Codec, EncryptionKey, KeyPair, Keys, SealedBox, SecureChannel } from "@arkstack/encryption";
3
3
  import { NodeCipher } from "@arkstack/encryption/node";
4
4
  import { Secret, TOTP } from "otpauth";
@@ -202,9 +202,9 @@ var Encryption = class {
202
202
  var Hash = class {
203
203
  /**
204
204
  * Hash a value using bcrypt
205
- *
206
- * @param value
207
- * @returns
205
+ *
206
+ * @param value
207
+ * @returns
208
208
  */
209
209
  static async make(value) {
210
210
  const salt = await genSalt(10);
@@ -212,21 +212,21 @@ var Hash = class {
212
212
  }
213
213
  /**
214
214
  * Verify a value against a hashed value
215
- *
216
- * @param value
217
- * @param hashedValue
218
- * @returns
215
+ *
216
+ * @param value
217
+ * @param hashedValue
218
+ * @returns
219
219
  */
220
220
  static async verify(value, hashedValue) {
221
221
  return await compare(value, hashedValue);
222
222
  }
223
223
  /**
224
224
  * Generate a one-time password (OTP) using TOTP algorithm
225
- *
225
+ *
226
226
  * @param digits The number of digits for the OTP, default is 6.
227
227
  * @param label A label to identify the OTP, can be an email or phone number.
228
228
  * @param period Interval of time for which a token is valid, in seconds.
229
- * @returns
229
+ * @returns
230
230
  */
231
231
  static otp(digits = 6, label = "Alice", period = 30) {
232
232
  return new TOTP({
@@ -292,22 +292,22 @@ var RequestException = class RequestException extends AppException {
292
292
  this.statusCode = statusCode;
293
293
  }
294
294
  /**
295
- * Asserts that a value is not null or undefined.
296
- *
297
- * @param value
298
- * @param message
299
- * @param code
295
+ * Asserts that a value is not null or undefined.
296
+ *
297
+ * @param value
298
+ * @param message
299
+ * @param code
300
300
  * @throws {RequestException} Throws if the value is null or undefined.
301
301
  */
302
302
  static assertFound(value, message, code = 404) {
303
303
  if (!value) throw new RequestException(message, code);
304
304
  }
305
305
  /**
306
- * Asserts that a value is not null or undefined.
307
- *
308
- * @param value
309
- * @param message
310
- * @param code
306
+ * Asserts that a value is not null or undefined.
307
+ *
308
+ * @param value
309
+ * @param message
310
+ * @param code
311
311
  * @throws {RequestException} Throws if the value is null or undefined.
312
312
  * @deprecated Use assertFound instead
313
313
  */
@@ -315,11 +315,11 @@ var RequestException = class RequestException extends AppException {
315
315
  return this.assertFound(value, message, code);
316
316
  }
317
317
  /**
318
- * Asserts that a boolean condition is true.
319
- *
320
- * @param boolean
321
- * @param message
322
- * @param code
318
+ * Asserts that a boolean condition is true.
319
+ *
320
+ * @param boolean
321
+ * @param message
322
+ * @param code
323
323
  * @throws {RequestException} Throws if the boolean condition is true.
324
324
  */
325
325
  static abortIf(boolean, message, code) {
@@ -341,9 +341,9 @@ const setModelResolver = (resolver) => {
341
341
  };
342
342
  /**
343
343
  * Checks and asserts if target is a class
344
- *
345
- * @param target
346
- * @returns
344
+ *
345
+ * @param target
346
+ * @returns
347
347
  */
348
348
  const isClass = (target) => {
349
349
  return typeof target === "function" && /^class\s/.test(Function.prototype.toString.call(target));
@@ -355,11 +355,11 @@ const normalizePositiveInteger = (value, fallback) => {
355
355
  };
356
356
  /**
357
357
  * Extracts a safe pagination limit from a query object.
358
- *
359
- * @param query
360
- * @param defaults
358
+ *
359
+ * @param query
360
+ * @param defaults
361
361
  * @default const defaults = { pageSize: 25, maxPageSize: 50 }
362
- * @returns
362
+ * @returns
363
363
  */
364
364
  const perPage = (query, defaults) => {
365
365
  const requestedPerPage = normalizePositiveInteger(query.limit ?? query.perPage ?? query["per-page"] ?? query.per_page, defaults?.perPage ?? 25);
@@ -367,11 +367,11 @@ const perPage = (query, defaults) => {
367
367
  };
368
368
  /**
369
369
  * Extracts the current page and a safe pagination limit from a query object.
370
- *
371
- * @param query
372
- * @param defaults
370
+ *
371
+ * @param query
372
+ * @param defaults
373
373
  * @default const defaults = { currentPage: 1, pageSize: 25, maxPageSize: 50 }
374
- * @returns
374
+ * @returns
375
375
  */
376
376
  const resolvePagination = (query, defaults) => {
377
377
  return {
@@ -388,7 +388,7 @@ function getModelSync(modelName) {
388
388
  }
389
389
  const initializeGlobalContext = async ({ Request, Response, Session } = {}) => {
390
390
  try {
391
- const { Request: Req, Response: Res, Session: Ses } = await import("./dist-DwGScrDq.js");
391
+ const { Request: Req, Response: Res, Session: Ses } = await import("./dist-kNVDZ1C_.js");
392
392
  Session ??= new Ses();
393
393
  Request ??= new Req();
394
394
  Response ??= new Res();
@@ -403,31 +403,31 @@ const initializeGlobalContext = async ({ Request, Response, Session } = {}) => {
403
403
  };
404
404
  /**
405
405
  * Thows to abort the current request
406
- *
407
- * @param message
408
- * @param code
406
+ *
407
+ * @param message
408
+ * @param code
409
409
  * @throws {RequestException}
410
410
  */
411
411
  const abort = (message = "Request Aborted", code = 404) => {
412
412
  RequestException.abortIf(true, message, code);
413
413
  };
414
414
  /**
415
- * Asserts that a boolean condition is true.
416
- *
417
- * @param boolean
418
- * @param message
419
- * @param code
415
+ * Asserts that a boolean condition is true.
416
+ *
417
+ * @param boolean
418
+ * @param message
419
+ * @param code
420
420
  * @throws {RequestException} Throws if the boolean condition is true.
421
421
  */
422
422
  const abortIf = (boolean, message = "Request Aborted", code = 404) => {
423
423
  RequestException.abortIf(boolean, message, code);
424
424
  };
425
425
  /**
426
- * Asserts that a value is not null or undefined.
427
- *
428
- * @param value
429
- * @param message
430
- * @param code
426
+ * Asserts that a value is not null or undefined.
427
+ *
428
+ * @param value
429
+ * @param message
430
+ * @param code
431
431
  * @throws {RequestException} Throws if the value is null or undefined.
432
432
  */
433
433
  const assertFound = (value, message, code = 404) => {
@@ -437,8 +437,8 @@ const assertFound = (value, message, code = 404) => {
437
437
  //#region src/utils/traits.ts
438
438
  /**
439
439
  * CRC32 implementation in TypeScript, adapted from https://stackoverflow.com/a/18639999
440
- * Note: This implementation is not cryptographically secure and is only used for generating
441
- * unique identifiers for traits based on their factory function's string representation.
440
+ * Note: This implementation is not cryptographically secure and is only used for generating
441
+ * unique identifiers for traits based on their factory function's string representation.
442
442
  */
443
443
  const crcTable = [];
444
444
  for (let n = 0; n < 256; n++) {
@@ -456,8 +456,8 @@ const isArkormModelInstance = (value) => typeof value === "object" && value !==
456
456
  const isTypeFactory = (fn) => typeof fn === "function" && !fn.prototype && fn.length === 0;
457
457
  /**
458
458
  * API: generate trait (technical implementation)
459
- *
460
- * @param args
459
+ *
460
+ * @param args
461
461
  */
462
462
  function trait(...args) {
463
463
  const factory = args.length === 2 ? args[1] : args[0];
@@ -471,11 +471,11 @@ function trait(...args) {
471
471
  }
472
472
  /**
473
473
  * utility function: add an additional invisible property to an object
474
- *
475
- * @param cons
476
- * @param field
477
- * @param value
478
- * @returns
474
+ *
475
+ * @param cons
476
+ * @param field
477
+ * @param value
478
+ * @returns
479
479
  */
480
480
  const extendProperties = (cons, field, value) => Object.defineProperty(cons, field, {
481
481
  value,
@@ -509,9 +509,9 @@ const registerMethodScope = (target, base, ignored) => {
509
509
  };
510
510
  /**
511
511
  * Registers conflicting trait methods
512
- *
513
- * @param classInstance
514
- * @param baseClass
512
+ *
513
+ * @param classInstance
514
+ * @param baseClass
515
515
  */
516
516
  const registerTraitMethods = (classInstance, baseClass) => {
517
517
  registerMethodScope(classInstance.prototype, baseClass.prototype, /* @__PURE__ */ new Set(["constructor"]));
@@ -527,21 +527,21 @@ const registerTraitMethods = (classInstance, baseClass) => {
527
527
  * Return every trait implementation for a method, bound to the supplied
528
528
  * instance or class. Methods are ordered from the base implementation to the
529
529
  * currently active trait implementation.
530
- *
531
- * @param target
532
- * @param name
533
- * @returns
530
+ *
531
+ * @param target
532
+ * @param name
533
+ * @returns
534
534
  */
535
535
  const getTraitMethods = (target, name) => {
536
536
  return (((typeof target === "function" ? target : Object.getPrototypeOf(target))?.[traitMethodRegistry])?.get(name) ?? []).map((method) => method.bind(target));
537
537
  };
538
538
  /**
539
539
  * Invoke every trait implementation for a method in registration order.
540
- *
541
- * @param target
542
- * @param name
543
- * @param args
544
- * @returns
540
+ *
541
+ * @param target
542
+ * @param name
543
+ * @param args
544
+ * @returns
545
545
  */
546
546
  const callTraitMethods = (target, name, ...args) => {
547
547
  const methods = getTraitMethods(target, name);
@@ -553,18 +553,18 @@ const callTraitMethods = (target, name, ...args) => {
553
553
  };
554
554
  /**
555
555
  * utility function: get raw trait
556
- *
557
- * @param x
558
- * @returns
556
+ *
557
+ * @param x
558
+ * @returns
559
559
  */
560
560
  const rawTrait = (x) => isTypeFactory(x) ? x() : x;
561
561
  /**
562
562
  * utility function: derive a trait
563
- *
564
- * @param trait$
565
- * @param baseClass
566
- * @param derived
567
- * @returns
563
+ *
564
+ * @param trait$
565
+ * @param baseClass
566
+ * @param derived
567
+ * @returns
568
568
  */
569
569
  const deriveTrait = (trait$, baseClass, derived) => {
570
570
  const trait = rawTrait(trait$);
@@ -583,9 +583,9 @@ const deriveTrait = (trait$, baseClass, derived) => {
583
583
  };
584
584
  /**
585
585
  * utility function: get reversed trait list
586
- *
587
- * @param traits
588
- * @returns
586
+ *
587
+ * @param traits
588
+ * @returns
589
589
  */
590
590
  const reverseTraitList = (traits) => traits.slice().reverse();
591
591
  function use(...args) {
@@ -625,10 +625,10 @@ function use(...args) {
625
625
  }
626
626
  /**
627
627
  * API: type guard for checking whether class instance is derived from a trait
628
- *
629
- * @param instance
630
- * @param trait
631
- * @returns
628
+ *
629
+ * @param instance
630
+ * @param trait
631
+ * @returns
632
632
  */
633
633
  function uses(instance, trait) {
634
634
  if (typeof instance !== "object" || instance === null) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/common",
3
- "version": "0.19.2",
3
+ "version": "0.19.3",
4
4
  "type": "module",
5
5
  "description": "Core utilities, primitives, and shared infrastructure for the Arkstack ecosystem.",
6
6
  "homepage": "https://arkstack.toneflix.net",
@@ -43,13 +43,13 @@
43
43
  "otpauth": "^9.5.1",
44
44
  "pino": "^10.3.1",
45
45
  "selfsigned": "^2.4.1",
46
- "@arkstack/encryption": "^0.19.2"
46
+ "@arkstack/encryption": "^0.19.3"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@h3ravel/support": "^2.2.7",
50
50
  "arkormx": "^2.12.8",
51
- "@arkstack/contract": "^0.19.2",
52
- "@arkstack/foundry": "^0.19.2"
51
+ "@arkstack/contract": "^0.19.3",
52
+ "@arkstack/foundry": "^0.19.3"
53
53
  },
54
54
  "optionalDependencies": {
55
55
  "@faker-js/faker": "^10.4.0"