@longzai-intelligence-tenant/core 0.0.1

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.
@@ -0,0 +1,387 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/types/tenant.d.ts
4
+ type TenantStatus = "active" | "suspended" | "inactive";
5
+ type TenantListItem = {
6
+ id: string;
7
+ name: string;
8
+ slug: string;
9
+ status: TenantStatus;
10
+ plan: string | null;
11
+ ownerId: string;
12
+ maxMembers: number;
13
+ createdAt: string;
14
+ updatedAt: string;
15
+ };
16
+ type TenantDetail = TenantListItem & {
17
+ settings: Record<string, unknown>;
18
+ };
19
+ type CreateTenantInput = {
20
+ id: string;
21
+ name: string;
22
+ slug: string;
23
+ plan?: string | null;
24
+ ownerId: string;
25
+ maxMembers?: number;
26
+ };
27
+ type UpdateTenantInput = {
28
+ name?: string;
29
+ plan?: string | null;
30
+ maxMembers?: number;
31
+ settings?: Record<string, unknown>;
32
+ };
33
+ //#endregion
34
+ //#region src/types/membership.d.ts
35
+ type MemberRole = "owner" | "admin" | "member" | "viewer";
36
+ type MemberStatus = "active" | "inactive";
37
+ type MemberItem = {
38
+ id: string;
39
+ tenantId: string;
40
+ userId: string;
41
+ role: MemberRole;
42
+ joinedAt: string;
43
+ status: MemberStatus;
44
+ };
45
+ type InvitationStatus = "pending" | "accepted" | "expired" | "cancelled";
46
+ type InvitationItem = {
47
+ id: string;
48
+ tenantId: string;
49
+ inviteCode: string;
50
+ email: string;
51
+ role: MemberRole;
52
+ expiresAt: string;
53
+ status: InvitationStatus;
54
+ usedBy: string | null;
55
+ usedAt: string | null;
56
+ };
57
+ type AddMemberInput = {
58
+ userId: string;
59
+ role: MemberRole;
60
+ };
61
+ type CreateInvitationInput = {
62
+ email: string;
63
+ role: MemberRole;
64
+ expiresInHours?: number;
65
+ };
66
+ //#endregion
67
+ //#region src/types/subscription.d.ts
68
+ type PlanStatus = "active" | "archived";
69
+ type BillingCycle = "monthly" | "yearly" | "lifetime";
70
+ type PlanItem = {
71
+ id: string;
72
+ name: string;
73
+ description: string | null;
74
+ features: string[];
75
+ limits: Record<string, number>;
76
+ price: number;
77
+ billingCycle: BillingCycle;
78
+ status: PlanStatus;
79
+ };
80
+ type SubscriptionStatus = "active" | "expired" | "cancelled" | "trial";
81
+ type SubscriptionItem = {
82
+ id: string;
83
+ tenantId: string;
84
+ planId: string;
85
+ status: SubscriptionStatus;
86
+ startDate: string;
87
+ endDate: string | null;
88
+ trialEndAt: string | null;
89
+ };
90
+ type CreatePlanInput = {
91
+ name: string;
92
+ description?: string | null;
93
+ features: string[];
94
+ limits: Record<string, number>;
95
+ price: number;
96
+ billingCycle: BillingCycle;
97
+ };
98
+ type SubscribeInput = {
99
+ planId: string;
100
+ trialDays?: number;
101
+ };
102
+ //#endregion
103
+ //#region src/types/quota.d.ts
104
+ type ResourceType = "members" | "projects" | "storage" | "api_calls";
105
+ type QuotaPeriod = "monthly" | "yearly" | "total";
106
+ type QuotaItem = {
107
+ id: string;
108
+ tenantId: string;
109
+ resourceType: ResourceType;
110
+ limit: number;
111
+ used: number;
112
+ period: QuotaPeriod;
113
+ };
114
+ type QuotaCheckResult = {
115
+ allowed: boolean;
116
+ resourceType: ResourceType;
117
+ current: number;
118
+ limit: number;
119
+ };
120
+ type AdjustQuotaInput = {
121
+ resourceType: ResourceType;
122
+ limit: number;
123
+ };
124
+ //#endregion
125
+ //#region src/schemas/tenant.d.ts
126
+ declare const tenantStatusSchema: z.ZodEnum<{
127
+ active: "active";
128
+ suspended: "suspended";
129
+ inactive: "inactive";
130
+ }>;
131
+ declare const tenantListItemSchema: z.ZodObject<{
132
+ id: z.ZodString;
133
+ name: z.ZodString;
134
+ slug: z.ZodString;
135
+ status: z.ZodEnum<{
136
+ active: "active";
137
+ suspended: "suspended";
138
+ inactive: "inactive";
139
+ }>;
140
+ plan: z.ZodNullable<z.ZodString>;
141
+ ownerId: z.ZodString;
142
+ maxMembers: z.ZodNumber;
143
+ createdAt: z.ZodString;
144
+ updatedAt: z.ZodString;
145
+ }, z.core.$strip>;
146
+ declare const tenantDetailSchema: z.ZodObject<{
147
+ id: z.ZodString;
148
+ name: z.ZodString;
149
+ slug: z.ZodString;
150
+ status: z.ZodEnum<{
151
+ active: "active";
152
+ suspended: "suspended";
153
+ inactive: "inactive";
154
+ }>;
155
+ plan: z.ZodNullable<z.ZodString>;
156
+ ownerId: z.ZodString;
157
+ maxMembers: z.ZodNumber;
158
+ createdAt: z.ZodString;
159
+ updatedAt: z.ZodString;
160
+ settings: z.ZodRecord<z.ZodString, z.ZodUnknown>;
161
+ }, z.core.$strip>;
162
+ declare const createTenantInputSchema: z.ZodObject<{
163
+ id: z.ZodString;
164
+ name: z.ZodString;
165
+ slug: z.ZodString;
166
+ plan: z.ZodOptional<z.ZodNullable<z.ZodString>>;
167
+ ownerId: z.ZodString;
168
+ maxMembers: z.ZodOptional<z.ZodNumber>;
169
+ }, z.core.$strip>;
170
+ declare const updateTenantInputSchema: z.ZodObject<{
171
+ name: z.ZodOptional<z.ZodString>;
172
+ plan: z.ZodOptional<z.ZodNullable<z.ZodString>>;
173
+ maxMembers: z.ZodOptional<z.ZodNumber>;
174
+ settings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
175
+ }, z.core.$strip>;
176
+ //#endregion
177
+ //#region src/schemas/membership.d.ts
178
+ declare const memberRoleSchema: z.ZodEnum<{
179
+ owner: "owner";
180
+ admin: "admin";
181
+ member: "member";
182
+ viewer: "viewer";
183
+ }>;
184
+ declare const memberStatusSchema: z.ZodEnum<{
185
+ active: "active";
186
+ inactive: "inactive";
187
+ }>;
188
+ declare const invitationStatusSchema: z.ZodEnum<{
189
+ expired: "expired";
190
+ cancelled: "cancelled";
191
+ pending: "pending";
192
+ accepted: "accepted";
193
+ }>;
194
+ declare const memberItemSchema: z.ZodObject<{
195
+ id: z.ZodString;
196
+ tenantId: z.ZodString;
197
+ userId: z.ZodString;
198
+ role: z.ZodEnum<{
199
+ owner: "owner";
200
+ admin: "admin";
201
+ member: "member";
202
+ viewer: "viewer";
203
+ }>;
204
+ joinedAt: z.ZodString;
205
+ status: z.ZodEnum<{
206
+ active: "active";
207
+ inactive: "inactive";
208
+ }>;
209
+ }, z.core.$strip>;
210
+ declare const invitationItemSchema: z.ZodObject<{
211
+ id: z.ZodString;
212
+ tenantId: z.ZodString;
213
+ inviteCode: z.ZodString;
214
+ email: z.ZodString;
215
+ role: z.ZodEnum<{
216
+ owner: "owner";
217
+ admin: "admin";
218
+ member: "member";
219
+ viewer: "viewer";
220
+ }>;
221
+ expiresAt: z.ZodString;
222
+ status: z.ZodEnum<{
223
+ expired: "expired";
224
+ cancelled: "cancelled";
225
+ pending: "pending";
226
+ accepted: "accepted";
227
+ }>;
228
+ usedBy: z.ZodNullable<z.ZodString>;
229
+ usedAt: z.ZodNullable<z.ZodString>;
230
+ }, z.core.$strip>;
231
+ declare const addMemberInputSchema: z.ZodObject<{
232
+ userId: z.ZodString;
233
+ role: z.ZodEnum<{
234
+ owner: "owner";
235
+ admin: "admin";
236
+ member: "member";
237
+ viewer: "viewer";
238
+ }>;
239
+ }, z.core.$strip>;
240
+ declare const createInvitationInputSchema: z.ZodObject<{
241
+ email: z.ZodString;
242
+ role: z.ZodEnum<{
243
+ owner: "owner";
244
+ admin: "admin";
245
+ member: "member";
246
+ viewer: "viewer";
247
+ }>;
248
+ expiresInHours: z.ZodOptional<z.ZodNumber>;
249
+ }, z.core.$strip>;
250
+ //#endregion
251
+ //#region src/schemas/subscription.d.ts
252
+ declare const planStatusSchema: z.ZodEnum<{
253
+ active: "active";
254
+ archived: "archived";
255
+ }>;
256
+ declare const billingCycleSchema: z.ZodEnum<{
257
+ monthly: "monthly";
258
+ yearly: "yearly";
259
+ lifetime: "lifetime";
260
+ }>;
261
+ declare const subscriptionStatusSchema: z.ZodEnum<{
262
+ active: "active";
263
+ expired: "expired";
264
+ cancelled: "cancelled";
265
+ trial: "trial";
266
+ }>;
267
+ declare const planItemSchema: z.ZodObject<{
268
+ id: z.ZodString;
269
+ name: z.ZodString;
270
+ description: z.ZodNullable<z.ZodString>;
271
+ features: z.ZodArray<z.ZodString>;
272
+ limits: z.ZodRecord<z.ZodString, z.ZodNumber>;
273
+ price: z.ZodNumber;
274
+ billingCycle: z.ZodEnum<{
275
+ monthly: "monthly";
276
+ yearly: "yearly";
277
+ lifetime: "lifetime";
278
+ }>;
279
+ status: z.ZodEnum<{
280
+ active: "active";
281
+ archived: "archived";
282
+ }>;
283
+ }, z.core.$strip>;
284
+ declare const subscriptionItemSchema: z.ZodObject<{
285
+ id: z.ZodString;
286
+ tenantId: z.ZodString;
287
+ planId: z.ZodString;
288
+ status: z.ZodEnum<{
289
+ active: "active";
290
+ expired: "expired";
291
+ cancelled: "cancelled";
292
+ trial: "trial";
293
+ }>;
294
+ startDate: z.ZodString;
295
+ endDate: z.ZodNullable<z.ZodString>;
296
+ trialEndAt: z.ZodNullable<z.ZodString>;
297
+ }, z.core.$strip>;
298
+ declare const createPlanInputSchema: z.ZodObject<{
299
+ name: z.ZodString;
300
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
301
+ features: z.ZodArray<z.ZodString>;
302
+ limits: z.ZodRecord<z.ZodString, z.ZodNumber>;
303
+ price: z.ZodNumber;
304
+ billingCycle: z.ZodEnum<{
305
+ monthly: "monthly";
306
+ yearly: "yearly";
307
+ lifetime: "lifetime";
308
+ }>;
309
+ }, z.core.$strip>;
310
+ declare const subscribeInputSchema: z.ZodObject<{
311
+ planId: z.ZodString;
312
+ trialDays: z.ZodOptional<z.ZodNumber>;
313
+ }, z.core.$strip>;
314
+ //#endregion
315
+ //#region src/schemas/quota.d.ts
316
+ declare const resourceTypeSchema: z.ZodEnum<{
317
+ members: "members";
318
+ projects: "projects";
319
+ storage: "storage";
320
+ api_calls: "api_calls";
321
+ }>;
322
+ declare const quotaPeriodSchema: z.ZodEnum<{
323
+ monthly: "monthly";
324
+ yearly: "yearly";
325
+ total: "total";
326
+ }>;
327
+ declare const quotaItemSchema: z.ZodObject<{
328
+ id: z.ZodString;
329
+ tenantId: z.ZodString;
330
+ resourceType: z.ZodEnum<{
331
+ members: "members";
332
+ projects: "projects";
333
+ storage: "storage";
334
+ api_calls: "api_calls";
335
+ }>;
336
+ limit: z.ZodNumber;
337
+ used: z.ZodNumber;
338
+ period: z.ZodEnum<{
339
+ monthly: "monthly";
340
+ yearly: "yearly";
341
+ total: "total";
342
+ }>;
343
+ }, z.core.$strip>;
344
+ declare const quotaCheckResultSchema: z.ZodObject<{
345
+ allowed: z.ZodBoolean;
346
+ resourceType: z.ZodEnum<{
347
+ members: "members";
348
+ projects: "projects";
349
+ storage: "storage";
350
+ api_calls: "api_calls";
351
+ }>;
352
+ current: z.ZodNumber;
353
+ limit: z.ZodNumber;
354
+ }, z.core.$strip>;
355
+ declare const adjustQuotaInputSchema: z.ZodObject<{
356
+ resourceType: z.ZodEnum<{
357
+ members: "members";
358
+ projects: "projects";
359
+ storage: "storage";
360
+ api_calls: "api_calls";
361
+ }>;
362
+ limit: z.ZodNumber;
363
+ }, z.core.$strip>;
364
+ //#endregion
365
+ //#region src/constants/index.d.ts
366
+ declare const DEFAULT_MAX_MEMBERS = 10;
367
+ declare const DEFAULT_PAGE_SIZE = 20;
368
+ declare const MAX_PAGE_SIZE = 100;
369
+ declare const DEFAULT_INVITATION_EXPIRY_HOURS = 72;
370
+ declare const DEFAULT_QUOTA_LIMITS: Record<string, number>;
371
+ //#endregion
372
+ //#region src/utils/index.d.ts
373
+ type PaginatedInput = {
374
+ page?: number;
375
+ pageSize?: number;
376
+ };
377
+ type PaginatedOutput<T> = {
378
+ items: T[];
379
+ total: number;
380
+ page: number;
381
+ pageSize: number;
382
+ totalPages: number;
383
+ };
384
+ declare function paginate<T>(items: T[], input?: PaginatedInput): PaginatedOutput<T>;
385
+ declare function generateInviteCode(): string;
386
+ //#endregion
387
+ export { type AddMemberInput, type AdjustQuotaInput, type BillingCycle, type CreateInvitationInput, type CreatePlanInput, type CreateTenantInput, DEFAULT_INVITATION_EXPIRY_HOURS, DEFAULT_MAX_MEMBERS, DEFAULT_PAGE_SIZE, DEFAULT_QUOTA_LIMITS, type InvitationItem, type InvitationStatus, MAX_PAGE_SIZE, type MemberItem, type MemberRole, type MemberStatus, PaginatedInput, PaginatedOutput, type PlanItem, type PlanStatus, type QuotaCheckResult, type QuotaItem, type QuotaPeriod, type ResourceType, type SubscribeInput, type SubscriptionItem, type SubscriptionStatus, type TenantDetail, type TenantListItem, type TenantStatus, type UpdateTenantInput, addMemberInputSchema, adjustQuotaInputSchema, billingCycleSchema, createInvitationInputSchema, createPlanInputSchema, createTenantInputSchema, generateInviteCode, invitationItemSchema, invitationStatusSchema, memberItemSchema, memberRoleSchema, memberStatusSchema, paginate, planItemSchema, planStatusSchema, quotaCheckResultSchema, quotaItemSchema, quotaPeriodSchema, resourceTypeSchema, subscribeInputSchema, subscriptionItemSchema, subscriptionStatusSchema, tenantDetailSchema, tenantListItemSchema, tenantStatusSchema, updateTenantInputSchema };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{z as e}from"zod";const t=e.enum([`active`,`suspended`,`inactive`]),n=e.object({id:e.string(),name:e.string(),slug:e.string(),status:t,plan:e.string().nullable(),ownerId:e.string(),maxMembers:e.number(),createdAt:e.string(),updatedAt:e.string()}),r=n.extend({settings:e.record(e.string(),e.unknown())}),i=e.object({id:e.string(),name:e.string().min(1),slug:e.string().min(1),plan:e.string().nullable().optional(),ownerId:e.string().min(1),maxMembers:e.number().int().min(1).optional()}),a=e.object({name:e.string().min(1).optional(),plan:e.string().nullable().optional(),maxMembers:e.number().int().min(1).optional(),settings:e.record(e.string(),e.unknown()).optional()}),o=e.enum([`owner`,`admin`,`member`,`viewer`]),s=e.enum([`active`,`inactive`]),c=e.enum([`pending`,`accepted`,`expired`,`cancelled`]),l=e.object({id:e.string(),tenantId:e.string(),userId:e.string(),role:o,joinedAt:e.string(),status:s}),u=e.object({id:e.string(),tenantId:e.string(),inviteCode:e.string(),email:e.string().email(),role:o,expiresAt:e.string(),status:c,usedBy:e.string().nullable(),usedAt:e.string().nullable()}),d=e.object({userId:e.string().min(1),role:o}),f=e.object({email:e.string().email(),role:o,expiresInHours:e.number().int().min(1).optional()}),p=e.enum([`active`,`archived`]),m=e.enum([`monthly`,`yearly`,`lifetime`]),h=e.enum([`active`,`expired`,`cancelled`,`trial`]),g=e.object({id:e.string(),name:e.string(),description:e.string().nullable(),features:e.array(e.string()),limits:e.record(e.string(),e.number()),price:e.number().nonnegative(),billingCycle:m,status:p}),_=e.object({id:e.string(),tenantId:e.string(),planId:e.string(),status:h,startDate:e.string(),endDate:e.string().nullable(),trialEndAt:e.string().nullable()}),v=e.object({name:e.string().min(1),description:e.string().nullable().optional(),features:e.array(e.string()),limits:e.record(e.string(),e.number()),price:e.number().nonnegative(),billingCycle:m}),y=e.object({planId:e.string().min(1),trialDays:e.number().int().min(0).optional()}),b=e.enum([`members`,`projects`,`storage`,`api_calls`]),x=e.enum([`monthly`,`yearly`,`total`]),S=e.object({id:e.string(),tenantId:e.string(),resourceType:b,limit:e.number().int().nonnegative(),used:e.number().int().nonnegative(),period:x}),C=e.object({allowed:e.boolean(),resourceType:b,current:e.number().int().nonnegative(),limit:e.number().int().nonnegative()}),w=e.object({resourceType:b,limit:e.number().int().min(0)}),T=10,E=20,D=100,O=72,k={members:10,projects:5,storage:1073741824,api_calls:1e4};function A(e,t){let n=t?.page??1,r=t?.pageSize??20,i=e.length,a=Math.max(1,Math.ceil(i/r)),o=(n-1)*r;return{items:e.slice(o,o+r),total:i,page:n,pageSize:r,totalPages:a}}function j(){let e=``;for(let t=0;t<32;t++)e+=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`.charAt(Math.floor(Math.random()*62));return e}export{O as DEFAULT_INVITATION_EXPIRY_HOURS,T as DEFAULT_MAX_MEMBERS,E as DEFAULT_PAGE_SIZE,k as DEFAULT_QUOTA_LIMITS,D as MAX_PAGE_SIZE,d as addMemberInputSchema,w as adjustQuotaInputSchema,m as billingCycleSchema,f as createInvitationInputSchema,v as createPlanInputSchema,i as createTenantInputSchema,j as generateInviteCode,u as invitationItemSchema,c as invitationStatusSchema,l as memberItemSchema,o as memberRoleSchema,s as memberStatusSchema,A as paginate,g as planItemSchema,p as planStatusSchema,C as quotaCheckResultSchema,S as quotaItemSchema,x as quotaPeriodSchema,b as resourceTypeSchema,y as subscribeInputSchema,_ as subscriptionItemSchema,h as subscriptionStatusSchema,r as tenantDetailSchema,n as tenantListItemSchema,t as tenantStatusSchema,a as updateTenantInputSchema};
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@longzai-intelligence-tenant/core",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsgo --build tsconfig/build.json && resolve-aliases -p tsconfig/build.json",
20
+ "build:prod": "NODE_ENV=production tsdown",
21
+ "prepublishOnly": "bun run build:prod",
22
+ "typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
23
+ "typecheck:app": "tsgo --noEmit -p tsconfig/app.json",
24
+ "typecheck:node": "tsgo --noEmit -p tsconfig/node.json",
25
+ "typecheck:test": "tsgo --noEmit -p tsconfig/test.json",
26
+ "lint": "oxlint src && oxfmt --check src",
27
+ "lint:fix": "oxlint --fix src && oxfmt src",
28
+ "test": "bun test",
29
+ "test:watch": "bun test --watch",
30
+ "test:coverage": "bun test --coverage",
31
+ "clean": "rm -rf dist out .cache"
32
+ },
33
+ "dependencies": {
34
+ "zod": "^4.4.3"
35
+ },
36
+ "devDependencies": {}
37
+ }