@companyio/auth-contracts 0.1.3 → 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/README.md +19 -0
- package/package.json +12 -2
- package/src/index.ts +0 -84
- package/tsconfig.json +0 -11
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @companyio/auth-contracts
|
|
2
|
+
|
|
3
|
+
Shared Zod validation schemas and TypeScript types for authentication, users, sessions, organizations, and invitations.
|
|
4
|
+
|
|
5
|
+
Exports include `SignInSchema`, `SignUpSchema`, `SessionSchema`, `UserSchema`, `OrganizationSchema`, and their inferred types.
|
|
6
|
+
|
|
7
|
+
## Use
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { SignInSchema } from '@companyio/auth-contracts';
|
|
11
|
+
|
|
12
|
+
const credentials = SignInSchema.parse({ email, password });
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Build
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm --filter @companyio/auth-contracts build
|
|
19
|
+
```
|
package/package.json
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@companyio/auth-contracts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Shared authentication, user, organization, and permission contracts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
8
18
|
"dependencies": {
|
|
9
19
|
"zod": "^3.22.0"
|
|
10
20
|
},
|
|
@@ -13,6 +23,6 @@
|
|
|
13
23
|
},
|
|
14
24
|
"scripts": {
|
|
15
25
|
"build": "tsc",
|
|
16
|
-
"test": "
|
|
26
|
+
"test": "vitest run"
|
|
17
27
|
}
|
|
18
28
|
}
|
package/src/index.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
export const UserSchema = z.object({
|
|
4
|
-
id: z.string(),
|
|
5
|
-
email: z.string().email(),
|
|
6
|
-
name: z.string().min(1),
|
|
7
|
-
main_business_id: z.string().min(1),
|
|
8
|
-
branch_id: z.string().min(1),
|
|
9
|
-
avatarUrl: z.string().url().optional(),
|
|
10
|
-
createdAt: z.string().datetime(),
|
|
11
|
-
updatedAt: z.string().datetime(),
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export type User = z.infer<typeof UserSchema>;
|
|
15
|
-
|
|
16
|
-
export const OrganizationSchema = z.object({
|
|
17
|
-
id: z.string(),
|
|
18
|
-
name: z.string().min(1),
|
|
19
|
-
slug: z.string().min(1),
|
|
20
|
-
role: z.enum(['owner', 'admin', 'member']),
|
|
21
|
-
main_business_id: z.string().min(1),
|
|
22
|
-
branch_id: z.string().min(1),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export type Organization = z.infer<typeof OrganizationSchema>;
|
|
26
|
-
|
|
27
|
-
export const SessionSchema = z.object({
|
|
28
|
-
accessToken: z.string().min(1),
|
|
29
|
-
expiresAt: z.number().int().positive(),
|
|
30
|
-
user: UserSchema,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
export type AuthSession = z.infer<typeof SessionSchema>;
|
|
34
|
-
|
|
35
|
-
export type AuthErrorCode =
|
|
36
|
-
'UNAUTHENTICATED' | 'FORBIDDEN' | 'INVALID_REQUEST' | 'NETWORK_ERROR' | 'UNKNOWN';
|
|
37
|
-
|
|
38
|
-
export type AuthError = {
|
|
39
|
-
code: AuthErrorCode;
|
|
40
|
-
message: string;
|
|
41
|
-
status?: number;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const SignUpSchema = z.object({
|
|
45
|
-
name: z.string().min(1).max(80),
|
|
46
|
-
email: z.string().email(),
|
|
47
|
-
password: z.string().min(8).max(128),
|
|
48
|
-
businessName: z.string().min(1).max(120),
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
export type SignUpInput = z.infer<typeof SignUpSchema>;
|
|
52
|
-
|
|
53
|
-
export const SignInSchema = z.object({
|
|
54
|
-
email: z.string().email(),
|
|
55
|
-
password: z.string().min(1),
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
export type SignInInput = z.infer<typeof SignInSchema>;
|
|
59
|
-
|
|
60
|
-
export type AuthClientConfig = {
|
|
61
|
-
baseUrl: string;
|
|
62
|
-
clientId: string;
|
|
63
|
-
storage?: TokenStorage;
|
|
64
|
-
fetch?: typeof fetch;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export interface TokenStorage {
|
|
68
|
-
get(): Promise<string | null>;
|
|
69
|
-
set(token: string): Promise<void>;
|
|
70
|
-
clear(): Promise<void>;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export type AuthApi = {
|
|
74
|
-
session: AuthSession;
|
|
75
|
-
user: User;
|
|
76
|
-
organizations: Organization[];
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const CreateInvitationSchema = z.object({
|
|
80
|
-
email: z.string().email(),
|
|
81
|
-
role: z.enum(['admin', 'member']).default('member'),
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
export type CreateInvitation = z.infer<typeof CreateInvitationSchema>;
|