@krutai/auth 0.1.2 → 0.1.4

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.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as better_auth from 'better-auth';
2
2
  import { BetterAuthOptions, betterAuth } from 'better-auth';
3
3
  export { BetterAuthOptions, betterAuth } from 'better-auth';
4
+ export { ApiKeyValidationError, createApiKeyChecker, validateApiKeyFormat, validateApiKeyWithService } from 'krutai';
4
5
 
5
6
  /**
6
7
  * Configuration options for KrutAuth
@@ -121,50 +122,10 @@ declare class KrutAuth {
121
122
  getSession(): Promise<better_auth.Auth<better_auth.BetterAuthOptions>>;
122
123
  }
123
124
 
124
- /**
125
- * API Key Validation Module
126
- *
127
- * Centralized API key validation for @krutai/auth.
128
- * This is bundled directly into @krutai/auth so no separate `krutai` package install is needed.
129
- */
130
- /**
131
- * Custom error for API key validation failures
132
- */
133
- declare class ApiKeyValidationError extends Error {
134
- constructor(message: string);
135
- }
136
- /**
137
- * Validates the format of an API key
138
- * @param apiKey - The API key to validate
139
- * @throws {ApiKeyValidationError} If the API key format is invalid
140
- */
141
- declare function validateApiKeyFormat(apiKey: string): void;
142
- /**
143
- * Validates an API key with the KrutAI service
144
- * @param apiKey - The API key to validate
145
- * @returns Promise that resolves to true if valid, false otherwise
146
- */
147
- declare function validateApiKeyWithService(apiKey: string): Promise<boolean>;
148
- /**
149
- * Creates a validated API key checker function
150
- * @param apiKey - The API key to validate
151
- * @returns A function that checks if the API key is valid
152
- */
153
- declare function createApiKeyChecker(apiKey: string): {
154
- /**
155
- * Validates the API key (cached after first call)
156
- */
157
- validate(): Promise<boolean>;
158
- /**
159
- * Resets the validation cache
160
- */
161
- reset(): void;
162
- };
163
-
164
125
  /**
165
126
  * @krutai/auth - Authentication package for KrutAI
166
127
  *
167
- * Everything is bundled no need to separately install `krutai` or `better-auth`.
128
+ * Requires `krutai` as a peer dependency (installed automatically).
168
129
  *
169
130
  * @example Server-side (Next.js API route / server component)
170
131
  * ```typescript
@@ -189,4 +150,4 @@ declare function createApiKeyChecker(apiKey: string): {
189
150
 
190
151
  declare const VERSION = "0.1.2";
191
152
 
192
- export { ApiKeyValidationError, type AuthSession, KrutAuth, type KrutAuthConfig, VERSION, createApiKeyChecker, validateApiKeyFormat, validateApiKeyWithService };
153
+ export { type AuthSession, KrutAuth, type KrutAuthConfig, VERSION };
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var krutai = require('krutai');
4
+
3
5
  var __defProp = Object.defineProperty;
4
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
7
  var __esm = (fn, res) => function __init() {
@@ -51491,64 +51493,6 @@ var betterAuth = (options) => {
51491
51493
  init_env();
51492
51494
  init_error();
51493
51495
  init_utils();
51494
-
51495
- // src/validator.ts
51496
- var ApiKeyValidationError = class extends Error {
51497
- constructor(message2) {
51498
- super(message2);
51499
- this.name = "ApiKeyValidationError";
51500
- }
51501
- };
51502
- function validateApiKeyFormat(apiKey) {
51503
- if (!apiKey || typeof apiKey !== "string") {
51504
- throw new ApiKeyValidationError("API key must be a non-empty string");
51505
- }
51506
- if (apiKey.trim().length === 0) {
51507
- throw new ApiKeyValidationError("API key cannot be empty or whitespace");
51508
- }
51509
- if (apiKey.length < 10) {
51510
- throw new ApiKeyValidationError("API key must be at least 10 characters long");
51511
- }
51512
- }
51513
- async function validateApiKeyWithService(apiKey) {
51514
- validateApiKeyFormat(apiKey);
51515
- try {
51516
- return true;
51517
- } catch (error49) {
51518
- throw new ApiKeyValidationError(
51519
- `Failed to validate API key: ${error49 instanceof Error ? error49.message : "Unknown error"}`
51520
- );
51521
- }
51522
- }
51523
- function createApiKeyChecker(apiKey) {
51524
- let isValid = null;
51525
- let validationPromise = null;
51526
- return {
51527
- /**
51528
- * Validates the API key (cached after first call)
51529
- */
51530
- async validate() {
51531
- if (isValid !== null) {
51532
- return isValid;
51533
- }
51534
- if (validationPromise) {
51535
- return validationPromise;
51536
- }
51537
- validationPromise = validateApiKeyWithService(apiKey);
51538
- isValid = await validationPromise;
51539
- return isValid;
51540
- },
51541
- /**
51542
- * Resets the validation cache
51543
- */
51544
- reset() {
51545
- isValid = null;
51546
- validationPromise = null;
51547
- }
51548
- };
51549
- }
51550
-
51551
- // src/client.ts
51552
51496
  var KrutAuth = class {
51553
51497
  /**
51554
51498
  * Creates a new KrutAuth instance
@@ -51557,7 +51501,7 @@ var KrutAuth = class {
51557
51501
  */
51558
51502
  constructor(config3) {
51559
51503
  this.config = config3;
51560
- validateApiKeyFormat(config3.apiKey);
51504
+ krutai.validateApiKeyFormat(config3.apiKey);
51561
51505
  this.apiKey = config3.apiKey;
51562
51506
  if (config3.validateOnInit === false) {
51563
51507
  this.initializeBetterAuth();
@@ -51576,7 +51520,7 @@ var KrutAuth = class {
51576
51520
  return;
51577
51521
  }
51578
51522
  if (this.config.validateOnInit !== false) {
51579
- await validateApiKeyWithService(this.apiKey);
51523
+ await krutai.validateApiKeyWithService(this.apiKey);
51580
51524
  }
51581
51525
  this.initializeBetterAuth();
51582
51526
  this.initialized = true;
@@ -51641,8 +51585,6 @@ var KrutAuth = class {
51641
51585
  return auth;
51642
51586
  }
51643
51587
  };
51644
-
51645
- // src/index.ts
51646
51588
  var VERSION = "0.1.2";
51647
51589
  /*! Bundled license information:
51648
51590
 
@@ -51653,12 +51595,24 @@ var VERSION = "0.1.2";
51653
51595
  (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
51654
51596
  */
51655
51597
 
51656
- exports.ApiKeyValidationError = ApiKeyValidationError;
51598
+ Object.defineProperty(exports, "ApiKeyValidationError", {
51599
+ enumerable: true,
51600
+ get: function () { return krutai.ApiKeyValidationError; }
51601
+ });
51602
+ Object.defineProperty(exports, "createApiKeyChecker", {
51603
+ enumerable: true,
51604
+ get: function () { return krutai.createApiKeyChecker; }
51605
+ });
51606
+ Object.defineProperty(exports, "validateApiKeyFormat", {
51607
+ enumerable: true,
51608
+ get: function () { return krutai.validateApiKeyFormat; }
51609
+ });
51610
+ Object.defineProperty(exports, "validateApiKeyWithService", {
51611
+ enumerable: true,
51612
+ get: function () { return krutai.validateApiKeyWithService; }
51613
+ });
51657
51614
  exports.KrutAuth = KrutAuth;
51658
51615
  exports.VERSION = VERSION;
51659
51616
  exports.betterAuth = betterAuth;
51660
- exports.createApiKeyChecker = createApiKeyChecker;
51661
- exports.validateApiKeyFormat = validateApiKeyFormat;
51662
- exports.validateApiKeyWithService = validateApiKeyWithService;
51663
51617
  //# sourceMappingURL=index.js.map
51664
51618
  //# sourceMappingURL=index.js.map