@inai-dev/shared 1.0.0 → 1.2.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/README.md +74 -13
- 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
|
|
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,86 @@ 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
|
-
##
|
|
13
|
+
## Exports
|
|
14
|
+
|
|
15
|
+
### Error Class
|
|
14
16
|
|
|
15
17
|
```ts
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
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
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { normalizeApiUrl, buildEndpoint } from "@inai-dev/shared";
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Exports Reference
|
|
22
73
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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 |
|
|
28
89
|
|
|
29
|
-
##
|
|
90
|
+
## Questions & Support
|
|
30
91
|
|
|
31
|
-
|
|
92
|
+
Visit [https://inai.dev](https://inai.dev) for documentation, guides, and support.
|
|
32
93
|
|
|
33
94
|
## License
|
|
34
95
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inai-dev/shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.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.
|
|
27
|
+
"@inai-dev/types": "^1.2.0"
|
|
28
28
|
},
|
|
29
29
|
"sideEffects": false,
|
|
30
30
|
"publishConfig": {
|