@ericsanchezok/synergy-util 3.0.1 → 3.0.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.
@@ -9,6 +9,8 @@ export interface RuntimeLimits {
9
9
  taskRunTimeoutMs: number;
10
10
  shutdownGraceMs: number;
11
11
  heartbeatIntervalMs: number;
12
+ maxMemoryMb: number;
13
+ memorySampleIntervalMs: number;
12
14
  }
13
15
  export type RuntimeLimitOverrides = Partial<RuntimeLimits>;
14
16
  export interface PluginRuntimePolicyInput {
@@ -6,6 +6,8 @@ export const DEFAULT_PLUGIN_RUNTIME_LIMITS = {
6
6
  taskRunTimeoutMs: 120_000,
7
7
  shutdownGraceMs: 1_500,
8
8
  heartbeatIntervalMs: 5_000,
9
+ maxMemoryMb: 512,
10
+ memorySampleIntervalMs: 5_000,
9
11
  };
10
12
  export function resolveRuntimeMode(input) {
11
13
  return input.source === "builtin" ? "inProcess" : "process";
package/dist/uuid.d.ts CHANGED
@@ -7,4 +7,10 @@ export interface UUIDEnvironment {
7
7
  now?: () => number;
8
8
  random?: () => number;
9
9
  }
10
+ export declare class SecureRandomUnavailableError extends Error {
11
+ constructor();
12
+ }
13
+ export declare function generateRandomBytes(length: number, environment?: UUIDEnvironment): Uint8Array;
14
+ export declare function generateSecureRandomBytes(length: number, environment?: UUIDEnvironment): Uint8Array;
15
+ export declare function generateSecureUUID(environment?: UUIDEnvironment): string;
10
16
  export declare function generateUUID(environment?: UUIDEnvironment): string;
package/dist/uuid.js CHANGED
@@ -1,3 +1,46 @@
1
+ export class SecureRandomUnavailableError extends Error {
2
+ constructor() {
3
+ super("Secure randomness requires a usable Web Crypto implementation");
4
+ this.name = "SecureRandomUnavailableError";
5
+ }
6
+ }
7
+ export function generateRandomBytes(length, environment) {
8
+ const bytes = new Uint8Array(length);
9
+ const webCrypto = environment ? environment.crypto : globalThis.crypto;
10
+ try {
11
+ if (typeof webCrypto?.getRandomValues === "function")
12
+ return webCrypto.getRandomValues(bytes);
13
+ }
14
+ catch {
15
+ // Ordinary identifiers may use the weak fallback when Web Crypto is unavailable.
16
+ }
17
+ const random = environment?.random ?? Math.random;
18
+ for (let index = 0; index < bytes.length; index++)
19
+ bytes[index] = Math.floor(random() * 256);
20
+ return bytes;
21
+ }
22
+ export function generateSecureRandomBytes(length, environment) {
23
+ const webCrypto = environment ? environment.crypto : globalThis.crypto;
24
+ if (typeof webCrypto?.getRandomValues !== "function")
25
+ throw new SecureRandomUnavailableError();
26
+ try {
27
+ return webCrypto.getRandomValues(new Uint8Array(length));
28
+ }
29
+ catch {
30
+ throw new SecureRandomUnavailableError();
31
+ }
32
+ }
33
+ export function generateSecureUUID(environment) {
34
+ const webCrypto = environment ? environment.crypto : globalThis.crypto;
35
+ try {
36
+ if (typeof webCrypto?.randomUUID === "function")
37
+ return webCrypto.randomUUID();
38
+ }
39
+ catch {
40
+ // Fall through to strict getRandomValues without a weak fallback.
41
+ }
42
+ return formatUUID(generateSecureRandomBytes(16, environment));
43
+ }
1
44
  let fallbackCounter = 0;
2
45
  export function generateUUID(environment) {
3
46
  const webCrypto = environment ? environment.crypto : globalThis.crypto;
@@ -9,12 +52,8 @@ export function generateUUID(environment) {
9
52
  // randomUUID may be exposed but blocked outside a secure context.
10
53
  }
11
54
  try {
12
- if (typeof webCrypto?.getRandomValues === "function") {
13
- const bytes = webCrypto.getRandomValues(new Uint8Array(16));
14
- bytes[6] = (bytes[6] & 0x0f) | 0x40;
15
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
16
- return formatUUID(bytes);
17
- }
55
+ if (typeof webCrypto?.getRandomValues === "function")
56
+ return formatUUID(generateSecureRandomBytes(16, environment));
18
57
  }
19
58
  catch {
20
59
  // Fall through for runtimes without a usable Web Crypto implementation.
@@ -25,6 +64,8 @@ export function generateUUID(environment) {
25
64
  return `${now.toString(36)}-${fallbackCounter.toString(36)}-${random.toString(36).slice(2)}`;
26
65
  }
27
66
  function formatUUID(bytes) {
67
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
68
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
28
69
  const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
29
70
  return [hex.slice(0, 8), hex.slice(8, 12), hex.slice(12, 16), hex.slice(16, 20), hex.slice(20)].join("-");
30
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ericsanchezok/synergy-util",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "exports": {