@krutai/auth 0.1.0 → 0.1.2
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/README.md +30 -2
- package/dist/index.d.mts +50 -13
- package/dist/index.d.ts +50 -13
- package/dist/index.js +51548 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51546 -25
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +1 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.js +1648 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +1645 -0
- package/dist/react.mjs.map +1 -0
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @krutai/auth
|
|
2
2
|
|
|
3
|
-
Authentication package for KrutAI powered by [
|
|
3
|
+
Authentication package for KrutAI powered by [Krut AI](https://www.krut.ai/).
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
@@ -16,6 +16,8 @@ Authentication package for KrutAI powered by [Better Auth](https://www.better-au
|
|
|
16
16
|
npm install @krutai/auth
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
> **Note:** Installing `@krutai/auth` automatically installs the parent `krutai` package, which provides centralized API key validation for all KrutAI packages.
|
|
20
|
+
|
|
19
21
|
## Quick Start
|
|
20
22
|
|
|
21
23
|
### Basic Usage
|
|
@@ -127,9 +129,35 @@ const apiKey = auth.getApiKey();
|
|
|
127
129
|
|
|
128
130
|
**Returns:** `string`
|
|
129
131
|
|
|
132
|
+
## Architecture
|
|
133
|
+
|
|
134
|
+
### Dependency on Parent Package
|
|
135
|
+
|
|
136
|
+
`@krutai/auth` depends on the parent `krutai` package for API key validation:
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
@krutai/auth
|
|
140
|
+
└── krutai (parent)
|
|
141
|
+
└── Provides: validateApiKeyFormat, validateApiKeyWithService, etc.
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**Benefits:**
|
|
145
|
+
- ✅ All `@krutai/*` packages use the same validation logic from `krutai`
|
|
146
|
+
- ✅ No code duplication across packages
|
|
147
|
+
- ✅ Consistent API key handling
|
|
148
|
+
- ✅ Centralized validation updates benefit all packages
|
|
149
|
+
|
|
150
|
+
You can also use the validation utilities directly:
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { validateApiKeyFormat, ApiKeyValidationError } from '@krutai/auth';
|
|
154
|
+
// or
|
|
155
|
+
import { validateApiKeyFormat, ApiKeyValidationError } from 'krutai';
|
|
156
|
+
```
|
|
157
|
+
|
|
130
158
|
## Error Handling
|
|
131
159
|
|
|
132
|
-
The package throws `ApiKeyValidationError` when:
|
|
160
|
+
The package throws `ApiKeyValidationError` (from parent `krutai` package) when:
|
|
133
161
|
|
|
134
162
|
- API key is not provided
|
|
135
163
|
- API key is empty or invalid format
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as better_auth from 'better-auth';
|
|
2
2
|
import { BetterAuthOptions, betterAuth } from 'better-auth';
|
|
3
|
-
export { BetterAuthOptions } from 'better-auth';
|
|
3
|
+
export { BetterAuthOptions, betterAuth } from 'better-auth';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Configuration options for KrutAuth
|
|
@@ -122,7 +122,13 @@ declare class KrutAuth {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
|
-
*
|
|
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
|
|
126
132
|
*/
|
|
127
133
|
declare class ApiKeyValidationError extends Error {
|
|
128
134
|
constructor(message: string);
|
|
@@ -130,26 +136,57 @@ declare class ApiKeyValidationError extends Error {
|
|
|
130
136
|
/**
|
|
131
137
|
* Validates the format of an API key
|
|
132
138
|
* @param apiKey - The API key to validate
|
|
133
|
-
* @throws {ApiKeyValidationError} If the API key is invalid
|
|
139
|
+
* @throws {ApiKeyValidationError} If the API key format is invalid
|
|
134
140
|
*/
|
|
135
|
-
declare function validateApiKeyFormat(apiKey: string
|
|
141
|
+
declare function validateApiKeyFormat(apiKey: string): void;
|
|
136
142
|
/**
|
|
137
|
-
* Validates an API key
|
|
138
|
-
*
|
|
139
|
-
* @
|
|
140
|
-
* @returns Promise that resolves if valid, rejects if invalid
|
|
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
|
|
141
146
|
*/
|
|
142
|
-
declare function validateApiKeyWithService(
|
|
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
|
+
};
|
|
143
163
|
|
|
144
164
|
/**
|
|
145
165
|
* @krutai/auth - Authentication package for KrutAI
|
|
146
166
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
167
|
+
* Everything is bundled — no need to separately install `krutai` or `better-auth`.
|
|
168
|
+
*
|
|
169
|
+
* @example Server-side (Next.js API route / server component)
|
|
170
|
+
* ```typescript
|
|
171
|
+
* import { betterAuth } from "@krutai/auth";
|
|
172
|
+
*
|
|
173
|
+
* export const auth = betterAuth({ ... });
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @example Client-side (React / Next.js client component)
|
|
177
|
+
* ```typescript
|
|
178
|
+
* import { createAuthClient } from "@krutai/auth/react";
|
|
179
|
+
*
|
|
180
|
+
* export const authClient = createAuthClient({
|
|
181
|
+
* baseURL: process.env.NEXT_PUBLIC_APP_URL ?? "http://localhost:3000",
|
|
182
|
+
* });
|
|
183
|
+
*
|
|
184
|
+
* export const { signIn, signUp, signOut, useSession } = authClient;
|
|
185
|
+
* ```
|
|
149
186
|
*
|
|
150
187
|
* @packageDocumentation
|
|
151
188
|
*/
|
|
152
189
|
|
|
153
|
-
declare const VERSION = "0.1.
|
|
190
|
+
declare const VERSION = "0.1.2";
|
|
154
191
|
|
|
155
|
-
export { ApiKeyValidationError, type AuthSession, KrutAuth, type KrutAuthConfig, VERSION, validateApiKeyFormat, validateApiKeyWithService };
|
|
192
|
+
export { ApiKeyValidationError, type AuthSession, KrutAuth, type KrutAuthConfig, VERSION, createApiKeyChecker, validateApiKeyFormat, validateApiKeyWithService };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as better_auth from 'better-auth';
|
|
2
2
|
import { BetterAuthOptions, betterAuth } from 'better-auth';
|
|
3
|
-
export { BetterAuthOptions } from 'better-auth';
|
|
3
|
+
export { BetterAuthOptions, betterAuth } from 'better-auth';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Configuration options for KrutAuth
|
|
@@ -122,7 +122,13 @@ declare class KrutAuth {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
|
-
*
|
|
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
|
|
126
132
|
*/
|
|
127
133
|
declare class ApiKeyValidationError extends Error {
|
|
128
134
|
constructor(message: string);
|
|
@@ -130,26 +136,57 @@ declare class ApiKeyValidationError extends Error {
|
|
|
130
136
|
/**
|
|
131
137
|
* Validates the format of an API key
|
|
132
138
|
* @param apiKey - The API key to validate
|
|
133
|
-
* @throws {ApiKeyValidationError} If the API key is invalid
|
|
139
|
+
* @throws {ApiKeyValidationError} If the API key format is invalid
|
|
134
140
|
*/
|
|
135
|
-
declare function validateApiKeyFormat(apiKey: string
|
|
141
|
+
declare function validateApiKeyFormat(apiKey: string): void;
|
|
136
142
|
/**
|
|
137
|
-
* Validates an API key
|
|
138
|
-
*
|
|
139
|
-
* @
|
|
140
|
-
* @returns Promise that resolves if valid, rejects if invalid
|
|
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
|
|
141
146
|
*/
|
|
142
|
-
declare function validateApiKeyWithService(
|
|
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
|
+
};
|
|
143
163
|
|
|
144
164
|
/**
|
|
145
165
|
* @krutai/auth - Authentication package for KrutAI
|
|
146
166
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
167
|
+
* Everything is bundled — no need to separately install `krutai` or `better-auth`.
|
|
168
|
+
*
|
|
169
|
+
* @example Server-side (Next.js API route / server component)
|
|
170
|
+
* ```typescript
|
|
171
|
+
* import { betterAuth } from "@krutai/auth";
|
|
172
|
+
*
|
|
173
|
+
* export const auth = betterAuth({ ... });
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @example Client-side (React / Next.js client component)
|
|
177
|
+
* ```typescript
|
|
178
|
+
* import { createAuthClient } from "@krutai/auth/react";
|
|
179
|
+
*
|
|
180
|
+
* export const authClient = createAuthClient({
|
|
181
|
+
* baseURL: process.env.NEXT_PUBLIC_APP_URL ?? "http://localhost:3000",
|
|
182
|
+
* });
|
|
183
|
+
*
|
|
184
|
+
* export const { signIn, signUp, signOut, useSession } = authClient;
|
|
185
|
+
* ```
|
|
149
186
|
*
|
|
150
187
|
* @packageDocumentation
|
|
151
188
|
*/
|
|
152
189
|
|
|
153
|
-
declare const VERSION = "0.1.
|
|
190
|
+
declare const VERSION = "0.1.2";
|
|
154
191
|
|
|
155
|
-
export { ApiKeyValidationError, type AuthSession, KrutAuth, type KrutAuthConfig, VERSION, validateApiKeyFormat, validateApiKeyWithService };
|
|
192
|
+
export { ApiKeyValidationError, type AuthSession, KrutAuth, type KrutAuthConfig, VERSION, createApiKeyChecker, validateApiKeyFormat, validateApiKeyWithService };
|