@ppabari/strio 1.0.2 → 1.1.0

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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RandomStringOptions, E as EntropyResult, V as ValidateOptions, c as ValidationResult } from './zod-CINbFpp9.cjs';
2
- export { a as RandomStringResult, b as RandomStringSchemaOptions, S as StartWith, r as randomStringSchema } from './zod-CINbFpp9.cjs';
1
+ import { R as RandomStringOptions, E as EntropyResult, V as ValidateOptions, a as ValidationResult } from './zod-IWq12GIY.cjs';
2
+ export { b as RandomStringResult, c as RandomStringSchemaOptions, S as StartWith, r as randomStringSchema } from './zod-IWq12GIY.cjs';
3
3
 
4
4
  /**
5
5
  * short-id.ts
@@ -347,6 +347,54 @@ declare function estimateEntropy(options?: RandomStringOptions): EntropyResult;
347
347
  */
348
348
  declare function validateRandomString(str: string, options?: ValidateOptions): ValidationResult;
349
349
 
350
+ /**
351
+ * compat.ts
352
+ * Runtime environment & version compatibility checks.
353
+ *
354
+ * `@ppabari/strio` depends on the Web Crypto API (`crypto.getRandomValues`),
355
+ * which is available natively in Node >=18, all modern browsers, Deno, Bun,
356
+ * and edge runtimes. These helpers let applications verify — at startup or in
357
+ * a health check — that the current runtime can support secure generation,
358
+ * and surface a clear message when it cannot.
359
+ */
360
+ /** The minimum Node.js major version supported by this package. */
361
+ declare const MIN_NODE_VERSION = 18;
362
+ type Runtime = 'node' | 'deno' | 'bun' | 'browser' | 'workerd' | 'unknown';
363
+ interface CompatibilityResult {
364
+ /** `true` when the runtime can support secure string generation. */
365
+ ok: boolean;
366
+ /** Whether `crypto.getRandomValues` is available. */
367
+ cryptoAvailable: boolean;
368
+ /** Best-effort detected runtime. */
369
+ runtime: Runtime;
370
+ /** Node.js version string (e.g. `'20.11.0'`), when running on Node. */
371
+ nodeVersion?: string;
372
+ /** Human-readable warnings; empty when fully compatible. */
373
+ warnings: string[];
374
+ }
375
+ /**
376
+ * Inspect the current runtime and report whether `@ppabari/strio` can perform
377
+ * secure string generation. Never throws.
378
+ *
379
+ * @example
380
+ * import { checkCompatibility } from '@ppabari/strio';
381
+ *
382
+ * const report = checkCompatibility();
383
+ * if (!report.ok) console.warn(report.warnings.join('\n'));
384
+ */
385
+ declare function checkCompatibility(): CompatibilityResult;
386
+ /**
387
+ * Assert that the current runtime is compatible, throwing a descriptive error
388
+ * otherwise. Call this at startup to fail fast instead of at first use.
389
+ *
390
+ * @throws {Error} when the runtime cannot support secure generation.
391
+ *
392
+ * @example
393
+ * import { assertCompatible } from '@ppabari/strio';
394
+ * assertCompatible(); // throws on an unsupported runtime
395
+ */
396
+ declare function assertCompatible(): void;
397
+
350
398
  /**
351
399
  * charset-aliases.ts
352
400
  * Named character set aliases for common encoding schemes.
@@ -882,4 +930,4 @@ declare function generateRandomString(options: RandomStringOptions & {
882
930
  }): string[];
883
931
  declare function generateRandomStringAsync(options?: RandomStringOptions): Promise<string | string[]>;
884
932
 
885
- export { type ApiKeyOptions, type ApiKeyResult, WORD_LIST as BUILT_IN_WORD_LIST, type Base64Variant, CHARSET_ALIASES, type CharsetAlias, EntropyResult, type ExpiringTokenOptions, type ExpiringTokenResult, type JwtAlgorithm, type JwtSecretFormat, type JwtSecretOptions, type JwtSecretResult, type MaskSecretOptions, type OtpOptions, type OtpResult, PRESETS, type PassphraseOptions, type PassphraseResult, type PresetName, RandomStringOptions, type ShortIdOptions, type ShortIdValidateOptions, type ShortIdValidateResult, type TokenVerifyResult, ValidateOptions, ValidationResult, estimateEntropy, generateAesKey, generateApiKey, generateBase64Key, generateBytes, generateCookieSecret, generateDjangoSecretKey, generateExpiringToken, generateHexKey, generateId, generateJwtSecret, generateNextAuthSecret, generateOtp, generatePassphrase, generateRailsSecretKeyBase, generateRandomString, generateRandomStringAsync, maskSecret, randomStringStream, resolveCharsetAlias, take, takeWhere, timingSafeEqual, uniqueRandomStringStream, validateId, validateRandomString, verifyToken };
933
+ export { type ApiKeyOptions, type ApiKeyResult, WORD_LIST as BUILT_IN_WORD_LIST, type Base64Variant, CHARSET_ALIASES, type CharsetAlias, type CompatibilityResult, EntropyResult, type ExpiringTokenOptions, type ExpiringTokenResult, type JwtAlgorithm, type JwtSecretFormat, type JwtSecretOptions, type JwtSecretResult, MIN_NODE_VERSION, type MaskSecretOptions, type OtpOptions, type OtpResult, PRESETS, type PassphraseOptions, type PassphraseResult, type PresetName, RandomStringOptions, type Runtime, type ShortIdOptions, type ShortIdValidateOptions, type ShortIdValidateResult, type TokenVerifyResult, ValidateOptions, ValidationResult, assertCompatible, checkCompatibility, estimateEntropy, generateAesKey, generateApiKey, generateBase64Key, generateBytes, generateCookieSecret, generateDjangoSecretKey, generateExpiringToken, generateHexKey, generateId, generateJwtSecret, generateNextAuthSecret, generateOtp, generatePassphrase, generateRailsSecretKeyBase, generateRandomString, generateRandomStringAsync, maskSecret, randomStringStream, resolveCharsetAlias, take, takeWhere, timingSafeEqual, uniqueRandomStringStream, validateId, validateRandomString, verifyToken };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RandomStringOptions, E as EntropyResult, V as ValidateOptions, c as ValidationResult } from './zod-CINbFpp9.js';
2
- export { a as RandomStringResult, b as RandomStringSchemaOptions, S as StartWith, r as randomStringSchema } from './zod-CINbFpp9.js';
1
+ import { R as RandomStringOptions, E as EntropyResult, V as ValidateOptions, a as ValidationResult } from './zod-IWq12GIY.js';
2
+ export { b as RandomStringResult, c as RandomStringSchemaOptions, S as StartWith, r as randomStringSchema } from './zod-IWq12GIY.js';
3
3
 
4
4
  /**
5
5
  * short-id.ts
@@ -347,6 +347,54 @@ declare function estimateEntropy(options?: RandomStringOptions): EntropyResult;
347
347
  */
348
348
  declare function validateRandomString(str: string, options?: ValidateOptions): ValidationResult;
349
349
 
350
+ /**
351
+ * compat.ts
352
+ * Runtime environment & version compatibility checks.
353
+ *
354
+ * `@ppabari/strio` depends on the Web Crypto API (`crypto.getRandomValues`),
355
+ * which is available natively in Node >=18, all modern browsers, Deno, Bun,
356
+ * and edge runtimes. These helpers let applications verify — at startup or in
357
+ * a health check — that the current runtime can support secure generation,
358
+ * and surface a clear message when it cannot.
359
+ */
360
+ /** The minimum Node.js major version supported by this package. */
361
+ declare const MIN_NODE_VERSION = 18;
362
+ type Runtime = 'node' | 'deno' | 'bun' | 'browser' | 'workerd' | 'unknown';
363
+ interface CompatibilityResult {
364
+ /** `true` when the runtime can support secure string generation. */
365
+ ok: boolean;
366
+ /** Whether `crypto.getRandomValues` is available. */
367
+ cryptoAvailable: boolean;
368
+ /** Best-effort detected runtime. */
369
+ runtime: Runtime;
370
+ /** Node.js version string (e.g. `'20.11.0'`), when running on Node. */
371
+ nodeVersion?: string;
372
+ /** Human-readable warnings; empty when fully compatible. */
373
+ warnings: string[];
374
+ }
375
+ /**
376
+ * Inspect the current runtime and report whether `@ppabari/strio` can perform
377
+ * secure string generation. Never throws.
378
+ *
379
+ * @example
380
+ * import { checkCompatibility } from '@ppabari/strio';
381
+ *
382
+ * const report = checkCompatibility();
383
+ * if (!report.ok) console.warn(report.warnings.join('\n'));
384
+ */
385
+ declare function checkCompatibility(): CompatibilityResult;
386
+ /**
387
+ * Assert that the current runtime is compatible, throwing a descriptive error
388
+ * otherwise. Call this at startup to fail fast instead of at first use.
389
+ *
390
+ * @throws {Error} when the runtime cannot support secure generation.
391
+ *
392
+ * @example
393
+ * import { assertCompatible } from '@ppabari/strio';
394
+ * assertCompatible(); // throws on an unsupported runtime
395
+ */
396
+ declare function assertCompatible(): void;
397
+
350
398
  /**
351
399
  * charset-aliases.ts
352
400
  * Named character set aliases for common encoding schemes.
@@ -882,4 +930,4 @@ declare function generateRandomString(options: RandomStringOptions & {
882
930
  }): string[];
883
931
  declare function generateRandomStringAsync(options?: RandomStringOptions): Promise<string | string[]>;
884
932
 
885
- export { type ApiKeyOptions, type ApiKeyResult, WORD_LIST as BUILT_IN_WORD_LIST, type Base64Variant, CHARSET_ALIASES, type CharsetAlias, EntropyResult, type ExpiringTokenOptions, type ExpiringTokenResult, type JwtAlgorithm, type JwtSecretFormat, type JwtSecretOptions, type JwtSecretResult, type MaskSecretOptions, type OtpOptions, type OtpResult, PRESETS, type PassphraseOptions, type PassphraseResult, type PresetName, RandomStringOptions, type ShortIdOptions, type ShortIdValidateOptions, type ShortIdValidateResult, type TokenVerifyResult, ValidateOptions, ValidationResult, estimateEntropy, generateAesKey, generateApiKey, generateBase64Key, generateBytes, generateCookieSecret, generateDjangoSecretKey, generateExpiringToken, generateHexKey, generateId, generateJwtSecret, generateNextAuthSecret, generateOtp, generatePassphrase, generateRailsSecretKeyBase, generateRandomString, generateRandomStringAsync, maskSecret, randomStringStream, resolveCharsetAlias, take, takeWhere, timingSafeEqual, uniqueRandomStringStream, validateId, validateRandomString, verifyToken };
933
+ export { type ApiKeyOptions, type ApiKeyResult, WORD_LIST as BUILT_IN_WORD_LIST, type Base64Variant, CHARSET_ALIASES, type CharsetAlias, type CompatibilityResult, EntropyResult, type ExpiringTokenOptions, type ExpiringTokenResult, type JwtAlgorithm, type JwtSecretFormat, type JwtSecretOptions, type JwtSecretResult, MIN_NODE_VERSION, type MaskSecretOptions, type OtpOptions, type OtpResult, PRESETS, type PassphraseOptions, type PassphraseResult, type PresetName, RandomStringOptions, type Runtime, type ShortIdOptions, type ShortIdValidateOptions, type ShortIdValidateResult, type TokenVerifyResult, ValidateOptions, ValidationResult, assertCompatible, checkCompatibility, estimateEntropy, generateAesKey, generateApiKey, generateBase64Key, generateBytes, generateCookieSecret, generateDjangoSecretKey, generateExpiringToken, generateHexKey, generateId, generateJwtSecret, generateNextAuthSecret, generateOtp, generatePassphrase, generateRailsSecretKeyBase, generateRandomString, generateRandomStringAsync, maskSecret, randomStringStream, resolveCharsetAlias, take, takeWhere, timingSafeEqual, uniqueRandomStringStream, validateId, validateRandomString, verifyToken };
package/dist/index.js CHANGED
@@ -1429,6 +1429,54 @@ function validatePattern(str, pattern) {
1429
1429
  return errors;
1430
1430
  }
1431
1431
 
1432
+ // src/compat.ts
1433
+ var MIN_NODE_VERSION = 18;
1434
+ function detectRuntime() {
1435
+ const g = globalThis;
1436
+ if (typeof g.Deno !== "undefined") return { runtime: "deno" };
1437
+ if (typeof g.Bun !== "undefined") return { runtime: "bun" };
1438
+ if (typeof g.process !== "undefined" && g.process?.versions?.node) {
1439
+ return { runtime: "node", nodeVersion: String(g.process.versions.node) };
1440
+ }
1441
+ if (typeof g.WebSocketPair !== "undefined") return { runtime: "workerd" };
1442
+ if (typeof g.window !== "undefined" || typeof g.document !== "undefined") {
1443
+ return { runtime: "browser" };
1444
+ }
1445
+ return { runtime: "unknown" };
1446
+ }
1447
+ function checkCompatibility() {
1448
+ const warnings = [];
1449
+ const { runtime, nodeVersion } = detectRuntime();
1450
+ const cryptoAvailable = typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.getRandomValues === "function";
1451
+ if (!cryptoAvailable) {
1452
+ warnings.push(
1453
+ "Web Crypto API (crypto.getRandomValues) is unavailable. Secure generation will fail. On Node.js, upgrade to v18 or newer."
1454
+ );
1455
+ }
1456
+ if (runtime === "node" && nodeVersion) {
1457
+ const major = parseInt(nodeVersion.split(".")[0] ?? "0", 10);
1458
+ if (major < MIN_NODE_VERSION) {
1459
+ warnings.push(
1460
+ `Node.js ${nodeVersion} is below the supported minimum (v${MIN_NODE_VERSION}). Please upgrade.`
1461
+ );
1462
+ }
1463
+ }
1464
+ return {
1465
+ ok: cryptoAvailable && warnings.length === 0,
1466
+ cryptoAvailable,
1467
+ runtime,
1468
+ ...nodeVersion ? { nodeVersion } : {},
1469
+ warnings
1470
+ };
1471
+ }
1472
+ function assertCompatible() {
1473
+ const report = checkCompatibility();
1474
+ if (!report.ok) {
1475
+ throw new Error(`@ppabari/strio: incompatible runtime.
1476
+ - ${report.warnings.join("\n- ")}`);
1477
+ }
1478
+ }
1479
+
1432
1480
  // src/presets.ts
1433
1481
  var PRESETS = {
1434
1482
  /**
@@ -1876,6 +1924,6 @@ async function generateRandomStringAsync(options = {}) {
1876
1924
  return generateBatch(rest, count);
1877
1925
  }
1878
1926
 
1879
- export { WORD_LIST as BUILT_IN_WORD_LIST, CHARSET_ALIASES, PRESETS, estimateEntropy, generateAesKey, generateApiKey, generateBase64Key, generateBytes, generateCookieSecret, generateDjangoSecretKey, generateExpiringToken, generateHexKey, generateId, generateJwtSecret, generateNextAuthSecret, generateOtp, generatePassphrase, generateRailsSecretKeyBase, generateRandomString, generateRandomStringAsync, maskSecret, randomStringSchema, randomStringStream, resolveCharsetAlias, take, takeWhere, timingSafeEqual, uniqueRandomStringStream, validateId, validateRandomString, verifyToken };
1927
+ export { WORD_LIST as BUILT_IN_WORD_LIST, CHARSET_ALIASES, MIN_NODE_VERSION, PRESETS, assertCompatible, checkCompatibility, estimateEntropy, generateAesKey, generateApiKey, generateBase64Key, generateBytes, generateCookieSecret, generateDjangoSecretKey, generateExpiringToken, generateHexKey, generateId, generateJwtSecret, generateNextAuthSecret, generateOtp, generatePassphrase, generateRailsSecretKeyBase, generateRandomString, generateRandomStringAsync, maskSecret, randomStringSchema, randomStringStream, resolveCharsetAlias, take, takeWhere, timingSafeEqual, uniqueRandomStringStream, validateId, validateRandomString, verifyToken };
1880
1928
  //# sourceMappingURL=index.js.map
1881
1929
  //# sourceMappingURL=index.js.map