@hanzo/iam 0.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.
package/src/types.ts ADDED
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Core types for the Hanzo IAM SDK.
3
+ * Based on Casdoor data models.
4
+ */
5
+
6
+ // ---------------------------------------------------------------------------
7
+ // Config
8
+ // ---------------------------------------------------------------------------
9
+
10
+ export type IamConfig = {
11
+ /** IAM server base URL (e.g. "https://iam.hanzo.ai"). */
12
+ serverUrl: string;
13
+ /** OAuth2 client ID. */
14
+ clientId: string;
15
+ /** OAuth2 client secret (for confidential clients / server-side). */
16
+ clientSecret?: string;
17
+ /** Organization name (owner context). */
18
+ orgName?: string;
19
+ /** Application name. */
20
+ appName?: string;
21
+ };
22
+
23
+ // ---------------------------------------------------------------------------
24
+ // OIDC
25
+ // ---------------------------------------------------------------------------
26
+
27
+ export type OidcDiscovery = {
28
+ issuer: string;
29
+ authorization_endpoint: string;
30
+ token_endpoint: string;
31
+ userinfo_endpoint: string;
32
+ jwks_uri: string;
33
+ scopes_supported?: string[];
34
+ response_types_supported?: string[];
35
+ grant_types_supported?: string[];
36
+ };
37
+
38
+ export type TokenResponse = {
39
+ access_token: string;
40
+ token_type: string;
41
+ expires_in?: number;
42
+ refresh_token?: string;
43
+ id_token?: string;
44
+ scope?: string;
45
+ };
46
+
47
+ // ---------------------------------------------------------------------------
48
+ // JWT Claims
49
+ // ---------------------------------------------------------------------------
50
+
51
+ export type IamJwtClaims = {
52
+ /** Subject (user ID in format "org/username"). */
53
+ sub: string;
54
+ /** Issuer URL. */
55
+ iss?: string;
56
+ /** Audience. */
57
+ aud?: string | string[];
58
+ /** Expiry (unix seconds). */
59
+ exp?: number;
60
+ /** Issued at (unix seconds). */
61
+ iat?: number;
62
+ /** User email. */
63
+ email?: string;
64
+ /** Display name. */
65
+ name?: string;
66
+ /** Preferred username. */
67
+ preferred_username?: string;
68
+ /** Avatar URL. */
69
+ picture?: string;
70
+ /** Phone number. */
71
+ phone?: string;
72
+ /** Groups/roles. */
73
+ groups?: string[];
74
+ /** Arbitrary extra claims. */
75
+ [key: string]: unknown;
76
+ };
77
+
78
+ // ---------------------------------------------------------------------------
79
+ // User
80
+ // ---------------------------------------------------------------------------
81
+
82
+ export type IamUser = {
83
+ owner: string;
84
+ name: string;
85
+ id?: string;
86
+ displayName?: string;
87
+ email?: string;
88
+ phone?: string;
89
+ avatar?: string;
90
+ type?: string;
91
+ isAdmin?: boolean;
92
+ isGlobalAdmin?: boolean;
93
+ createdTime?: string;
94
+ signupApplication?: string;
95
+ };
96
+
97
+ // ---------------------------------------------------------------------------
98
+ // Organization
99
+ // ---------------------------------------------------------------------------
100
+
101
+ export type IamOrganization = {
102
+ owner: string;
103
+ name: string;
104
+ displayName?: string;
105
+ createdTime?: string;
106
+ websiteUrl?: string;
107
+ logo?: string;
108
+ logoDark?: string;
109
+ favicon?: string;
110
+ isPersonal?: boolean;
111
+ orgBalance?: number;
112
+ userBalance?: number;
113
+ balanceCredit?: number;
114
+ balanceCurrency?: string;
115
+ };
116
+
117
+ // ---------------------------------------------------------------------------
118
+ // Subscription / Plan / Pricing
119
+ // ---------------------------------------------------------------------------
120
+
121
+ export type IamSubscription = {
122
+ owner: string;
123
+ name: string;
124
+ displayName?: string;
125
+ createdTime?: string;
126
+ user?: string;
127
+ plan?: string;
128
+ pricing?: string;
129
+ startTime?: string;
130
+ endTime?: string;
131
+ duration?: number;
132
+ state?: "Active" | "Inactive" | "Expired" | "Cancelled" | string;
133
+ description?: string;
134
+ };
135
+
136
+ export type IamPlan = {
137
+ owner: string;
138
+ name: string;
139
+ displayName?: string;
140
+ createdTime?: string;
141
+ description?: string;
142
+ pricePerMonth?: number;
143
+ pricePerYear?: number;
144
+ currency?: string;
145
+ options?: string[];
146
+ isEnabled?: boolean;
147
+ role?: string;
148
+ };
149
+
150
+ export type IamPricing = {
151
+ owner: string;
152
+ name: string;
153
+ displayName?: string;
154
+ createdTime?: string;
155
+ description?: string;
156
+ plans?: string[];
157
+ isEnabled?: boolean;
158
+ application?: string;
159
+ trialDuration?: number;
160
+ };
161
+
162
+ // ---------------------------------------------------------------------------
163
+ // Payment / Order
164
+ // ---------------------------------------------------------------------------
165
+
166
+ export type IamPayment = {
167
+ owner: string;
168
+ name: string;
169
+ displayName?: string;
170
+ createdTime?: string;
171
+ provider?: string;
172
+ type?: string;
173
+ currency?: string;
174
+ price?: number;
175
+ user?: string;
176
+ state?: string;
177
+ message?: string;
178
+ };
179
+
180
+ export type IamOrder = {
181
+ owner: string;
182
+ name: string;
183
+ displayName?: string;
184
+ createdTime?: string;
185
+ user?: string;
186
+ products?: string[];
187
+ price?: number;
188
+ currency?: string;
189
+ state?: string;
190
+ message?: string;
191
+ };
192
+
193
+ // ---------------------------------------------------------------------------
194
+ // Auth result
195
+ // ---------------------------------------------------------------------------
196
+
197
+ export type IamAuthResult =
198
+ | {
199
+ ok: true;
200
+ userId: string;
201
+ email?: string;
202
+ name?: string;
203
+ avatar?: string;
204
+ owner: string;
205
+ claims: IamJwtClaims;
206
+ }
207
+ | {
208
+ ok: false;
209
+ reason: string;
210
+ };
211
+
212
+ // ---------------------------------------------------------------------------
213
+ // API response wrapper
214
+ // ---------------------------------------------------------------------------
215
+
216
+ export type IamApiResponse<T> = {
217
+ status: "ok" | "error";
218
+ msg?: string;
219
+ data?: T;
220
+ data2?: unknown;
221
+ };