@igstack/app-catalog-backend-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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.d.ts +1934 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +2539 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +84 -0
  7. package/prisma/migrations/20250526183023_init/migration.sql +71 -0
  8. package/prisma/migrations/migration_lock.toml +3 -0
  9. package/prisma/schema.prisma +149 -0
  10. package/src/__tests__/dummy.test.ts +7 -0
  11. package/src/db/client.ts +42 -0
  12. package/src/db/index.ts +21 -0
  13. package/src/db/syncAppCatalog.ts +312 -0
  14. package/src/db/tableSyncMagazine.ts +32 -0
  15. package/src/db/tableSyncPrismaAdapter.ts +203 -0
  16. package/src/index.ts +126 -0
  17. package/src/middleware/backendResolver.ts +42 -0
  18. package/src/middleware/createEhMiddleware.ts +171 -0
  19. package/src/middleware/database.ts +62 -0
  20. package/src/middleware/featureRegistry.ts +173 -0
  21. package/src/middleware/index.ts +43 -0
  22. package/src/middleware/types.ts +202 -0
  23. package/src/modules/admin/chat/createAdminChatHandler.ts +152 -0
  24. package/src/modules/admin/chat/createDatabaseTools.ts +261 -0
  25. package/src/modules/appCatalog/service.ts +130 -0
  26. package/src/modules/appCatalogAdmin/appCatalogAdminRouter.ts +187 -0
  27. package/src/modules/appCatalogAdmin/catalogBackupController.ts +213 -0
  28. package/src/modules/approvalMethod/approvalMethodRouter.ts +169 -0
  29. package/src/modules/approvalMethod/slugUtils.ts +17 -0
  30. package/src/modules/approvalMethod/syncApprovalMethods.ts +38 -0
  31. package/src/modules/assets/assetRestController.ts +271 -0
  32. package/src/modules/assets/assetUtils.ts +114 -0
  33. package/src/modules/assets/screenshotRestController.ts +195 -0
  34. package/src/modules/assets/screenshotRouter.ts +112 -0
  35. package/src/modules/assets/syncAssets.ts +277 -0
  36. package/src/modules/assets/upsertAsset.ts +46 -0
  37. package/src/modules/auth/auth.ts +51 -0
  38. package/src/modules/auth/authProviders.ts +40 -0
  39. package/src/modules/auth/authRouter.ts +75 -0
  40. package/src/modules/auth/authorizationUtils.ts +132 -0
  41. package/src/modules/auth/devMockUserUtils.ts +49 -0
  42. package/src/modules/auth/registerAuthRoutes.ts +33 -0
  43. package/src/modules/icons/iconRestController.ts +171 -0
  44. package/src/modules/icons/iconRouter.ts +180 -0
  45. package/src/modules/icons/iconService.ts +73 -0
  46. package/src/modules/icons/iconUtils.ts +46 -0
  47. package/src/prisma-json-types.d.ts +34 -0
  48. package/src/server/controller.ts +47 -0
  49. package/src/server/ehStaticControllerContract.ts +19 -0
  50. package/src/server/ehTrpcContext.ts +26 -0
  51. package/src/server/trpcSetup.ts +89 -0
  52. package/src/types/backend/api.ts +73 -0
  53. package/src/types/backend/common.ts +10 -0
  54. package/src/types/backend/companySpecificBackend.ts +5 -0
  55. package/src/types/backend/dataSources.ts +25 -0
  56. package/src/types/backend/deployments.ts +40 -0
  57. package/src/types/common/app/appTypes.ts +13 -0
  58. package/src/types/common/app/ui/appUiTypes.ts +12 -0
  59. package/src/types/common/appCatalogTypes.ts +65 -0
  60. package/src/types/common/approvalMethodTypes.ts +149 -0
  61. package/src/types/common/env/envTypes.ts +7 -0
  62. package/src/types/common/resourceTypes.ts +8 -0
  63. package/src/types/common/sharedTypes.ts +5 -0
  64. package/src/types/index.ts +21 -0
@@ -0,0 +1,261 @@
1
+ import type { Tool } from 'ai'
2
+ import { z } from 'zod'
3
+ import { getDbClient } from '../../../db'
4
+
5
+ /**
6
+ * Generic interface for executing raw SQL queries.
7
+ * Can be implemented with Prisma's $queryRawUnsafe or any other SQL client.
8
+ */
9
+ export interface DatabaseClient {
10
+ /** Execute a SELECT query and return results */
11
+ query: <T = unknown>(sql: string) => Promise<Array<T>>
12
+ /** Execute an INSERT/UPDATE/DELETE and return affected row count */
13
+ execute: (sql: string) => Promise<{ affectedRows: number }>
14
+ /** Get list of tables in the database */
15
+ getTables: () => Promise<Array<string>>
16
+ /** Get columns for a specific table */
17
+ getColumns: (
18
+ tableName: string,
19
+ ) => Promise<Array<{ name: string; type: string; nullable: boolean }>>
20
+ }
21
+
22
+ /**
23
+ * Creates a DatabaseClient from a Prisma client.
24
+ */
25
+ export function createPrismaDatabaseClient(prisma: {
26
+ $queryRawUnsafe: <T>(sql: string) => Promise<T>
27
+ $executeRawUnsafe: (sql: string) => Promise<number>
28
+ }): DatabaseClient {
29
+ return {
30
+ query: async <T = unknown>(sql: string): Promise<Array<T>> => {
31
+ const result = await prisma.$queryRawUnsafe<Array<T>>(sql)
32
+ return result
33
+ },
34
+ execute: async (sql: string) => {
35
+ const affectedRows = await prisma.$executeRawUnsafe(sql)
36
+ return { affectedRows }
37
+ },
38
+ getTables: async () => {
39
+ const tables = await prisma.$queryRawUnsafe<Array<{ tablename: string }>>(
40
+ `SELECT tablename FROM pg_tables WHERE schemaname = 'public'`,
41
+ )
42
+ return tables.map((t) => t.tablename)
43
+ },
44
+ getColumns: async (tableName: string) => {
45
+ const columns = await prisma.$queryRawUnsafe<
46
+ Array<{
47
+ column_name: string
48
+ data_type: string
49
+ is_nullable: string
50
+ }>
51
+ >(
52
+ `SELECT column_name, data_type, is_nullable
53
+ FROM information_schema.columns
54
+ WHERE table_name = '${tableName}' AND table_schema = 'public'`,
55
+ )
56
+ return columns.map((c) => ({
57
+ name: c.column_name,
58
+ type: c.data_type,
59
+ nullable: c.is_nullable === 'YES',
60
+ }))
61
+ },
62
+ }
63
+ }
64
+
65
+ // Define zod schemas for tool parameters
66
+ const querySchema = z.object({
67
+ sql: z.string().describe('The SELECT SQL query to execute'),
68
+ })
69
+
70
+ const modifySchema = z.object({
71
+ sql: z
72
+ .string()
73
+ .describe('The INSERT, UPDATE, or DELETE SQL query to execute'),
74
+ confirmed: z
75
+ .boolean()
76
+ .describe('Must be true to execute destructive operations'),
77
+ })
78
+
79
+ const schemaParamsSchema = z.object({
80
+ tableName: z
81
+ .string()
82
+ .optional()
83
+ .describe(
84
+ 'Specific table name to get columns for. If not provided, returns list of all tables.',
85
+ ),
86
+ })
87
+
88
+ type QueryInput = z.infer<typeof querySchema>
89
+ type ModifyInput = z.infer<typeof modifySchema>
90
+ type SchemaInput = z.infer<typeof schemaParamsSchema>
91
+
92
+ /**
93
+ * Creates a DatabaseClient using the internal backend-core Prisma client.
94
+ * This is a convenience function for apps that don't need to pass their own Prisma client.
95
+ */
96
+ function createInternalDatabaseClient(): DatabaseClient {
97
+ return createPrismaDatabaseClient(getDbClient())
98
+ }
99
+
100
+ /**
101
+ * Creates AI tools for generic database access.
102
+ *
103
+ * The AI uses these internally - users interact via natural language.
104
+ * Results are formatted as tables by the AI based on the system prompt.
105
+ * Uses the internal backend-core Prisma client automatically.
106
+ */
107
+ export function createDatabaseTools(): Record<string, Tool> {
108
+ const db = createInternalDatabaseClient()
109
+ const queryDatabase: Tool<QueryInput, unknown> = {
110
+ description: `Execute a SELECT query to read data from the database.
111
+ Use this to list, search, or filter records from any table.
112
+ Always use double quotes around table and column names for PostgreSQL (e.g., SELECT * FROM "App").
113
+ Return results will be formatted as a table for the user.`,
114
+ inputSchema: querySchema,
115
+ execute: async ({ sql }) => {
116
+ console.log(`Executing ${sql}`)
117
+ // Safety check - only allow SELECT
118
+ const normalizedSql = sql.trim().toUpperCase()
119
+ if (!normalizedSql.startsWith('SELECT')) {
120
+ return {
121
+ error:
122
+ 'Only SELECT queries are allowed with queryDatabase. Use modifyDatabase for changes.',
123
+ }
124
+ }
125
+ try {
126
+ const results = await db.query(sql)
127
+ return {
128
+ success: true,
129
+ rowCount: Array.isArray(results) ? results.length : 0,
130
+ data: results,
131
+ }
132
+ } catch (error) {
133
+ return {
134
+ success: false,
135
+ error: error instanceof Error ? error.message : 'Query failed',
136
+ }
137
+ }
138
+ },
139
+ }
140
+
141
+ const modifyDatabase: Tool<ModifyInput, unknown> = {
142
+ description: `Execute an INSERT, UPDATE, or DELETE query to modify data.
143
+ Use double quotes around table and column names for PostgreSQL.
144
+ IMPORTANT: Always ask for user confirmation before executing. Set confirmed=true only after user confirms.
145
+ For UPDATE/DELETE, always include a WHERE clause to avoid affecting all rows.`,
146
+ inputSchema: modifySchema,
147
+ execute: async ({ sql, confirmed }) => {
148
+ if (!confirmed) {
149
+ return {
150
+ needsConfirmation: true,
151
+ message: 'Please confirm you want to execute this operation.',
152
+ sql,
153
+ }
154
+ }
155
+
156
+ // Safety check - don't allow SELECT here
157
+ const normalizedSql = sql.trim().toUpperCase()
158
+ if (normalizedSql.startsWith('SELECT')) {
159
+ return { error: 'Use queryDatabase for SELECT queries.' }
160
+ }
161
+
162
+ // Extra safety - warn about missing WHERE on UPDATE/DELETE
163
+ if (
164
+ (normalizedSql.startsWith('UPDATE') ||
165
+ normalizedSql.startsWith('DELETE')) &&
166
+ !normalizedSql.includes('WHERE')
167
+ ) {
168
+ return {
169
+ error:
170
+ 'UPDATE and DELETE queries must include a WHERE clause for safety.',
171
+ sql,
172
+ }
173
+ }
174
+
175
+ try {
176
+ const result = await db.execute(sql)
177
+ return {
178
+ success: true,
179
+ affectedRows: result.affectedRows,
180
+ message: `Operation completed. ${result.affectedRows} row(s) affected.`,
181
+ }
182
+ } catch (error) {
183
+ return {
184
+ success: false,
185
+ error: error instanceof Error ? error.message : 'Operation failed',
186
+ }
187
+ }
188
+ },
189
+ }
190
+
191
+ const getDatabaseSchema: Tool<SchemaInput, unknown> = {
192
+ description: `Get information about database tables and their columns.
193
+ Use this to understand the database structure before writing queries.
194
+ Call without tableName to list all tables, or with tableName to get columns for a specific table.`,
195
+ inputSchema: schemaParamsSchema,
196
+ execute: async ({ tableName }) => {
197
+ try {
198
+ if (tableName) {
199
+ const columns = await db.getColumns(tableName)
200
+ return {
201
+ success: true,
202
+ table: tableName,
203
+ columns,
204
+ }
205
+ } else {
206
+ const tables = await db.getTables()
207
+ return {
208
+ success: true,
209
+ tables,
210
+ }
211
+ }
212
+ } catch (error) {
213
+ return {
214
+ success: false,
215
+ error:
216
+ error instanceof Error ? error.message : 'Failed to get schema',
217
+ }
218
+ }
219
+ },
220
+ }
221
+
222
+ return {
223
+ queryDatabase,
224
+ modifyDatabase,
225
+ getDatabaseSchema,
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Default system prompt for the database admin assistant.
231
+ * Can be customized or extended.
232
+ */
233
+ export const DEFAULT_ADMIN_SYSTEM_PROMPT = `You are a helpful database admin assistant. You help users view and manage data in the database.
234
+
235
+ IMPORTANT RULES:
236
+ 1. When showing data, ALWAYS format it as a numbered ASCII table so users can reference rows by number
237
+ 2. NEVER show raw SQL to users - just describe what you're doing in plain language
238
+ 3. When users ask to modify data (update, delete, create), ALWAYS confirm before executing
239
+ 4. For updates, show the current value and ask for confirmation before changing
240
+ 5. Keep responses concise and focused on the data
241
+
242
+ FORMATTING EXAMPLE:
243
+ When user asks "show me all apps", respond like:
244
+ "Here are all the apps:
245
+
246
+ | # | ID | Slug | Display Name | Icon |
247
+ |---|----|---------|-----------------| -------|
248
+ | 1 | 1 | portal | Portal | portal |
249
+ | 2 | 2 | admin | Admin Dashboard | admin |
250
+ | 3 | 3 | api | API Service | null |
251
+
252
+ Found 3 apps total."
253
+
254
+ When user says "update row 2 display name to 'Admin Panel'":
255
+ 1. First confirm: "I'll update the app 'Admin Dashboard' (ID: 2) to have display name 'Admin Panel'. Proceed?"
256
+ 2. Only after user confirms, execute the update
257
+ 3. Then show the updated row
258
+
259
+ AVAILABLE TABLES:
260
+ Use getDatabaseSchema tool to discover tables and their columns.
261
+ `
@@ -0,0 +1,130 @@
1
+ import { getDbClient } from '../../db/client'
2
+ import type {
3
+ AppApprovalMethod,
4
+ AppCatalogData,
5
+ AppCategory,
6
+ AppForCatalog,
7
+ GroupingTagDefinition,
8
+ } from '../../types/common/appCatalogTypes'
9
+ import type {
10
+ CustomConfig,
11
+ PersonTeamConfig,
12
+ ServiceConfig,
13
+ } from '../../types/common/approvalMethodTypes'
14
+ import { omit } from 'radashi'
15
+
16
+ function capitalize(word: string): string {
17
+ if (!word) return word
18
+ return word.charAt(0).toUpperCase() + word.slice(1)
19
+ }
20
+
21
+ export async function getGroupingTagDefinitionsFromPrisma(): Promise<
22
+ Array<GroupingTagDefinition>
23
+ > {
24
+ const prisma = getDbClient()
25
+
26
+ // Fetch all apps
27
+ const rows = await prisma.dbAppTagDefinition.findMany()
28
+ return rows.map((row) => omit(row, ['id', 'updatedAt', 'createdAt']))
29
+ }
30
+
31
+ export async function getApprovalMethodsFromPrisma(): Promise<
32
+ Array<AppApprovalMethod>
33
+ > {
34
+ const prisma = getDbClient()
35
+
36
+ // Fetch all apps
37
+ const rows = await prisma.dbApprovalMethod.findMany()
38
+
39
+ return rows.map((row) => {
40
+ // Handle discriminated union by explicitly narrowing based on type
41
+ const baseFields = {
42
+ slug: row.slug,
43
+ displayName: row.displayName,
44
+ }
45
+
46
+ // Provide default empty config if null, as AppApprovalMethod discriminated union requires config
47
+ const config = row.config ?? {}
48
+
49
+ switch (row.type) {
50
+ case 'service':
51
+ return {
52
+ ...baseFields,
53
+ type: 'service',
54
+ config: config as ServiceConfig,
55
+ }
56
+ case 'personTeam':
57
+ return {
58
+ ...baseFields,
59
+ type: 'personTeam',
60
+ config: config as PersonTeamConfig,
61
+ }
62
+ case 'custom':
63
+ return { ...baseFields, type: 'custom', config: config as CustomConfig }
64
+ }
65
+ })
66
+ }
67
+
68
+ export async function getAppsFromPrisma(): Promise<Array<AppForCatalog>> {
69
+ const prisma = getDbClient()
70
+
71
+ // Fetch all apps
72
+ const rows = await prisma.dbAppForCatalog.findMany()
73
+
74
+ return rows.map((row) => {
75
+ const accessRequest =
76
+ row.accessRequest as unknown as AppForCatalog['accessRequest']
77
+ const teams = (row.teams as unknown as Array<string> | null) ?? []
78
+ const tags = (row.tags as unknown as AppForCatalog['tags']) ?? []
79
+ const screenshotIds =
80
+ (row.screenshotIds as unknown as AppForCatalog['screenshotIds']) ?? []
81
+ const notes = row.notes == null ? undefined : row.notes
82
+ const appUrl = row.appUrl == null ? undefined : row.appUrl
83
+ const iconName = row.iconName == null ? undefined : row.iconName
84
+
85
+ return {
86
+ id: row.id,
87
+ slug: row.slug,
88
+ displayName: row.displayName,
89
+ description: row.description,
90
+ accessRequest,
91
+ teams,
92
+ notes,
93
+ tags,
94
+ appUrl,
95
+ iconName,
96
+ screenshotIds,
97
+ }
98
+ })
99
+ }
100
+
101
+ export function deriveCategories(
102
+ apps: Array<AppForCatalog>,
103
+ ): Array<AppCategory> {
104
+ const tagSet = new Set<string>()
105
+ for (const app of apps) {
106
+ for (const tag of app.tags ?? []) {
107
+ const normalized = tag.trim().toLowerCase()
108
+ if (normalized) tagSet.add(normalized)
109
+ }
110
+ }
111
+ const categories: Array<AppCategory> = [{ id: 'all', name: 'All' }]
112
+ for (const tag of Array.from(tagSet).sort()) {
113
+ categories.push({ id: tag, name: capitalize(tag) })
114
+ }
115
+ return categories
116
+ }
117
+
118
+ export async function getAppCatalogData(
119
+ getAppsOptional?: () => Promise<Array<AppForCatalog>>,
120
+ ): Promise<AppCatalogData> {
121
+ const apps = getAppsOptional
122
+ ? await getAppsOptional()
123
+ : await getAppsFromPrisma()
124
+
125
+ return {
126
+ apps,
127
+ tagsDefinitions: await getGroupingTagDefinitionsFromPrisma(),
128
+ approvalMethods: await getApprovalMethodsFromPrisma(),
129
+ }
130
+ }
@@ -0,0 +1,187 @@
1
+ import { z } from 'zod'
2
+ import { getDbClient } from '../../db'
3
+ import { adminProcedure, router } from '../../server/trpcSetup'
4
+ import type { AppAccessRequest } from '../../types'
5
+
6
+ // Zod schema for access method (simplified for now - you can expand this)
7
+ const AccessMethodSchema = z
8
+ .object({
9
+ type: z.enum([
10
+ 'bot',
11
+ 'ticketing',
12
+ 'email',
13
+ 'self-service',
14
+ 'documentation',
15
+ 'manual',
16
+ ]),
17
+ })
18
+ .loose()
19
+
20
+ const AppLinkSchema = z.object({
21
+ displayName: z.string().optional(),
22
+ url: z.url(),
23
+ })
24
+
25
+ // New AppAccessRequest schema
26
+ const AppRoleSchema = z.object({
27
+ name: z.string(),
28
+ description: z.string().optional(),
29
+ })
30
+
31
+ const ApproverContactSchema = z.object({
32
+ displayName: z.string(),
33
+ contact: z.string().optional(),
34
+ })
35
+
36
+ const ApprovalUrlSchema = z.object({
37
+ label: z.string().optional(),
38
+ url: z.url(),
39
+ })
40
+
41
+ const AppAccessRequestSchema = z.object({
42
+ approvalMethodId: z.string(),
43
+ comments: z.string().optional(),
44
+ requestPrompt: z.string().optional(),
45
+ postApprovalInstructions: z.string().optional(),
46
+ roles: z.array(AppRoleSchema).optional(),
47
+ approvers: z.array(ApproverContactSchema).optional(),
48
+ urls: z.array(ApprovalUrlSchema).optional(),
49
+ whoToReachOut: z.string().optional(),
50
+ })
51
+
52
+ const CreateAppForCatalogSchema = z.object({
53
+ slug: z
54
+ .string()
55
+ .min(1)
56
+ .regex(/^[a-z0-9-]+$/, 'Slug must be lowercase alphanumeric with hyphens'),
57
+ displayName: z.string().min(1),
58
+ description: z.string(),
59
+ access: AccessMethodSchema.optional(),
60
+ teams: z.array(z.string()).optional(),
61
+ accessRequest: AppAccessRequestSchema.optional(),
62
+ notes: z.string().optional(),
63
+ tags: z.array(z.string()).optional(),
64
+ appUrl: z.url().optional(),
65
+ links: z.array(AppLinkSchema).optional(),
66
+ iconName: z.string().optional(),
67
+ screenshotIds: z.array(z.string()).optional(),
68
+ })
69
+
70
+ const UpdateAppForCatalogSchema = CreateAppForCatalogSchema.partial().extend({
71
+ id: z.string(),
72
+ })
73
+
74
+ export function createAppCatalogAdminRouter() {
75
+ const prisma = getDbClient()
76
+ return router({
77
+ list: adminProcedure.query(async () => {
78
+ return prisma.dbAppForCatalog.findMany({
79
+ orderBy: { displayName: 'asc' },
80
+ })
81
+ }),
82
+
83
+ getById: adminProcedure
84
+ .input(z.object({ id: z.string() }))
85
+ .query(async ({ input }) => {
86
+ return prisma.dbAppForCatalog.findUnique({
87
+ where: { id: input.id },
88
+ })
89
+ }),
90
+
91
+ getBySlug: adminProcedure
92
+ .input(z.object({ slug: z.string() }))
93
+ .query(async ({ input }) => {
94
+ return prisma.dbAppForCatalog.findUnique({
95
+ where: { slug: input.slug },
96
+ })
97
+ }),
98
+
99
+ create: adminProcedure
100
+ .input(CreateAppForCatalogSchema)
101
+ .mutation(async ({ input }) => {
102
+ // Type assertion needed because Zod's passthrough() creates index signatures
103
+ // that don't structurally match Prisma's typed JSON fields.
104
+ // This is safe because Zod validates the input shape.
105
+ return prisma.dbAppForCatalog.create({
106
+ data: {
107
+ slug: input.slug,
108
+ displayName: input.displayName,
109
+ description: input.description,
110
+ teams: input.teams ?? [],
111
+ accessRequest: input.accessRequest as AppAccessRequest | undefined,
112
+ notes: input.notes,
113
+ tags: input.tags ?? [],
114
+ appUrl: input.appUrl,
115
+ links: input.links as Array<{ displayName?: string; url: string }>,
116
+ iconName: input.iconName,
117
+ screenshotIds: input.screenshotIds ?? [],
118
+ },
119
+ })
120
+ }),
121
+
122
+ update: adminProcedure
123
+ .input(UpdateAppForCatalogSchema)
124
+ .mutation(async ({ input }) => {
125
+ const { id, ...updateData } = input
126
+
127
+ // Type assertion needed because Zod's passthrough() creates index signatures
128
+ return prisma.dbAppForCatalog.update({
129
+ where: { id },
130
+ data: {
131
+ ...(updateData.slug !== undefined && { slug: updateData.slug }),
132
+ ...(updateData.displayName !== undefined && {
133
+ displayName: updateData.displayName,
134
+ }),
135
+ ...(updateData.description !== undefined && {
136
+ description: updateData.description,
137
+ }),
138
+ ...(updateData.teams !== undefined && { teams: updateData.teams }),
139
+ ...(updateData.accessRequest !== undefined && {
140
+ accessRequest: updateData.accessRequest as
141
+ | AppAccessRequest
142
+ | undefined,
143
+ }),
144
+ ...(updateData.notes !== undefined && { notes: updateData.notes }),
145
+ ...(updateData.tags !== undefined && { tags: updateData.tags }),
146
+ ...(updateData.appUrl !== undefined && {
147
+ appUrl: updateData.appUrl,
148
+ }),
149
+ ...(updateData.links !== undefined && {
150
+ links: updateData.links as Array<{
151
+ displayName?: string
152
+ url: string
153
+ }>,
154
+ }),
155
+ ...(updateData.iconName !== undefined && {
156
+ iconName: updateData.iconName,
157
+ }),
158
+ ...(updateData.screenshotIds !== undefined && {
159
+ screenshotIds: updateData.screenshotIds,
160
+ }),
161
+ },
162
+ })
163
+ }),
164
+
165
+ updateScreenshots: adminProcedure
166
+ .input(
167
+ z.object({
168
+ id: z.string(),
169
+ screenshotIds: z.array(z.string()),
170
+ }),
171
+ )
172
+ .mutation(async ({ input }) => {
173
+ return prisma.dbAppForCatalog.update({
174
+ where: { id: input.id },
175
+ data: { screenshotIds: input.screenshotIds },
176
+ })
177
+ }),
178
+
179
+ delete: adminProcedure
180
+ .input(z.object({ id: z.string() }))
181
+ .mutation(async ({ input }) => {
182
+ return prisma.dbAppForCatalog.delete({
183
+ where: { id: input.id },
184
+ })
185
+ }),
186
+ })
187
+ }