@inai-dev/shared 1.0.0 → 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.
Files changed (2) hide show
  1. package/README.md +70 -13
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @inai-dev/shared
2
2
 
3
- Shared utilities for the InAI Auth SDK. Includes validators, error classes, JWT helpers, URL utilities, and constants.
3
+ Shared utilities for the InAI Auth SDK. Includes error class, JWT helpers, validators, URL utilities, and constants.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,25 +10,82 @@ npm install @inai-dev/shared
10
10
 
11
11
  > **Note:** You typically don't need to install this directly. It's included as a dependency of higher-level packages.
12
12
 
13
- ## Usage
13
+ ## Exports
14
+
15
+ ### Error Class
14
16
 
15
17
  ```ts
16
- import { InAIError, isInAIError } from "@inai-dev/shared";
17
- import { validateEmail, validatePassword } from "@inai-dev/shared";
18
- import { AUTH_COOKIE_NAME, REFRESH_COOKIE_NAME } from "@inai-dev/shared";
18
+ import { InAIAuthError } from "@inai-dev/shared";
19
+
20
+ try {
21
+ // ...
22
+ } catch (err) {
23
+ if (err instanceof InAIAuthError) {
24
+ console.error(err.status, err.message, err.body);
25
+ }
26
+ }
19
27
  ```
20
28
 
21
- ## Exports
29
+ ### JWT Utilities
30
+
31
+ ```ts
32
+ import { decodeJWTPayload, isTokenExpired, getClaimsFromToken } from "@inai-dev/shared";
33
+
34
+ const payload = decodeJWTPayload(token); // Raw JWT payload or null
35
+ const expired = isTokenExpired(token); // boolean
36
+ const claims = getClaimsFromToken(token); // JWTClaims or null
37
+ ```
38
+
39
+ ### Validators
40
+
41
+ ```ts
42
+ import { isValidEmail, isStrongPassword } from "@inai-dev/shared";
43
+
44
+ isValidEmail("user@example.com"); // true
45
+ isStrongPassword("MyP@ss1234"); // true
46
+ ```
47
+
48
+ ### Constants
49
+
50
+ ```ts
51
+ import {
52
+ COOKIE_AUTH_TOKEN, // "auth_token"
53
+ COOKIE_REFRESH_TOKEN, // "refresh_token"
54
+ COOKIE_AUTH_SESSION, // "auth_session"
55
+ DEFAULT_SIGN_IN_URL, // "/login"
56
+ DEFAULT_SIGN_UP_URL, // "/register"
57
+ DEFAULT_AFTER_SIGN_IN_URL, // "/"
58
+ DEFAULT_AFTER_SIGN_OUT_URL, // "/login"
59
+ HEADER_PUBLISHABLE_KEY, // "X-Publishable-Key"
60
+ HEADER_AUTHORIZATION, // "Authorization"
61
+ HEADER_INAI_AUTH, // "x-inai-auth"
62
+ DEFAULT_API_URL, // Internal — not for public use
63
+ } from "@inai-dev/shared";
64
+ ```
65
+
66
+ ### URL Utilities
22
67
 
23
- - **Errors**: `InAIError`, `isInAIError`, error codes
24
- - **Validators**: Email, password, and input validation
25
- - **JWT**: Token decode and verification utilities
26
- - **URL**: API URL builder helpers
27
- - **Constants**: Cookie names, header names, default values
68
+ ```ts
69
+ import { normalizeApiUrl, buildEndpoint } from "@inai-dev/shared";
70
+ ```
28
71
 
29
- ## Documentation
72
+ ## Exports Reference
30
73
 
31
- See the full [API Reference](https://github.com/inai-dev/sdk/blob/main/docs/api-reference.md).
74
+ | Export | Kind | Description |
75
+ |---|---|---|
76
+ | `InAIAuthError` | Class | Auth error with status and body |
77
+ | `decodeJWTPayload` | Function | Decode JWT payload (no verification) |
78
+ | `isTokenExpired` | Function | Check if JWT is expired |
79
+ | `getClaimsFromToken` | Function | Extract typed JWTClaims from token |
80
+ | `isValidEmail` | Function | Email format validation |
81
+ | `isStrongPassword` | Function | Password strength validation |
82
+ | `normalizeApiUrl` | Function | Normalize API URL (trailing slash) |
83
+ | `buildEndpoint` | Function | Build full API endpoint URL |
84
+ | `COOKIE_AUTH_TOKEN` | Constant | Auth token cookie name |
85
+ | `COOKIE_REFRESH_TOKEN` | Constant | Refresh token cookie name |
86
+ | `COOKIE_AUTH_SESSION` | Constant | Session cookie name |
87
+ | `DEFAULT_API_URL` | Constant | Default API URL (internal) |
88
+ | `HEADER_PUBLISHABLE_KEY` | Constant | Publishable key header name |
32
89
 
33
90
  ## License
34
91
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inai-dev/shared",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Shared utilities for the InAI Auth SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "prepublishOnly": "npm run build"
25
25
  },
26
26
  "dependencies": {
27
- "@inai-dev/types": "^1.0.0"
27
+ "@inai-dev/types": "^1.1.0"
28
28
  },
29
29
  "sideEffects": false,
30
30
  "publishConfig": {