@sudobility/entity_service 1.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.
- package/CLAUDE.md +124 -0
- package/dist/helpers/EntityHelper.cjs +234 -0
- package/dist/helpers/EntityHelper.d.ts +60 -0
- package/dist/helpers/EntityHelper.d.ts.map +1 -0
- package/dist/helpers/EntityHelper.js +234 -0
- package/dist/helpers/EntityHelper.js.map +1 -0
- package/dist/helpers/EntityMemberHelper.cjs +215 -0
- package/dist/helpers/EntityMemberHelper.d.ts +45 -0
- package/dist/helpers/EntityMemberHelper.d.ts.map +1 -0
- package/dist/helpers/EntityMemberHelper.js +215 -0
- package/dist/helpers/EntityMemberHelper.js.map +1 -0
- package/dist/helpers/InvitationHelper.cjs +251 -0
- package/dist/helpers/InvitationHelper.d.ts +59 -0
- package/dist/helpers/InvitationHelper.d.ts.map +1 -0
- package/dist/helpers/InvitationHelper.js +251 -0
- package/dist/helpers/InvitationHelper.js.map +1 -0
- package/dist/helpers/PermissionHelper.cjs +197 -0
- package/dist/helpers/PermissionHelper.d.ts +86 -0
- package/dist/helpers/PermissionHelper.d.ts.map +1 -0
- package/dist/helpers/PermissionHelper.js +197 -0
- package/dist/helpers/PermissionHelper.js.map +1 -0
- package/dist/helpers/index.cjs +15 -0
- package/dist/helpers/index.d.ts +8 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +15 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/index.cjs +76 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +76 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/hono.cjs +148 -0
- package/dist/middleware/hono.d.ts +102 -0
- package/dist/middleware/hono.d.ts.map +1 -0
- package/dist/middleware/hono.js +148 -0
- package/dist/middleware/hono.js.map +1 -0
- package/dist/middleware/index.cjs +12 -0
- package/dist/middleware/index.d.ts +5 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +12 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/migrations/001_add_entities.cjs +269 -0
- package/dist/migrations/001_add_entities.d.ts +29 -0
- package/dist/migrations/001_add_entities.d.ts.map +1 -0
- package/dist/migrations/001_add_entities.js +269 -0
- package/dist/migrations/001_add_entities.js.map +1 -0
- package/dist/migrations/index.cjs +10 -0
- package/dist/migrations/index.d.ts +5 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +10 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/schema/entities.cjs +304 -0
- package/dist/schema/entities.d.ts +1047 -0
- package/dist/schema/entities.d.ts.map +1 -0
- package/dist/schema/entities.js +304 -0
- package/dist/schema/entities.js.map +1 -0
- package/dist/types/index.cjs +14 -0
- package/dist/types/index.d.ts +71 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +14 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.cjs +21 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/slug-generator.cjs +92 -0
- package/dist/utils/slug-generator.d.ts +41 -0
- package/dist/utils/slug-generator.d.ts.map +1 -0
- package/dist/utils/slug-generator.js +92 -0
- package/dist/utils/slug-generator.js.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../src/schema/entities.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgBH;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,OAwBnE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBzB,CAAC;AAEF,yDAAyD;AACzD,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqB7B,CAAC;AAMF,6CAA6C;AAC7C,MAAM,MAAM,YAAY,GAAG,OAAO,QAAQ,CAAC,YAAY,CAAC;AACxD,MAAM,MAAM,eAAe,GAAG,OAAO,QAAQ,CAAC,YAAY,CAAC;AAE3D,mDAAmD;AACnD,MAAM,MAAM,kBAAkB,GAAG,OAAO,aAAa,CAAC,YAAY,CAAC;AACnE,MAAM,MAAM,qBAAqB,GAAG,OAAO,aAAa,CAAC,YAAY,CAAC;AAEtE,uDAAuD;AACvD,MAAM,MAAM,sBAAsB,GAAG,OAAO,iBAAiB,CAAC,YAAY,CAAC;AAC3E,MAAM,MAAM,yBAAyB,GAAG,OAAO,iBAAiB,CAAC,YAAY,CAAC;AAM9E;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,UAAU,CAAC,cAAc,UAAU,CAAC,CAAC,EAC7C,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAkGf"}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Drizzle Schema for Entity/Organization Tables
|
|
4
|
+
* @description Database schema definitions for entities, members, and invitations
|
|
5
|
+
*
|
|
6
|
+
* Provides:
|
|
7
|
+
* - Factory functions for custom PostgreSQL schemas
|
|
8
|
+
* - Default tables for public schema
|
|
9
|
+
* - Initialization functions for table creation
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.entityInvitations = exports.entityMembers = exports.entities = void 0;
|
|
13
|
+
exports.createEntitiesTable = createEntitiesTable;
|
|
14
|
+
exports.createEntitiesTablePublic = createEntitiesTablePublic;
|
|
15
|
+
exports.createEntityMembersTable = createEntityMembersTable;
|
|
16
|
+
exports.createEntityMembersTablePublic = createEntityMembersTablePublic;
|
|
17
|
+
exports.createEntityInvitationsTable = createEntityInvitationsTable;
|
|
18
|
+
exports.createEntityInvitationsTablePublic = createEntityInvitationsTablePublic;
|
|
19
|
+
exports.initEntityTables = initEntityTables;
|
|
20
|
+
const pg_core_1 = require("drizzle-orm/pg-core");
|
|
21
|
+
// ========================================
|
|
22
|
+
// ENTITIES TABLE
|
|
23
|
+
// ========================================
|
|
24
|
+
/**
|
|
25
|
+
* Create an entities table for a specific PostgreSQL schema.
|
|
26
|
+
*
|
|
27
|
+
* @param schema - The Drizzle pgSchema object
|
|
28
|
+
* @param indexPrefix - Prefix for index names to avoid conflicts
|
|
29
|
+
* @returns Drizzle table definition
|
|
30
|
+
*/
|
|
31
|
+
function createEntitiesTable(schema, indexPrefix) {
|
|
32
|
+
return schema.table('entities', {
|
|
33
|
+
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
|
|
34
|
+
entity_slug: (0, pg_core_1.varchar)('entity_slug', { length: 12 }).notNull().unique(),
|
|
35
|
+
entity_type: (0, pg_core_1.varchar)('entity_type', { length: 20 }).notNull(),
|
|
36
|
+
display_name: (0, pg_core_1.varchar)('display_name', { length: 255 }).notNull(),
|
|
37
|
+
description: (0, pg_core_1.text)('description'),
|
|
38
|
+
avatar_url: (0, pg_core_1.text)('avatar_url'),
|
|
39
|
+
owner_user_id: (0, pg_core_1.uuid)('owner_user_id').notNull(),
|
|
40
|
+
created_at: (0, pg_core_1.timestamp)('created_at', { withTimezone: true }).defaultNow(),
|
|
41
|
+
updated_at: (0, pg_core_1.timestamp)('updated_at', { withTimezone: true }).defaultNow(),
|
|
42
|
+
}, (table) => ({
|
|
43
|
+
slugIdx: (0, pg_core_1.uniqueIndex)(`${indexPrefix}_entities_slug_idx`).on(table.entity_slug),
|
|
44
|
+
ownerIdx: (0, pg_core_1.index)(`${indexPrefix}_entities_owner_idx`).on(table.owner_user_id),
|
|
45
|
+
typeIdx: (0, pg_core_1.index)(`${indexPrefix}_entities_type_idx`).on(table.entity_type),
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create an entities table for the public schema.
|
|
50
|
+
*/
|
|
51
|
+
function createEntitiesTablePublic(indexPrefix) {
|
|
52
|
+
return (0, pg_core_1.pgTable)('entities', {
|
|
53
|
+
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
|
|
54
|
+
entity_slug: (0, pg_core_1.varchar)('entity_slug', { length: 12 }).notNull().unique(),
|
|
55
|
+
entity_type: (0, pg_core_1.varchar)('entity_type', { length: 20 }).notNull(),
|
|
56
|
+
display_name: (0, pg_core_1.varchar)('display_name', { length: 255 }).notNull(),
|
|
57
|
+
description: (0, pg_core_1.text)('description'),
|
|
58
|
+
avatar_url: (0, pg_core_1.text)('avatar_url'),
|
|
59
|
+
owner_user_id: (0, pg_core_1.uuid)('owner_user_id').notNull(),
|
|
60
|
+
created_at: (0, pg_core_1.timestamp)('created_at', { withTimezone: true }).defaultNow(),
|
|
61
|
+
updated_at: (0, pg_core_1.timestamp)('updated_at', { withTimezone: true }).defaultNow(),
|
|
62
|
+
}, (table) => ({
|
|
63
|
+
slugIdx: (0, pg_core_1.uniqueIndex)(`${indexPrefix}_entities_slug_idx`).on(table.entity_slug),
|
|
64
|
+
ownerIdx: (0, pg_core_1.index)(`${indexPrefix}_entities_owner_idx`).on(table.owner_user_id),
|
|
65
|
+
typeIdx: (0, pg_core_1.index)(`${indexPrefix}_entities_type_idx`).on(table.entity_type),
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
// ========================================
|
|
69
|
+
// ENTITY MEMBERS TABLE
|
|
70
|
+
// ========================================
|
|
71
|
+
/**
|
|
72
|
+
* Create an entity_members table for a specific PostgreSQL schema.
|
|
73
|
+
*/
|
|
74
|
+
function createEntityMembersTable(schema, indexPrefix) {
|
|
75
|
+
return schema.table('entity_members', {
|
|
76
|
+
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
|
|
77
|
+
entity_id: (0, pg_core_1.uuid)('entity_id').notNull(),
|
|
78
|
+
user_id: (0, pg_core_1.uuid)('user_id').notNull(),
|
|
79
|
+
role: (0, pg_core_1.varchar)('role', { length: 20 }).notNull(),
|
|
80
|
+
joined_at: (0, pg_core_1.timestamp)('joined_at', { withTimezone: true }).defaultNow(),
|
|
81
|
+
created_at: (0, pg_core_1.timestamp)('created_at', { withTimezone: true }).defaultNow(),
|
|
82
|
+
updated_at: (0, pg_core_1.timestamp)('updated_at', { withTimezone: true }).defaultNow(),
|
|
83
|
+
}, (table) => ({
|
|
84
|
+
entityUserUniqueIdx: (0, pg_core_1.uniqueIndex)(`${indexPrefix}_entity_members_entity_user_idx`).on(table.entity_id, table.user_id),
|
|
85
|
+
entityIdx: (0, pg_core_1.index)(`${indexPrefix}_entity_members_entity_idx`).on(table.entity_id),
|
|
86
|
+
userIdx: (0, pg_core_1.index)(`${indexPrefix}_entity_members_user_idx`).on(table.user_id),
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Create an entity_members table for the public schema.
|
|
91
|
+
*/
|
|
92
|
+
function createEntityMembersTablePublic(indexPrefix) {
|
|
93
|
+
return (0, pg_core_1.pgTable)('entity_members', {
|
|
94
|
+
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
|
|
95
|
+
entity_id: (0, pg_core_1.uuid)('entity_id').notNull(),
|
|
96
|
+
user_id: (0, pg_core_1.uuid)('user_id').notNull(),
|
|
97
|
+
role: (0, pg_core_1.varchar)('role', { length: 20 }).notNull(),
|
|
98
|
+
joined_at: (0, pg_core_1.timestamp)('joined_at', { withTimezone: true }).defaultNow(),
|
|
99
|
+
created_at: (0, pg_core_1.timestamp)('created_at', { withTimezone: true }).defaultNow(),
|
|
100
|
+
updated_at: (0, pg_core_1.timestamp)('updated_at', { withTimezone: true }).defaultNow(),
|
|
101
|
+
}, (table) => ({
|
|
102
|
+
entityUserUniqueIdx: (0, pg_core_1.uniqueIndex)(`${indexPrefix}_entity_members_entity_user_idx`).on(table.entity_id, table.user_id),
|
|
103
|
+
entityIdx: (0, pg_core_1.index)(`${indexPrefix}_entity_members_entity_idx`).on(table.entity_id),
|
|
104
|
+
userIdx: (0, pg_core_1.index)(`${indexPrefix}_entity_members_user_idx`).on(table.user_id),
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
// ========================================
|
|
108
|
+
// ENTITY INVITATIONS TABLE
|
|
109
|
+
// ========================================
|
|
110
|
+
/**
|
|
111
|
+
* Create an entity_invitations table for a specific PostgreSQL schema.
|
|
112
|
+
*/
|
|
113
|
+
function createEntityInvitationsTable(schema, indexPrefix) {
|
|
114
|
+
return schema.table('entity_invitations', {
|
|
115
|
+
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
|
|
116
|
+
entity_id: (0, pg_core_1.uuid)('entity_id').notNull(),
|
|
117
|
+
email: (0, pg_core_1.varchar)('email', { length: 255 }).notNull(),
|
|
118
|
+
role: (0, pg_core_1.varchar)('role', { length: 20 }).notNull(),
|
|
119
|
+
status: (0, pg_core_1.varchar)('status', { length: 20 }).notNull().default('pending'),
|
|
120
|
+
invited_by_user_id: (0, pg_core_1.uuid)('invited_by_user_id').notNull(),
|
|
121
|
+
token: (0, pg_core_1.varchar)('token', { length: 64 }).notNull().unique(),
|
|
122
|
+
expires_at: (0, pg_core_1.timestamp)('expires_at', { withTimezone: true }).notNull(),
|
|
123
|
+
accepted_at: (0, pg_core_1.timestamp)('accepted_at', { withTimezone: true }),
|
|
124
|
+
created_at: (0, pg_core_1.timestamp)('created_at', { withTimezone: true }).defaultNow(),
|
|
125
|
+
updated_at: (0, pg_core_1.timestamp)('updated_at', { withTimezone: true }).defaultNow(),
|
|
126
|
+
}, (table) => ({
|
|
127
|
+
tokenIdx: (0, pg_core_1.uniqueIndex)(`${indexPrefix}_entity_invitations_token_idx`).on(table.token),
|
|
128
|
+
entityIdx: (0, pg_core_1.index)(`${indexPrefix}_entity_invitations_entity_idx`).on(table.entity_id),
|
|
129
|
+
emailIdx: (0, pg_core_1.index)(`${indexPrefix}_entity_invitations_email_idx`).on(table.email),
|
|
130
|
+
statusIdx: (0, pg_core_1.index)(`${indexPrefix}_entity_invitations_status_idx`).on(table.status),
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Create an entity_invitations table for the public schema.
|
|
135
|
+
*/
|
|
136
|
+
function createEntityInvitationsTablePublic(indexPrefix) {
|
|
137
|
+
return (0, pg_core_1.pgTable)('entity_invitations', {
|
|
138
|
+
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
|
|
139
|
+
entity_id: (0, pg_core_1.uuid)('entity_id').notNull(),
|
|
140
|
+
email: (0, pg_core_1.varchar)('email', { length: 255 }).notNull(),
|
|
141
|
+
role: (0, pg_core_1.varchar)('role', { length: 20 }).notNull(),
|
|
142
|
+
status: (0, pg_core_1.varchar)('status', { length: 20 }).notNull().default('pending'),
|
|
143
|
+
invited_by_user_id: (0, pg_core_1.uuid)('invited_by_user_id').notNull(),
|
|
144
|
+
token: (0, pg_core_1.varchar)('token', { length: 64 }).notNull().unique(),
|
|
145
|
+
expires_at: (0, pg_core_1.timestamp)('expires_at', { withTimezone: true }).notNull(),
|
|
146
|
+
accepted_at: (0, pg_core_1.timestamp)('accepted_at', { withTimezone: true }),
|
|
147
|
+
created_at: (0, pg_core_1.timestamp)('created_at', { withTimezone: true }).defaultNow(),
|
|
148
|
+
updated_at: (0, pg_core_1.timestamp)('updated_at', { withTimezone: true }).defaultNow(),
|
|
149
|
+
}, (table) => ({
|
|
150
|
+
tokenIdx: (0, pg_core_1.uniqueIndex)(`${indexPrefix}_entity_invitations_token_idx`).on(table.token),
|
|
151
|
+
entityIdx: (0, pg_core_1.index)(`${indexPrefix}_entity_invitations_entity_idx`).on(table.entity_id),
|
|
152
|
+
emailIdx: (0, pg_core_1.index)(`${indexPrefix}_entity_invitations_email_idx`).on(table.email),
|
|
153
|
+
statusIdx: (0, pg_core_1.index)(`${indexPrefix}_entity_invitations_status_idx`).on(table.status),
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
156
|
+
// ========================================
|
|
157
|
+
// DEFAULT TABLES (Public Schema)
|
|
158
|
+
// ========================================
|
|
159
|
+
/** Default entities table for public schema */
|
|
160
|
+
exports.entities = (0, pg_core_1.pgTable)('entities', {
|
|
161
|
+
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
|
|
162
|
+
entity_slug: (0, pg_core_1.varchar)('entity_slug', { length: 12 }).notNull().unique(),
|
|
163
|
+
entity_type: (0, pg_core_1.varchar)('entity_type', { length: 20 }).notNull(),
|
|
164
|
+
display_name: (0, pg_core_1.varchar)('display_name', { length: 255 }).notNull(),
|
|
165
|
+
description: (0, pg_core_1.text)('description'),
|
|
166
|
+
avatar_url: (0, pg_core_1.text)('avatar_url'),
|
|
167
|
+
owner_user_id: (0, pg_core_1.uuid)('owner_user_id').notNull(),
|
|
168
|
+
created_at: (0, pg_core_1.timestamp)('created_at', { withTimezone: true }).defaultNow(),
|
|
169
|
+
updated_at: (0, pg_core_1.timestamp)('updated_at', { withTimezone: true }).defaultNow(),
|
|
170
|
+
}, (table) => ({
|
|
171
|
+
slugIdx: (0, pg_core_1.uniqueIndex)('entities_slug_idx').on(table.entity_slug),
|
|
172
|
+
ownerIdx: (0, pg_core_1.index)('entities_owner_idx').on(table.owner_user_id),
|
|
173
|
+
typeIdx: (0, pg_core_1.index)('entities_type_idx').on(table.entity_type),
|
|
174
|
+
}));
|
|
175
|
+
/** Default entity_members table for public schema */
|
|
176
|
+
exports.entityMembers = (0, pg_core_1.pgTable)('entity_members', {
|
|
177
|
+
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
|
|
178
|
+
entity_id: (0, pg_core_1.uuid)('entity_id').notNull(),
|
|
179
|
+
user_id: (0, pg_core_1.uuid)('user_id').notNull(),
|
|
180
|
+
role: (0, pg_core_1.varchar)('role', { length: 20 }).notNull(),
|
|
181
|
+
joined_at: (0, pg_core_1.timestamp)('joined_at', { withTimezone: true }).defaultNow(),
|
|
182
|
+
created_at: (0, pg_core_1.timestamp)('created_at', { withTimezone: true }).defaultNow(),
|
|
183
|
+
updated_at: (0, pg_core_1.timestamp)('updated_at', { withTimezone: true }).defaultNow(),
|
|
184
|
+
}, (table) => ({
|
|
185
|
+
entityUserUniqueIdx: (0, pg_core_1.uniqueIndex)('entity_members_entity_user_idx').on(table.entity_id, table.user_id),
|
|
186
|
+
entityIdx: (0, pg_core_1.index)('entity_members_entity_idx').on(table.entity_id),
|
|
187
|
+
userIdx: (0, pg_core_1.index)('entity_members_user_idx').on(table.user_id),
|
|
188
|
+
}));
|
|
189
|
+
/** Default entity_invitations table for public schema */
|
|
190
|
+
exports.entityInvitations = (0, pg_core_1.pgTable)('entity_invitations', {
|
|
191
|
+
id: (0, pg_core_1.uuid)('id').primaryKey().defaultRandom(),
|
|
192
|
+
entity_id: (0, pg_core_1.uuid)('entity_id').notNull(),
|
|
193
|
+
email: (0, pg_core_1.varchar)('email', { length: 255 }).notNull(),
|
|
194
|
+
role: (0, pg_core_1.varchar)('role', { length: 20 }).notNull(),
|
|
195
|
+
status: (0, pg_core_1.varchar)('status', { length: 20 }).notNull().default('pending'),
|
|
196
|
+
invited_by_user_id: (0, pg_core_1.uuid)('invited_by_user_id').notNull(),
|
|
197
|
+
token: (0, pg_core_1.varchar)('token', { length: 64 }).notNull().unique(),
|
|
198
|
+
expires_at: (0, pg_core_1.timestamp)('expires_at', { withTimezone: true }).notNull(),
|
|
199
|
+
accepted_at: (0, pg_core_1.timestamp)('accepted_at', { withTimezone: true }),
|
|
200
|
+
created_at: (0, pg_core_1.timestamp)('created_at', { withTimezone: true }).defaultNow(),
|
|
201
|
+
updated_at: (0, pg_core_1.timestamp)('updated_at', { withTimezone: true }).defaultNow(),
|
|
202
|
+
}, (table) => ({
|
|
203
|
+
tokenIdx: (0, pg_core_1.uniqueIndex)('entity_invitations_token_idx').on(table.token),
|
|
204
|
+
entityIdx: (0, pg_core_1.index)('entity_invitations_entity_idx').on(table.entity_id),
|
|
205
|
+
emailIdx: (0, pg_core_1.index)('entity_invitations_email_idx').on(table.email),
|
|
206
|
+
statusIdx: (0, pg_core_1.index)('entity_invitations_status_idx').on(table.status),
|
|
207
|
+
}));
|
|
208
|
+
// ========================================
|
|
209
|
+
// INITIALIZATION FUNCTIONS
|
|
210
|
+
// ========================================
|
|
211
|
+
/**
|
|
212
|
+
* Initialize all entity tables in the database.
|
|
213
|
+
*
|
|
214
|
+
* @param client - postgres-js client instance
|
|
215
|
+
* @param schemaName - PostgreSQL schema name (null for public)
|
|
216
|
+
* @param indexPrefix - Prefix for index names
|
|
217
|
+
*/
|
|
218
|
+
async function initEntityTables(client, schemaName, indexPrefix) {
|
|
219
|
+
const prefix = schemaName ? `${schemaName}.` : '';
|
|
220
|
+
// Create entities table
|
|
221
|
+
await client.unsafe(`
|
|
222
|
+
CREATE TABLE IF NOT EXISTS ${prefix}entities (
|
|
223
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
224
|
+
entity_slug VARCHAR(12) NOT NULL UNIQUE,
|
|
225
|
+
entity_type VARCHAR(20) NOT NULL CHECK (entity_type IN ('personal', 'organization')),
|
|
226
|
+
display_name VARCHAR(255) NOT NULL,
|
|
227
|
+
description TEXT,
|
|
228
|
+
avatar_url TEXT,
|
|
229
|
+
owner_user_id UUID NOT NULL,
|
|
230
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
231
|
+
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
232
|
+
)
|
|
233
|
+
`);
|
|
234
|
+
await client.unsafe(`
|
|
235
|
+
CREATE UNIQUE INDEX IF NOT EXISTS ${indexPrefix}_entities_slug_idx
|
|
236
|
+
ON ${prefix}entities (entity_slug)
|
|
237
|
+
`);
|
|
238
|
+
await client.unsafe(`
|
|
239
|
+
CREATE INDEX IF NOT EXISTS ${indexPrefix}_entities_owner_idx
|
|
240
|
+
ON ${prefix}entities (owner_user_id)
|
|
241
|
+
`);
|
|
242
|
+
await client.unsafe(`
|
|
243
|
+
CREATE INDEX IF NOT EXISTS ${indexPrefix}_entities_type_idx
|
|
244
|
+
ON ${prefix}entities (entity_type)
|
|
245
|
+
`);
|
|
246
|
+
// Create entity_members table
|
|
247
|
+
await client.unsafe(`
|
|
248
|
+
CREATE TABLE IF NOT EXISTS ${prefix}entity_members (
|
|
249
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
250
|
+
entity_id UUID NOT NULL REFERENCES ${prefix}entities(id) ON DELETE CASCADE,
|
|
251
|
+
user_id UUID NOT NULL,
|
|
252
|
+
role VARCHAR(20) NOT NULL CHECK (role IN ('admin', 'manager', 'viewer')),
|
|
253
|
+
joined_at TIMESTAMPTZ DEFAULT NOW(),
|
|
254
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
255
|
+
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
|
256
|
+
UNIQUE(entity_id, user_id)
|
|
257
|
+
)
|
|
258
|
+
`);
|
|
259
|
+
await client.unsafe(`
|
|
260
|
+
CREATE UNIQUE INDEX IF NOT EXISTS ${indexPrefix}_entity_members_entity_user_idx
|
|
261
|
+
ON ${prefix}entity_members (entity_id, user_id)
|
|
262
|
+
`);
|
|
263
|
+
await client.unsafe(`
|
|
264
|
+
CREATE INDEX IF NOT EXISTS ${indexPrefix}_entity_members_entity_idx
|
|
265
|
+
ON ${prefix}entity_members (entity_id)
|
|
266
|
+
`);
|
|
267
|
+
await client.unsafe(`
|
|
268
|
+
CREATE INDEX IF NOT EXISTS ${indexPrefix}_entity_members_user_idx
|
|
269
|
+
ON ${prefix}entity_members (user_id)
|
|
270
|
+
`);
|
|
271
|
+
// Create entity_invitations table
|
|
272
|
+
await client.unsafe(`
|
|
273
|
+
CREATE TABLE IF NOT EXISTS ${prefix}entity_invitations (
|
|
274
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
275
|
+
entity_id UUID NOT NULL REFERENCES ${prefix}entities(id) ON DELETE CASCADE,
|
|
276
|
+
email VARCHAR(255) NOT NULL,
|
|
277
|
+
role VARCHAR(20) NOT NULL CHECK (role IN ('admin', 'manager', 'viewer')),
|
|
278
|
+
status VARCHAR(20) NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'accepted', 'declined', 'expired')),
|
|
279
|
+
invited_by_user_id UUID NOT NULL,
|
|
280
|
+
token VARCHAR(64) NOT NULL UNIQUE,
|
|
281
|
+
expires_at TIMESTAMPTZ NOT NULL,
|
|
282
|
+
accepted_at TIMESTAMPTZ,
|
|
283
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
284
|
+
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
285
|
+
)
|
|
286
|
+
`);
|
|
287
|
+
await client.unsafe(`
|
|
288
|
+
CREATE UNIQUE INDEX IF NOT EXISTS ${indexPrefix}_entity_invitations_token_idx
|
|
289
|
+
ON ${prefix}entity_invitations (token)
|
|
290
|
+
`);
|
|
291
|
+
await client.unsafe(`
|
|
292
|
+
CREATE INDEX IF NOT EXISTS ${indexPrefix}_entity_invitations_entity_idx
|
|
293
|
+
ON ${prefix}entity_invitations (entity_id)
|
|
294
|
+
`);
|
|
295
|
+
await client.unsafe(`
|
|
296
|
+
CREATE INDEX IF NOT EXISTS ${indexPrefix}_entity_invitations_email_idx
|
|
297
|
+
ON ${prefix}entity_invitations (email)
|
|
298
|
+
`);
|
|
299
|
+
await client.unsafe(`
|
|
300
|
+
CREATE INDEX IF NOT EXISTS ${indexPrefix}_entity_invitations_status_idx
|
|
301
|
+
ON ${prefix}entity_invitations (status)
|
|
302
|
+
`);
|
|
303
|
+
}
|
|
304
|
+
//# sourceMappingURL=entities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.js","sourceRoot":"","sources":["../../src/schema/entities.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAuBH,kDAwBC;AAKD,8DAwBC;AASD,4DAsBC;AAKD,wEAsBC;AASD,oEA+BC;AAKD,gFA+BC;AAoGD,4CAsGC;AA1ZD,iDAQ6B;AAE7B,2CAA2C;AAC3C,iBAAiB;AACjB,2CAA2C;AAE3C;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,MAAW,EAAE,WAAmB;IAClE,OAAO,MAAM,CAAC,KAAK,CACjB,UAAU,EACV;QACE,EAAE,EAAE,IAAA,cAAI,EAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC,aAAa,EAAE;QAC3C,WAAW,EAAE,IAAA,iBAAO,EAAC,aAAa,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE;QACtE,WAAW,EAAE,IAAA,iBAAO,EAAC,aAAa,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE;QAC7D,YAAY,EAAE,IAAA,iBAAO,EAAC,cAAc,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE;QAChE,WAAW,EAAE,IAAA,cAAI,EAAC,aAAa,CAAC;QAChC,UAAU,EAAE,IAAA,cAAI,EAAC,YAAY,CAAC;QAC9B,aAAa,EAAE,IAAA,cAAI,EAAC,eAAe,CAAC,CAAC,OAAO,EAAE;QAC9C,UAAU,EAAE,IAAA,mBAAS,EAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,UAAU,EAAE;QACxE,UAAU,EAAE,IAAA,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;SACnC,MAAM;GACZ,CAAC,CAAC;IAEH,kCAAkC;IAClC,MAAM,MAAM,CAAC,MAAM,CAAC;iCACW,MAAM;;2CAEI,MAAM;;;;;;;;;;;GAW9C,CAAC,CAAC;IAEH,MAAM,MAAM,CAAC,MAAM,CAAC;wCACkB,WAAW;SAC1C,MAAM;GACZ,CAAC,CAAC;IAEH,MAAM,MAAM,CAAC,MAAM,CAAC;iCACW,WAAW;SACnC,MAAM;GACZ,CAAC,CAAC;IAEH,MAAM,MAAM,CAAC,MAAM,CAAC;iCACW,WAAW;SACnC,MAAM;GACZ,CAAC,CAAC;IAEH,MAAM,MAAM,CAAC,MAAM,CAAC;iCACW,WAAW;SACnC,MAAM;GACZ,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Internal Type Definitions for Entity Service
|
|
4
|
+
* @description Types used internally by the entity service helpers
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ROLE_PERMISSIONS = exports.InvitationStatus = exports.EntityRole = exports.EntityType = void 0;
|
|
8
|
+
// Re-export enums as values (not just types) so they can be used at runtime
|
|
9
|
+
var types_1 = require("@sudobility/types");
|
|
10
|
+
Object.defineProperty(exports, "EntityType", { enumerable: true, get: function () { return types_1.EntityType; } });
|
|
11
|
+
Object.defineProperty(exports, "EntityRole", { enumerable: true, get: function () { return types_1.EntityRole; } });
|
|
12
|
+
Object.defineProperty(exports, "InvitationStatus", { enumerable: true, get: function () { return types_1.InvitationStatus; } });
|
|
13
|
+
Object.defineProperty(exports, "ROLE_PERMISSIONS", { enumerable: true, get: function () { return types_1.ROLE_PERMISSIONS; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Internal Type Definitions for Entity Service
|
|
3
|
+
* @description Types used internally by the entity service helpers
|
|
4
|
+
*/
|
|
5
|
+
import type { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
|
|
6
|
+
export { EntityType, EntityRole, InvitationStatus, ROLE_PERMISSIONS, } from '@sudobility/types';
|
|
7
|
+
export type { Entity, EntityWithRole, EntityMember, EntityMemberUser, EntityInvitation, EntityPermissions, CreateEntityRequest, UpdateEntityRequest, InviteMemberRequest, UpdateMemberRoleRequest, } from '@sudobility/types';
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for entity helpers.
|
|
10
|
+
* Provides database connection and table references.
|
|
11
|
+
*/
|
|
12
|
+
export interface EntityHelperConfig {
|
|
13
|
+
/** Drizzle database instance */
|
|
14
|
+
db: PostgresJsDatabase<any>;
|
|
15
|
+
/** Entities table reference */
|
|
16
|
+
entitiesTable: any;
|
|
17
|
+
/** Entity members table reference */
|
|
18
|
+
membersTable: any;
|
|
19
|
+
/** Users table reference (for joins) */
|
|
20
|
+
usersTable: any;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Configuration for invitation helper.
|
|
24
|
+
* Extends entity config with invitation table.
|
|
25
|
+
*/
|
|
26
|
+
export interface InvitationHelperConfig extends EntityHelperConfig {
|
|
27
|
+
/** Entity invitations table reference */
|
|
28
|
+
invitationsTable: any;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Result of entity operations.
|
|
32
|
+
*/
|
|
33
|
+
export interface EntityOperationResult<T> {
|
|
34
|
+
success: boolean;
|
|
35
|
+
data?: T;
|
|
36
|
+
error?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Options for listing entities.
|
|
40
|
+
*/
|
|
41
|
+
export interface ListEntitiesOptions {
|
|
42
|
+
/** Include only entities of this type */
|
|
43
|
+
entityType?: 'personal' | 'organization';
|
|
44
|
+
/** Maximum number of results */
|
|
45
|
+
limit?: number;
|
|
46
|
+
/** Offset for pagination */
|
|
47
|
+
offset?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Options for listing members.
|
|
51
|
+
*/
|
|
52
|
+
export interface ListMembersOptions {
|
|
53
|
+
/** Filter by role */
|
|
54
|
+
role?: 'admin' | 'manager' | 'viewer';
|
|
55
|
+
/** Maximum number of results */
|
|
56
|
+
limit?: number;
|
|
57
|
+
/** Offset for pagination */
|
|
58
|
+
offset?: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Options for listing invitations.
|
|
62
|
+
*/
|
|
63
|
+
export interface ListInvitationsOptions {
|
|
64
|
+
/** Filter by status */
|
|
65
|
+
status?: 'pending' | 'accepted' | 'declined' | 'expired';
|
|
66
|
+
/** Maximum number of results */
|
|
67
|
+
limit?: number;
|
|
68
|
+
/** Offset for pagination */
|
|
69
|
+
offset?: number;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGlE,OAAO,EACL,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EACV,MAAM,EACN,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAM3B;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,gCAAgC;IAChC,EAAE,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAC5B,+BAA+B;IAC/B,aAAa,EAAE,GAAG,CAAC;IACnB,qCAAqC;IACrC,YAAY,EAAE,GAAG,CAAC;IAClB,wCAAwC;IACxC,UAAU,EAAE,GAAG,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAuB,SAAQ,kBAAkB;IAChE,yCAAyC;IACzC,gBAAgB,EAAE,GAAG,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,yCAAyC;IACzC,UAAU,CAAC,EAAE,UAAU,GAAG,cAAc,CAAC;IACzC,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,qBAAqB;IACrB,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;IACtC,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,uBAAuB;IACvB,MAAM,CAAC,EAAE,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;IACzD,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Internal Type Definitions for Entity Service
|
|
4
|
+
* @description Types used internally by the entity service helpers
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ROLE_PERMISSIONS = exports.InvitationStatus = exports.EntityRole = exports.EntityType = void 0;
|
|
8
|
+
// Re-export enums as values (not just types) so they can be used at runtime
|
|
9
|
+
var types_1 = require("@sudobility/types");
|
|
10
|
+
Object.defineProperty(exports, "EntityType", { enumerable: true, get: function () { return types_1.EntityType; } });
|
|
11
|
+
Object.defineProperty(exports, "EntityRole", { enumerable: true, get: function () { return types_1.EntityRole; } });
|
|
12
|
+
Object.defineProperty(exports, "InvitationStatus", { enumerable: true, get: function () { return types_1.InvitationStatus; } });
|
|
13
|
+
Object.defineProperty(exports, "ROLE_PERMISSIONS", { enumerable: true, get: function () { return types_1.ROLE_PERMISSIONS; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,4EAA4E;AAC5E,2CAK2B;AAJzB,mGAAA,UAAU,OAAA;AACV,mGAAA,UAAU,OAAA;AACV,yGAAA,gBAAgB,OAAA;AAChB,yGAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Utility Exports
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./slug-generator"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Utility Exports
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./slug-generator"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,mDAAiC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Entity Slug Generation Utilities
|
|
4
|
+
* @description Functions for generating unique entity slugs and invitation tokens
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.generateEntitySlug = generateEntitySlug;
|
|
8
|
+
exports.generateInvitationToken = generateInvitationToken;
|
|
9
|
+
exports.normalizeSlug = normalizeSlug;
|
|
10
|
+
exports.validateSlug = validateSlug;
|
|
11
|
+
exports.generateUniqueSlug = generateUniqueSlug;
|
|
12
|
+
exports.calculateInvitationExpiry = calculateInvitationExpiry;
|
|
13
|
+
/** Characters allowed in entity slugs (lowercase alphanumeric) */
|
|
14
|
+
const SLUG_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
15
|
+
/** Default length for generated entity slugs */
|
|
16
|
+
const DEFAULT_SLUG_LENGTH = 8;
|
|
17
|
+
/** Length for invitation tokens (hex characters) */
|
|
18
|
+
const INVITATION_TOKEN_LENGTH = 32;
|
|
19
|
+
/**
|
|
20
|
+
* Generate a random entity slug.
|
|
21
|
+
* @param length - Length of the slug (default 8, max 12)
|
|
22
|
+
* @returns A random alphanumeric slug
|
|
23
|
+
*/
|
|
24
|
+
function generateEntitySlug(length = DEFAULT_SLUG_LENGTH) {
|
|
25
|
+
const actualLength = Math.min(Math.max(length, 8), 12);
|
|
26
|
+
let slug = '';
|
|
27
|
+
for (let i = 0; i < actualLength; i++) {
|
|
28
|
+
slug += SLUG_CHARS[Math.floor(Math.random() * SLUG_CHARS.length)];
|
|
29
|
+
}
|
|
30
|
+
return slug;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Generate a unique invitation token.
|
|
34
|
+
* @returns A 64-character hex string
|
|
35
|
+
*/
|
|
36
|
+
function generateInvitationToken() {
|
|
37
|
+
const bytes = new Uint8Array(INVITATION_TOKEN_LENGTH);
|
|
38
|
+
crypto.getRandomValues(bytes);
|
|
39
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Normalize a user-provided slug to valid format.
|
|
43
|
+
* Converts to lowercase and removes invalid characters.
|
|
44
|
+
* @param input - The user-provided slug
|
|
45
|
+
* @returns Normalized slug
|
|
46
|
+
*/
|
|
47
|
+
function normalizeSlug(input) {
|
|
48
|
+
return input
|
|
49
|
+
.toLowerCase()
|
|
50
|
+
.replace(/[^a-z0-9]/g, '')
|
|
51
|
+
.slice(0, 12);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Validate that a slug meets the requirements.
|
|
55
|
+
* @param slug - The slug to validate
|
|
56
|
+
* @returns Whether the slug is valid
|
|
57
|
+
*/
|
|
58
|
+
function validateSlug(slug) {
|
|
59
|
+
return /^[a-z0-9]{8,12}$/.test(slug);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Generate a slug with a numeric suffix to avoid collisions.
|
|
63
|
+
* @param baseSlug - The base slug to append suffix to
|
|
64
|
+
* @param existingSlugs - Set of existing slugs to avoid
|
|
65
|
+
* @returns A unique slug with suffix if needed
|
|
66
|
+
*/
|
|
67
|
+
function generateUniqueSlug(baseSlug, existingSlugs) {
|
|
68
|
+
const normalized = normalizeSlug(baseSlug).slice(0, 8);
|
|
69
|
+
if (!existingSlugs.has(normalized) && validateSlug(normalized)) {
|
|
70
|
+
return normalized;
|
|
71
|
+
}
|
|
72
|
+
// Try adding numeric suffixes
|
|
73
|
+
for (let i = 1; i < 1000; i++) {
|
|
74
|
+
const suffix = i.toString();
|
|
75
|
+
const candidate = (normalized.slice(0, 12 - suffix.length) + suffix).slice(0, 12);
|
|
76
|
+
if (!existingSlugs.has(candidate) && validateSlug(candidate)) {
|
|
77
|
+
return candidate;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Fall back to random slug
|
|
81
|
+
return generateEntitySlug();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Calculate invitation expiry date (7 days from now).
|
|
85
|
+
* @returns ISO 8601 string for expiry date
|
|
86
|
+
*/
|
|
87
|
+
function calculateInvitationExpiry() {
|
|
88
|
+
const expiryDate = new Date();
|
|
89
|
+
expiryDate.setDate(expiryDate.getDate() + 7);
|
|
90
|
+
return expiryDate.toISOString();
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=slug-generator.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Entity Slug Generation Utilities
|
|
3
|
+
* @description Functions for generating unique entity slugs and invitation tokens
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Generate a random entity slug.
|
|
7
|
+
* @param length - Length of the slug (default 8, max 12)
|
|
8
|
+
* @returns A random alphanumeric slug
|
|
9
|
+
*/
|
|
10
|
+
export declare function generateEntitySlug(length?: number): string;
|
|
11
|
+
/**
|
|
12
|
+
* Generate a unique invitation token.
|
|
13
|
+
* @returns A 64-character hex string
|
|
14
|
+
*/
|
|
15
|
+
export declare function generateInvitationToken(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Normalize a user-provided slug to valid format.
|
|
18
|
+
* Converts to lowercase and removes invalid characters.
|
|
19
|
+
* @param input - The user-provided slug
|
|
20
|
+
* @returns Normalized slug
|
|
21
|
+
*/
|
|
22
|
+
export declare function normalizeSlug(input: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Validate that a slug meets the requirements.
|
|
25
|
+
* @param slug - The slug to validate
|
|
26
|
+
* @returns Whether the slug is valid
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateSlug(slug: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Generate a slug with a numeric suffix to avoid collisions.
|
|
31
|
+
* @param baseSlug - The base slug to append suffix to
|
|
32
|
+
* @param existingSlugs - Set of existing slugs to avoid
|
|
33
|
+
* @returns A unique slug with suffix if needed
|
|
34
|
+
*/
|
|
35
|
+
export declare function generateUniqueSlug(baseSlug: string, existingSlugs: Set<string>): string;
|
|
36
|
+
/**
|
|
37
|
+
* Calculate invitation expiry date (7 days from now).
|
|
38
|
+
* @returns ISO 8601 string for expiry date
|
|
39
|
+
*/
|
|
40
|
+
export declare function calculateInvitationExpiry(): string;
|
|
41
|
+
//# sourceMappingURL=slug-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slug-generator.d.ts","sourceRoot":"","sources":["../../src/utils/slug-generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,GAAE,MAA4B,GAAG,MAAM,CAO/E;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAIhD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKnD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,GACzB,MAAM,CAqBR;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAIlD"}
|