serene-core-server 0.1.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 (315) hide show
  1. package/dist/apollo/resolvers/mutations/mailing-lists.d.ts +11 -0
  2. package/dist/apollo/resolvers/mutations/mailing-lists.js +30 -0
  3. package/dist/apollo/resolvers/mutations/user-preferences.d.ts +13 -0
  4. package/dist/apollo/resolvers/mutations/user-preferences.js +31 -0
  5. package/dist/apollo/resolvers/mutations/users.d.ts +28 -0
  6. package/dist/apollo/resolvers/mutations/users.js +44 -0
  7. package/dist/apollo/resolvers/queries/access.d.ts +11 -0
  8. package/dist/apollo/resolvers/queries/access.js +25 -0
  9. package/dist/apollo/resolvers/queries/profile.d.ts +11 -0
  10. package/dist/apollo/resolvers/queries/profile.js +25 -0
  11. package/dist/apollo/resolvers/queries/quotas.d.ts +21 -0
  12. package/dist/apollo/resolvers/queries/quotas.js +25 -0
  13. package/dist/apollo/resolvers/queries/tech.d.ts +5 -0
  14. package/dist/apollo/resolvers/queries/tech.js +35 -0
  15. package/dist/apollo/resolvers/queries/user-preferences.d.ts +5 -0
  16. package/dist/apollo/resolvers/queries/user-preferences.js +33 -0
  17. package/dist/apollo/resolvers/queries/users.d.ts +15 -0
  18. package/dist/apollo/resolvers/queries/users.js +28 -0
  19. package/dist/apollo/resolvers/resolvers.d.ts +20 -0
  20. package/dist/apollo/resolvers/resolvers.js +38 -0
  21. package/dist/apollo/typedefs/typedefs.d.ts +1 -0
  22. package/dist/apollo/typedefs/typedefs.js +142 -0
  23. package/dist/index.d.ts +52 -0
  24. package/dist/index.js +68 -0
  25. package/dist/models/chat/chat-message-created-model.d.ts +17 -0
  26. package/dist/models/chat/chat-message-created-model.js +113 -0
  27. package/dist/models/chat/chat-message-model.d.ts +44 -0
  28. package/dist/models/chat/chat-message-model.js +523 -0
  29. package/dist/models/chat/chat-participant-model.d.ts +39 -0
  30. package/dist/models/chat/chat-participant-model.js +211 -0
  31. package/dist/models/chat/chat-session-model.d.ts +92 -0
  32. package/dist/models/chat/chat-session-model.js +301 -0
  33. package/dist/models/chat/chat-settings-model.d.ts +87 -0
  34. package/dist/models/chat/chat-settings-model.js +261 -0
  35. package/dist/models/feature-flags/feature-flag-model.d.ts +40 -0
  36. package/dist/models/feature-flags/feature-flag-model.js +164 -0
  37. package/dist/models/instances/instance-model.d.ts +93 -0
  38. package/dist/models/instances/instance-model.js +432 -0
  39. package/dist/models/instances/instance-setting-model.d.ts +39 -0
  40. package/dist/models/instances/instance-setting-model.js +193 -0
  41. package/dist/models/mailing-lists/mailing-list-model.d.ts +34 -0
  42. package/dist/models/mailing-lists/mailing-list-model.js +154 -0
  43. package/dist/models/mailing-lists/mailing-list-subscriber-model.d.ts +36 -0
  44. package/dist/models/mailing-lists/mailing-list-subscriber-model.js +152 -0
  45. package/dist/models/quotas/resource-quota-total-model.d.ts +46 -0
  46. package/dist/models/quotas/resource-quota-total-model.js +200 -0
  47. package/dist/models/quotas/resource-quota-usage-model.d.ts +51 -0
  48. package/dist/models/quotas/resource-quota-usage-model.js +181 -0
  49. package/dist/models/tech/rate-limited-api-event-model.d.ts +25 -0
  50. package/dist/models/tech/rate-limited-api-event-model.js +161 -0
  51. package/dist/models/tech/rate-limited-api-model.d.ts +21 -0
  52. package/dist/models/tech/rate-limited-api-model.js +141 -0
  53. package/dist/models/tech/tech-model.d.ts +44 -0
  54. package/dist/models/tech/tech-model.js +268 -0
  55. package/dist/models/tech/tech-provider-api-key-model.d.ts +43 -0
  56. package/dist/models/tech/tech-provider-api-key-model.js +224 -0
  57. package/dist/models/tech/tech-provider-model.d.ts +28 -0
  58. package/dist/models/tech/tech-provider-model.js +197 -0
  59. package/dist/models/users/external-user-integration-model.d.ts +36 -0
  60. package/dist/models/users/external-user-integration-model.js +196 -0
  61. package/dist/models/users/user-error-model.d.ts +54 -0
  62. package/dist/models/users/user-error-model.js +173 -0
  63. package/dist/models/users/user-error-summary-model.d.ts +45 -0
  64. package/dist/models/users/user-error-summary-model.js +172 -0
  65. package/dist/models/users/user-group-member-model.d.ts +41 -0
  66. package/dist/models/users/user-group-member-model.js +193 -0
  67. package/dist/models/users/user-group-model.d.ts +27 -0
  68. package/dist/models/users/user-group-model.js +146 -0
  69. package/dist/models/users/user-model.d.ts +46 -0
  70. package/dist/models/users/user-model.js +153 -0
  71. package/dist/models/users/user-preference-model.d.ts +60 -0
  72. package/dist/models/users/user-preference-model.js +228 -0
  73. package/dist/models/users/user-profile-model.d.ts +58 -0
  74. package/dist/models/users/user-profile-model.js +173 -0
  75. package/dist/prisma.config.d.ts +3 -0
  76. package/dist/prisma.config.js +13 -0
  77. package/dist/services/access/access-service.d.ts +12 -0
  78. package/dist/services/access/access-service.js +44 -0
  79. package/dist/services/access/encrypt-service.d.ts +13 -0
  80. package/dist/services/access/encrypt-service.js +84 -0
  81. package/dist/services/api-usage/api-usage-base-service.d.ts +15 -0
  82. package/dist/services/api-usage/api-usage-base-service.js +75 -0
  83. package/dist/services/console/service.d.ts +7 -0
  84. package/dist/services/console/service.js +70 -0
  85. package/dist/services/db/pg/pg-estimate-size-service.d.ts +16 -0
  86. package/dist/services/db/pg/pg-estimate-size-service.js +90 -0
  87. package/dist/services/files/types.d.ts +6 -0
  88. package/dist/services/files/types.js +2 -0
  89. package/dist/services/files/walk-dir-service.d.ts +8 -0
  90. package/dist/services/files/walk-dir-service.js +94 -0
  91. package/dist/services/locale/countries.d.ts +6 -0
  92. package/dist/services/locale/countries.js +484 -0
  93. package/dist/services/mailing-lists/mailing-list-subscriber-service.d.ts +14 -0
  94. package/dist/services/mailing-lists/mailing-list-subscriber-service.js +45 -0
  95. package/dist/services/process/sleep.d.ts +2 -0
  96. package/dist/services/process/sleep.js +10 -0
  97. package/dist/services/quotas/mutate-service.d.ts +5 -0
  98. package/dist/services/quotas/mutate-service.js +54 -0
  99. package/dist/services/quotas/query-service.d.ts +27 -0
  100. package/dist/services/quotas/query-service.js +137 -0
  101. package/dist/services/quotas/utils-service.d.ts +4 -0
  102. package/dist/services/quotas/utils-service.js +28 -0
  103. package/dist/services/tech/tech-provider-mutate-service.d.ts +7 -0
  104. package/dist/services/tech/tech-provider-mutate-service.js +142 -0
  105. package/dist/services/tech/tech-query-service.d.ts +9 -0
  106. package/dist/services/tech/tech-query-service.js +77 -0
  107. package/dist/services/user-preference/service.d.ts +10 -0
  108. package/dist/services/user-preference/service.js +70 -0
  109. package/dist/services/users/external-user-integration-service.d.ts +9 -0
  110. package/dist/services/users/external-user-integration-service.js +42 -0
  111. package/dist/services/users/profile-service.d.ts +40 -0
  112. package/dist/services/users/profile-service.js +408 -0
  113. package/dist/services/users/service.d.ts +64 -0
  114. package/dist/services/users/service.js +187 -0
  115. package/dist/services/users/user-error-service.d.ts +4 -0
  116. package/dist/services/users/user-error-service.js +42 -0
  117. package/dist/services/users/users-group-service.d.ts +16 -0
  118. package/dist/services/users/users-group-service.js +68 -0
  119. package/dist/services/utils/string-utils-service.d.ts +5 -0
  120. package/dist/services/utils/string-utils-service.js +41 -0
  121. package/dist/src/apollo/resolvers/mutations/mailing-lists.d.ts +11 -0
  122. package/dist/src/apollo/resolvers/mutations/mailing-lists.js +19 -0
  123. package/dist/src/apollo/resolvers/mutations/user-preferences.d.ts +13 -0
  124. package/dist/src/apollo/resolvers/mutations/user-preferences.js +20 -0
  125. package/dist/src/apollo/resolvers/mutations/users.d.ts +28 -0
  126. package/dist/src/apollo/resolvers/mutations/users.js +33 -0
  127. package/dist/src/apollo/resolvers/queries/access.d.ts +11 -0
  128. package/dist/src/apollo/resolvers/queries/access.js +14 -0
  129. package/dist/src/apollo/resolvers/queries/profile.d.ts +11 -0
  130. package/dist/src/apollo/resolvers/queries/profile.js +14 -0
  131. package/dist/src/apollo/resolvers/queries/quotas.d.ts +21 -0
  132. package/dist/src/apollo/resolvers/queries/quotas.js +14 -0
  133. package/dist/src/apollo/resolvers/queries/tech.d.ts +5 -0
  134. package/dist/src/apollo/resolvers/queries/tech.js +24 -0
  135. package/dist/src/apollo/resolvers/queries/user-preferences.d.ts +5 -0
  136. package/dist/src/apollo/resolvers/queries/user-preferences.js +22 -0
  137. package/dist/src/apollo/resolvers/queries/users.d.ts +15 -0
  138. package/dist/src/apollo/resolvers/queries/users.js +17 -0
  139. package/dist/src/apollo/typedefs/typedefs.d.ts +1 -0
  140. package/dist/src/apollo/typedefs/typedefs.js +139 -0
  141. package/dist/src/db.d.ts +3 -0
  142. package/dist/src/db.js +11 -0
  143. package/dist/src/index.d.ts +52 -0
  144. package/dist/src/index.js +52 -0
  145. package/dist/src/models/chat/chat-message-created-model.d.ts +17 -0
  146. package/dist/src/models/chat/chat-message-created-model.js +92 -0
  147. package/dist/src/models/chat/chat-message-model.d.ts +44 -0
  148. package/dist/src/models/chat/chat-message-model.js +484 -0
  149. package/dist/src/models/chat/chat-participant-model.d.ts +39 -0
  150. package/dist/src/models/chat/chat-participant-model.js +178 -0
  151. package/dist/src/models/chat/chat-session-model.d.ts +92 -0
  152. package/dist/src/models/chat/chat-session-model.js +266 -0
  153. package/dist/src/models/chat/chat-settings-model.d.ts +87 -0
  154. package/dist/src/models/chat/chat-settings-model.js +230 -0
  155. package/dist/src/models/feature-flags/feature-flag-model.d.ts +40 -0
  156. package/dist/src/models/feature-flags/feature-flag-model.js +137 -0
  157. package/dist/src/models/instances/instance-model.d.ts +100 -0
  158. package/dist/src/models/instances/instance-model.js +466 -0
  159. package/dist/src/models/instances/instance-setting-model.d.ts +39 -0
  160. package/dist/src/models/instances/instance-setting-model.js +164 -0
  161. package/dist/src/models/mailing-lists/mailing-list-model.d.ts +34 -0
  162. package/dist/src/models/mailing-lists/mailing-list-model.js +127 -0
  163. package/dist/src/models/mailing-lists/mailing-list-subscriber-model.d.ts +36 -0
  164. package/dist/src/models/mailing-lists/mailing-list-subscriber-model.js +127 -0
  165. package/dist/src/models/quotas/resource-quota-total-model.d.ts +46 -0
  166. package/dist/src/models/quotas/resource-quota-total-model.js +170 -0
  167. package/dist/src/models/quotas/resource-quota-usage-model.d.ts +51 -0
  168. package/dist/src/models/quotas/resource-quota-usage-model.js +151 -0
  169. package/dist/src/models/tech/rate-limited-api-event-model.d.ts +25 -0
  170. package/dist/src/models/tech/rate-limited-api-event-model.js +134 -0
  171. package/dist/src/models/tech/rate-limited-api-model.d.ts +21 -0
  172. package/dist/src/models/tech/rate-limited-api-model.js +116 -0
  173. package/dist/src/models/tech/tech-model.d.ts +44 -0
  174. package/dist/src/models/tech/tech-model.js +239 -0
  175. package/dist/src/models/tech/tech-provider-api-key-model.d.ts +43 -0
  176. package/dist/src/models/tech/tech-provider-api-key-model.js +195 -0
  177. package/dist/src/models/tech/tech-provider-model.d.ts +28 -0
  178. package/dist/src/models/tech/tech-provider-model.js +170 -0
  179. package/dist/src/models/users/external-user-integration-model.d.ts +36 -0
  180. package/dist/src/models/users/external-user-integration-model.js +167 -0
  181. package/dist/src/models/users/user-error-model.d.ts +54 -0
  182. package/dist/src/models/users/user-error-model.js +146 -0
  183. package/dist/src/models/users/user-error-summary-model.d.ts +45 -0
  184. package/dist/src/models/users/user-error-summary-model.js +145 -0
  185. package/dist/src/models/users/user-group-member-model.d.ts +41 -0
  186. package/dist/src/models/users/user-group-member-model.js +164 -0
  187. package/dist/src/models/users/user-group-model.d.ts +27 -0
  188. package/dist/src/models/users/user-group-model.js +121 -0
  189. package/dist/src/models/users/user-model.d.ts +46 -0
  190. package/dist/src/models/users/user-model.js +126 -0
  191. package/dist/src/models/users/user-preference-model.d.ts +60 -0
  192. package/dist/src/models/users/user-preference-model.js +197 -0
  193. package/dist/src/models/users/user-profile-model.d.ts +58 -0
  194. package/dist/src/models/users/user-profile-model.js +146 -0
  195. package/dist/src/services/access/access-service.d.ts +12 -0
  196. package/dist/src/services/access/access-service.js +27 -0
  197. package/dist/src/services/access/encrypt-service.d.ts +13 -0
  198. package/dist/src/services/access/encrypt-service.js +79 -0
  199. package/dist/src/services/api-usage/api-usage-base-service.d.ts +15 -0
  200. package/dist/src/services/api-usage/api-usage-base-service.js +58 -0
  201. package/dist/src/services/console/service.d.ts +7 -0
  202. package/dist/src/services/console/service.js +18 -0
  203. package/dist/src/services/db/pg/pg-estimate-size-service.d.ts +16 -0
  204. package/dist/src/services/db/pg/pg-estimate-size-service.js +83 -0
  205. package/dist/src/services/files/types.d.ts +6 -0
  206. package/dist/src/services/files/types.js +1 -0
  207. package/dist/src/services/files/walk-dir-service.d.ts +8 -0
  208. package/dist/src/services/files/walk-dir-service.js +77 -0
  209. package/dist/src/services/locale/countries.d.ts +6 -0
  210. package/dist/src/services/locale/countries.js +481 -0
  211. package/dist/src/services/mailing-lists/mailing-list-subscriber-service.d.ts +14 -0
  212. package/dist/src/services/mailing-lists/mailing-list-subscriber-service.js +28 -0
  213. package/dist/src/services/process/sleep.d.ts +2 -0
  214. package/dist/src/services/process/sleep.js +6 -0
  215. package/dist/src/services/quotas/mutate-service.d.ts +5 -0
  216. package/dist/src/services/quotas/mutate-service.js +37 -0
  217. package/dist/src/services/quotas/query-service.d.ts +27 -0
  218. package/dist/src/services/quotas/query-service.js +116 -0
  219. package/dist/src/services/quotas/utils-service.d.ts +4 -0
  220. package/dist/src/services/quotas/utils-service.js +22 -0
  221. package/dist/src/services/tech/tech-provider-mutate-service.d.ts +7 -0
  222. package/dist/src/services/tech/tech-provider-mutate-service.js +85 -0
  223. package/dist/src/services/tech/tech-query-service.d.ts +9 -0
  224. package/dist/src/services/tech/tech-query-service.js +58 -0
  225. package/dist/src/services/user-preference/service.d.ts +10 -0
  226. package/dist/src/services/user-preference/service.js +49 -0
  227. package/dist/src/services/users/external-user-integration-service.d.ts +9 -0
  228. package/dist/src/services/users/external-user-integration-service.js +25 -0
  229. package/dist/src/services/users/profile-service.d.ts +40 -0
  230. package/dist/src/services/users/profile-service.js +385 -0
  231. package/dist/src/services/users/service.d.ts +64 -0
  232. package/dist/src/services/users/service.js +152 -0
  233. package/dist/src/services/users/user-error-service.d.ts +4 -0
  234. package/dist/src/services/users/user-error-service.js +27 -0
  235. package/dist/src/services/users/users-group-service.d.ts +16 -0
  236. package/dist/src/services/users/users-group-service.js +51 -0
  237. package/dist/src/services/utils/field-naming-service.d.ts +20 -0
  238. package/dist/src/services/utils/field-naming-service.js +59 -0
  239. package/dist/src/services/utils/string-utils-service.d.ts +5 -0
  240. package/dist/src/services/utils/string-utils-service.js +37 -0
  241. package/dist/src/types/errors.d.ts +9 -0
  242. package/dist/src/types/errors.js +15 -0
  243. package/dist/src/types/user-types.d.ts +11 -0
  244. package/dist/src/types/user-types.js +14 -0
  245. package/dist/types/errors.d.ts +9 -0
  246. package/dist/types/errors.js +20 -0
  247. package/dist/types/user-types.d.ts +11 -0
  248. package/dist/types/user-types.js +19 -0
  249. package/package.json +21 -0
  250. package/prisma/schema.prisma +572 -0
  251. package/prisma.config.ts +14 -0
  252. package/src/apollo/README.md +4 -0
  253. package/src/apollo/resolvers/mutations/mailing-lists.ts +30 -0
  254. package/src/apollo/resolvers/mutations/user-preferences.ts +33 -0
  255. package/src/apollo/resolvers/mutations/users.ts +61 -0
  256. package/src/apollo/resolvers/queries/access.ts +23 -0
  257. package/src/apollo/resolvers/queries/profile.ts +24 -0
  258. package/src/apollo/resolvers/queries/quotas.ts +25 -0
  259. package/src/apollo/resolvers/queries/tech.ts +42 -0
  260. package/src/apollo/resolvers/queries/user-preferences.ts +34 -0
  261. package/src/apollo/resolvers/queries/users.ts +33 -0
  262. package/src/apollo/typedefs/typedefs.ts +139 -0
  263. package/src/db.ts +19 -0
  264. package/src/index.ts +52 -0
  265. package/src/models/chat/chat-message-created-model.ts +126 -0
  266. package/src/models/chat/chat-message-model.ts +678 -0
  267. package/src/models/chat/chat-participant-model.ts +248 -0
  268. package/src/models/chat/chat-session-model.ts +397 -0
  269. package/src/models/chat/chat-settings-model.ts +336 -0
  270. package/src/models/feature-flags/feature-flag-model.ts +198 -0
  271. package/src/models/instances/instance-model.ts +673 -0
  272. package/src/models/instances/instance-setting-model.ts +235 -0
  273. package/src/models/mailing-lists/mailing-list-model.ts +177 -0
  274. package/src/models/mailing-lists/mailing-list-subscriber-model.ts +194 -0
  275. package/src/models/quotas/resource-quota-total-model.ts +243 -0
  276. package/src/models/quotas/resource-quota-usage-model.ts +219 -0
  277. package/src/models/tech/rate-limited-api-event-model.ts +190 -0
  278. package/src/models/tech/rate-limited-api-model.ts +171 -0
  279. package/src/models/tech/tech-model.ts +360 -0
  280. package/src/models/tech/tech-provider-api-key-model.ts +289 -0
  281. package/src/models/tech/tech-provider-model.ts +247 -0
  282. package/src/models/users/external-user-integration-model.ts +236 -0
  283. package/src/models/users/user-error-model.ts +219 -0
  284. package/src/models/users/user-error-summary-model.ts +216 -0
  285. package/src/models/users/user-group-member-model.ts +233 -0
  286. package/src/models/users/user-group-model.ts +174 -0
  287. package/src/models/users/user-model.ts +172 -0
  288. package/src/models/users/user-preference-model.ts +285 -0
  289. package/src/models/users/user-profile-model.ts +207 -0
  290. package/src/services/access/access-service.ts +36 -0
  291. package/src/services/access/encrypt-service.ts +122 -0
  292. package/src/services/api-usage/api-usage-base-service.ts +95 -0
  293. package/src/services/console/service.ts +24 -0
  294. package/src/services/db/pg/pg-estimate-size-service.ts +119 -0
  295. package/src/services/files/types.ts +7 -0
  296. package/src/services/files/walk-dir-service.ts +135 -0
  297. package/src/services/locale/countries.ts +483 -0
  298. package/src/services/mailing-lists/mailing-list-subscriber-service.ts +54 -0
  299. package/src/services/process/sleep.ts +7 -0
  300. package/src/services/quotas/mutate-service.ts +66 -0
  301. package/src/services/quotas/query-service.ts +197 -0
  302. package/src/services/quotas/utils-service.ts +29 -0
  303. package/src/services/tech/tech-provider-mutate-service.ts +136 -0
  304. package/src/services/tech/tech-query-service.ts +93 -0
  305. package/src/services/user-preference/service.ts +110 -0
  306. package/src/services/users/external-user-integration-service.ts +51 -0
  307. package/src/services/users/profile-service.ts +513 -0
  308. package/src/services/users/service.ts +293 -0
  309. package/src/services/users/user-error-service.ts +74 -0
  310. package/src/services/users/users-group-service.ts +85 -0
  311. package/src/services/utils/field-naming-service.ts +78 -0
  312. package/src/services/utils/string-utils-service.ts +48 -0
  313. package/src/types/errors.ts +18 -0
  314. package/src/types/user-types.ts +19 -0
  315. package/tsconfig.json +25 -0
@@ -0,0 +1,92 @@
1
+ import { PrismaClient } from '@/prisma/client';
2
+ export declare class ChatSessionModel {
3
+ clName: string;
4
+ create(prisma: PrismaClient, id: string | undefined, chatSettingsId: string, instanceId: string | null, status: string, isEncryptedAtRest: boolean, name: string | null, externalIntegration: string | null, externalId: string | null, createdById: string): Promise<{
5
+ name: string | null;
6
+ id: string;
7
+ status: string;
8
+ token: string;
9
+ externalIntegration: string | null;
10
+ created: Date;
11
+ updated: Date;
12
+ externalId: string | null;
13
+ instanceId: string | null;
14
+ chatSettingsId: string;
15
+ isEncryptedAtRest: boolean;
16
+ createdById: string;
17
+ }>;
18
+ deleteById(prisma: PrismaClient, id: string): Promise<{
19
+ name: string | null;
20
+ id: string;
21
+ status: string;
22
+ token: string;
23
+ externalIntegration: string | null;
24
+ created: Date;
25
+ updated: Date;
26
+ externalId: string | null;
27
+ instanceId: string | null;
28
+ chatSettingsId: string;
29
+ isEncryptedAtRest: boolean;
30
+ createdById: string;
31
+ }>;
32
+ deleteByIdCascade(prisma: PrismaClient, id: string): Promise<void>;
33
+ deleteByInstanceId(prisma: PrismaClient, instanceId: string): Promise<void>;
34
+ filter(prisma: PrismaClient, instanceId: string | null | undefined, status: string | undefined, isEncryptedAtRest: boolean | undefined, externalIntegration: string | null | undefined, createdById: string | undefined): Promise<{
35
+ name: string | null;
36
+ id: string;
37
+ status: string;
38
+ token: string;
39
+ externalIntegration: string | null;
40
+ created: Date;
41
+ updated: Date;
42
+ externalId: string | null;
43
+ instanceId: string | null;
44
+ chatSettingsId: string;
45
+ isEncryptedAtRest: boolean;
46
+ createdById: string;
47
+ }[] | undefined>;
48
+ getByDaysAgo(prisma: PrismaClient, daysAgo: number, status?: string | undefined): Promise<{
49
+ name: string | null;
50
+ id: string;
51
+ status: string;
52
+ token: string;
53
+ externalIntegration: string | null;
54
+ created: Date;
55
+ updated: Date;
56
+ externalId: string | null;
57
+ instanceId: string | null;
58
+ chatSettingsId: string;
59
+ isEncryptedAtRest: boolean;
60
+ createdById: string;
61
+ }[] | undefined>;
62
+ getByExternalIntegrationAndExternalId(prisma: PrismaClient, externalIntegration: string, externalId: string, includeChatSettings?: boolean): Promise<any>;
63
+ getById(prisma: PrismaClient, id: string, includeChatSettings?: boolean): Promise<any>;
64
+ update(prisma: PrismaClient, id: string, chatSettingsId: string | undefined, instanceId: string | null | undefined, status: string | undefined, isEncryptedAtRest: boolean | undefined, name: string | null | undefined, externalIntegration: string | null | undefined, externalId: string | null | undefined, createdById: string | undefined): Promise<{
65
+ name: string | null;
66
+ id: string;
67
+ status: string;
68
+ token: string;
69
+ externalIntegration: string | null;
70
+ created: Date;
71
+ updated: Date;
72
+ externalId: string | null;
73
+ instanceId: string | null;
74
+ chatSettingsId: string;
75
+ isEncryptedAtRest: boolean;
76
+ createdById: string;
77
+ }>;
78
+ upsert(prisma: PrismaClient, id: string, chatSettingsId: string | undefined, instanceId: string | null | undefined, status: string | undefined, isEncryptedAtRest: boolean | undefined, name: string | null | undefined, externalIntegration: string | null | undefined, externalId: string | null | undefined, createdById: string): Promise<{
79
+ name: string | null;
80
+ id: string;
81
+ status: string;
82
+ token: string;
83
+ externalIntegration: string | null;
84
+ created: Date;
85
+ updated: Date;
86
+ externalId: string | null;
87
+ instanceId: string | null;
88
+ chatSettingsId: string;
89
+ isEncryptedAtRest: boolean;
90
+ createdById: string;
91
+ }>;
92
+ }
@@ -0,0 +1,266 @@
1
+ const { v4: uuidv4 } = require('uuid');
2
+ import { CustomError } from '../../types/errors';
3
+ import { ChatParticipantModel } from './chat-participant-model';
4
+ // Models
5
+ const chatParticipantModel = new ChatParticipantModel();
6
+ // Class
7
+ export class ChatSessionModel {
8
+ // Consts
9
+ clName = 'ChatSessionModel';
10
+ // Code
11
+ async create(prisma, id, chatSettingsId, instanceId, status, isEncryptedAtRest, name, externalIntegration, externalId, createdById) {
12
+ // Debug
13
+ const fnName = `${this.clName}.create()`;
14
+ // Generate a token
15
+ const token = uuidv4();
16
+ // Create record
17
+ try {
18
+ return await prisma.chatSession.create({
19
+ data: {
20
+ id: id,
21
+ chatSettingsId: chatSettingsId,
22
+ instanceId: instanceId,
23
+ status: status,
24
+ isEncryptedAtRest: isEncryptedAtRest,
25
+ token: token,
26
+ name: name,
27
+ externalIntegration: externalIntegration,
28
+ externalId: externalId,
29
+ createdById: createdById
30
+ }
31
+ });
32
+ }
33
+ catch (error) {
34
+ console.error(`${fnName}: error: ${error}`);
35
+ throw 'Prisma error';
36
+ }
37
+ }
38
+ async deleteById(prisma, id) {
39
+ // Debug
40
+ const fnName = `${this.clName}.deleteById()`;
41
+ // Delete chat session
42
+ try {
43
+ return await prisma.chatSession.delete({
44
+ where: {
45
+ id: id
46
+ }
47
+ });
48
+ }
49
+ catch (error) {
50
+ console.error(`${fnName}: error: ${error}`);
51
+ throw 'Prisma error';
52
+ }
53
+ }
54
+ async deleteByIdCascade(prisma, id) {
55
+ // Debug
56
+ const fnName = `${this.clName}.deleteByIdCascade()`;
57
+ // Delete chat messages (code copied directly from chat-message-model.ts
58
+ // to avoid setting the encryption key via the constructor).
59
+ try {
60
+ await prisma.chatMessage.deleteMany({
61
+ where: {
62
+ chatSessionId: id
63
+ }
64
+ });
65
+ }
66
+ catch (error) {
67
+ console.error(`${fnName}: error: ${error}`);
68
+ throw 'Prisma error';
69
+ }
70
+ // Delete chat participants
71
+ await chatParticipantModel.deleteByChatSessionId(prisma, id);
72
+ // Delete chat session
73
+ await this.deleteById(prisma, id);
74
+ }
75
+ async deleteByInstanceId(prisma, instanceId) {
76
+ // Debug
77
+ const fnName = `${this.clName}.deleteByInstanceId()`;
78
+ // Get records for the instanceId
79
+ const chatSessions = await this.filter(prisma, instanceId, undefined, undefined, undefined, undefined);
80
+ // Validate
81
+ if (chatSessions == null) {
82
+ throw new CustomError(`${fnName}: chatSessions == null`);
83
+ }
84
+ // Delete cascade each chat session
85
+ for (const chatSession of chatSessions) {
86
+ await this.deleteByIdCascade(prisma, chatSession.id);
87
+ }
88
+ }
89
+ async filter(prisma, instanceId, status, isEncryptedAtRest, externalIntegration, createdById) {
90
+ // Debug
91
+ const fnName = `${this.clName}.filter()`;
92
+ // Query records
93
+ try {
94
+ return await prisma.chatSession.findMany({
95
+ where: {
96
+ instanceId: instanceId,
97
+ status: status,
98
+ isEncryptedAtRest: isEncryptedAtRest,
99
+ externalIntegration: externalIntegration,
100
+ createdById: createdById
101
+ },
102
+ orderBy: [
103
+ {
104
+ created: 'desc'
105
+ }
106
+ ]
107
+ });
108
+ }
109
+ catch (error) {
110
+ if (!(error instanceof error.NotFound)) {
111
+ console.error(`${fnName}: error: ${error}`);
112
+ throw 'Prisma error';
113
+ }
114
+ }
115
+ }
116
+ async getByDaysAgo(prisma, daysAgo, status = undefined) {
117
+ // Debug
118
+ const fnName = `${this.clName}.getByDaysAgo()`;
119
+ // Days ago
120
+ const day = 1000 * 60 * 60 * 24;
121
+ const daysAgoTime = day * daysAgo;
122
+ const daysAgoDate = new Date(new Date().getTime() - daysAgoTime);
123
+ // Query records
124
+ try {
125
+ return await prisma.chatSession.findMany({
126
+ where: {
127
+ status: status,
128
+ created: {
129
+ lt: daysAgoDate
130
+ }
131
+ }
132
+ });
133
+ }
134
+ catch (error) {
135
+ if (!(error instanceof error.NotFound)) {
136
+ console.error(`${fnName}: error: ${error}`);
137
+ throw 'Prisma error';
138
+ }
139
+ }
140
+ }
141
+ async getByExternalIntegrationAndExternalId(prisma, externalIntegration, externalId, includeChatSettings = false) {
142
+ // Debug
143
+ const fnName = `${this.clName}.getByExternalIntegrationAndExternalId()`;
144
+ // Query record
145
+ var chatSession = undefined;
146
+ try {
147
+ chatSession = await prisma.chatSession.findFirst({
148
+ include: {
149
+ chatSettings: includeChatSettings
150
+ },
151
+ where: {
152
+ externalIntegration: externalIntegration,
153
+ externalId: externalId
154
+ }
155
+ });
156
+ }
157
+ catch (error) {
158
+ if (!(error instanceof error.NotFound)) {
159
+ console.error(`${fnName}: error: ${error}`);
160
+ throw 'Prisma error';
161
+ }
162
+ }
163
+ // Return OK
164
+ return chatSession;
165
+ }
166
+ async getById(prisma, id, includeChatSettings = false) {
167
+ // Debug
168
+ const fnName = `${this.clName}.getById()`;
169
+ // Query record
170
+ var chatSession = undefined;
171
+ try {
172
+ chatSession = await prisma.chatSession.findUnique({
173
+ include: {
174
+ chatSettings: includeChatSettings
175
+ },
176
+ where: {
177
+ id: id
178
+ }
179
+ });
180
+ }
181
+ catch (error) {
182
+ if (!(error instanceof error.NotFound)) {
183
+ console.error(`${fnName}: error: ${error}`);
184
+ throw 'Prisma error';
185
+ }
186
+ }
187
+ // Return OK
188
+ return chatSession;
189
+ }
190
+ async update(prisma, id, chatSettingsId, instanceId, status, isEncryptedAtRest, name, externalIntegration, externalId, createdById) {
191
+ // Debug
192
+ const fnName = `${this.clName}.update()`;
193
+ // Update record
194
+ try {
195
+ return await prisma.chatSession.update({
196
+ data: {
197
+ chatSettingsId: chatSettingsId,
198
+ instanceId: instanceId,
199
+ status: status,
200
+ isEncryptedAtRest: isEncryptedAtRest,
201
+ name: name,
202
+ externalIntegration: externalIntegration,
203
+ externalId: externalId,
204
+ createdById: createdById
205
+ },
206
+ where: {
207
+ id: id
208
+ }
209
+ });
210
+ }
211
+ catch (error) {
212
+ console.error(`${fnName}: error: ${error}`);
213
+ throw 'Prisma error';
214
+ }
215
+ }
216
+ async upsert(prisma, id, chatSettingsId, instanceId, status, isEncryptedAtRest, name, externalIntegration, externalId, createdById) {
217
+ // Debug
218
+ const fnName = `${this.clName}.upsert()`;
219
+ // If the id is specified, try to get it
220
+ if (id != null) {
221
+ const chatSession = await this.getById(prisma, id);
222
+ if (chatSession != null) {
223
+ id = chatSession.id;
224
+ }
225
+ }
226
+ // Upsert
227
+ if (id == null) {
228
+ // Validate for create (mainly for type validation of the create call)
229
+ if (chatSettingsId == null) {
230
+ console.error(`${fnName}: id is null and chatSettingsId is null`);
231
+ throw 'Prisma error';
232
+ }
233
+ if (instanceId === undefined) {
234
+ console.error(`${fnName}: id is null and instanceId is undefined`);
235
+ throw 'Prisma error';
236
+ }
237
+ if (status == null) {
238
+ console.error(`${fnName}: id is null and status is null`);
239
+ throw 'Prisma error';
240
+ }
241
+ if (name === undefined) {
242
+ console.error(`${fnName}: id is null and name is undefined`);
243
+ throw 'Prisma error';
244
+ }
245
+ if (externalIntegration === undefined) {
246
+ console.error(`${fnName}: id is null and externalIntegration is undefined`);
247
+ throw 'Prisma error';
248
+ }
249
+ if (externalId === undefined) {
250
+ console.error(`${fnName}: id is null and externalId is undefined`);
251
+ throw 'Prisma error';
252
+ }
253
+ if (isEncryptedAtRest == null) {
254
+ console.error(`${fnName}: id is null and isEncryptedAtRest is null`);
255
+ throw 'Prisma error';
256
+ }
257
+ // Create
258
+ return await this.create(prisma, undefined, // id
259
+ chatSettingsId, instanceId, status, isEncryptedAtRest, name, externalIntegration, externalId, createdById);
260
+ }
261
+ else {
262
+ // Update
263
+ return await this.update(prisma, id, chatSettingsId, instanceId, status, isEncryptedAtRest, name, externalIntegration, externalId, createdById);
264
+ }
265
+ }
266
+ }
@@ -0,0 +1,87 @@
1
+ import { PrismaClient } from '@/prisma/client';
2
+ export declare class ChatSettingsModel {
3
+ clName: string;
4
+ create(prisma: PrismaClient, baseChatSettingsId: string | null, status: string, isEncryptedAtRest: boolean, isJsonMode: boolean, isPinned: boolean, name: string | null, agentUserId: string, prompt: string | null, appCustom: any | null, createdById: string): Promise<{
5
+ name: string | null;
6
+ id: string;
7
+ prompt: string | null;
8
+ status: string;
9
+ created: Date;
10
+ updated: Date;
11
+ isEncryptedAtRest: boolean;
12
+ createdById: string;
13
+ baseChatSettingsId: string | null;
14
+ isJsonMode: boolean;
15
+ isPinned: boolean;
16
+ agentUserId: string;
17
+ agentRole: string | null;
18
+ appCustom: import("@/prisma/runtime/client").JsonValue | null;
19
+ }>;
20
+ deleteById(prisma: PrismaClient, id: string): Promise<void>;
21
+ getById(prisma: PrismaClient, id: string): Promise<any>;
22
+ getByName(prisma: PrismaClient, name: string): Promise<any>;
23
+ getByBaseChatSettingsId(prisma: PrismaClient, baseChatSettingsId: string | null | undefined): Promise<{
24
+ name: string | null;
25
+ id: string;
26
+ prompt: string | null;
27
+ status: string;
28
+ created: Date;
29
+ updated: Date;
30
+ isEncryptedAtRest: boolean;
31
+ createdById: string;
32
+ baseChatSettingsId: string | null;
33
+ isJsonMode: boolean;
34
+ isPinned: boolean;
35
+ agentUserId: string;
36
+ agentRole: string | null;
37
+ appCustom: import("@/prisma/runtime/client").JsonValue | null;
38
+ }[]>;
39
+ getUnused(prisma: PrismaClient): Promise<{
40
+ name: string | null;
41
+ id: string;
42
+ prompt: string | null;
43
+ status: string;
44
+ created: Date;
45
+ updated: Date;
46
+ isEncryptedAtRest: boolean;
47
+ createdById: string;
48
+ baseChatSettingsId: string | null;
49
+ isJsonMode: boolean;
50
+ isPinned: boolean;
51
+ agentUserId: string;
52
+ agentRole: string | null;
53
+ appCustom: import("@/prisma/runtime/client").JsonValue | null;
54
+ }[]>;
55
+ update(prisma: PrismaClient, id: string, baseChatSettingsId: string | null | undefined, status: string | undefined, isEncryptedAtRest: boolean | undefined, isJsonMode: boolean | undefined, isPinned: boolean | undefined, name: string | null | undefined, agentUserId: string | undefined, prompt: string | null | undefined, appCustom: any | null | undefined, createdById: string | undefined): Promise<{
56
+ name: string | null;
57
+ id: string;
58
+ prompt: string | null;
59
+ status: string;
60
+ created: Date;
61
+ updated: Date;
62
+ isEncryptedAtRest: boolean;
63
+ createdById: string;
64
+ baseChatSettingsId: string | null;
65
+ isJsonMode: boolean;
66
+ isPinned: boolean;
67
+ agentUserId: string;
68
+ agentRole: string | null;
69
+ appCustom: import("@/prisma/runtime/client").JsonValue | null;
70
+ }>;
71
+ upsert(prisma: PrismaClient, id: string | undefined, baseChatSettingsId: string | null | undefined, status: string | undefined, isEncryptedAtRest: boolean | undefined, isJsonMode: boolean | undefined, isPinned: boolean | undefined, name: string | null | undefined, agentUserId: string | undefined, prompt: string | null | undefined, appCustom: any | null | undefined, createdById: string | undefined): Promise<{
72
+ name: string | null;
73
+ id: string;
74
+ prompt: string | null;
75
+ status: string;
76
+ created: Date;
77
+ updated: Date;
78
+ isEncryptedAtRest: boolean;
79
+ createdById: string;
80
+ baseChatSettingsId: string | null;
81
+ isJsonMode: boolean;
82
+ isPinned: boolean;
83
+ agentUserId: string;
84
+ agentRole: string | null;
85
+ appCustom: import("@/prisma/runtime/client").JsonValue | null;
86
+ }>;
87
+ }
@@ -0,0 +1,230 @@
1
+ export class ChatSettingsModel {
2
+ // Consts
3
+ clName = 'ChatSettingsModel';
4
+ // Code
5
+ async create(prisma, baseChatSettingsId, status, isEncryptedAtRest, isJsonMode, isPinned, name, agentUserId, prompt, appCustom, createdById) {
6
+ // Debug
7
+ const fnName = `${this.clName}.create()`;
8
+ // console.log(`${fnName}: starting..`)
9
+ // Create record
10
+ try {
11
+ return await prisma.chatSettings.create({
12
+ data: {
13
+ baseChatSettingsId: baseChatSettingsId,
14
+ status: status,
15
+ isEncryptedAtRest: isEncryptedAtRest,
16
+ isJsonMode: isJsonMode,
17
+ isPinned: isPinned,
18
+ name: name,
19
+ agentUserId: agentUserId,
20
+ prompt: prompt,
21
+ appCustom: appCustom,
22
+ createdById: createdById
23
+ }
24
+ });
25
+ }
26
+ catch (error) {
27
+ console.error(`${fnName}: error: ${error}`);
28
+ throw 'Prisma error';
29
+ }
30
+ }
31
+ async deleteById(prisma, id) {
32
+ // Debug
33
+ const fnName = `${this.clName}.deleteById()`;
34
+ // Delete records
35
+ try {
36
+ await prisma.chatSettings.deleteMany({
37
+ where: {
38
+ id: id
39
+ }
40
+ });
41
+ }
42
+ catch (error) {
43
+ console.error(`${fnName}: error: ${error}`);
44
+ throw 'Prisma error';
45
+ }
46
+ }
47
+ async getById(prisma, id) {
48
+ // Debug
49
+ const fnName = `${this.clName}.getById()`;
50
+ // Query record
51
+ var chatSettings = undefined;
52
+ try {
53
+ chatSettings = await prisma.chatSettings.findUnique({
54
+ where: {
55
+ id: id
56
+ }
57
+ });
58
+ }
59
+ catch (error) {
60
+ if (!(error instanceof error.NotFound)) {
61
+ console.error(`${fnName}: error: ${error}`);
62
+ throw 'Prisma error';
63
+ }
64
+ }
65
+ // Return OK
66
+ return chatSettings;
67
+ }
68
+ async getByName(prisma, name) {
69
+ // Debug
70
+ const fnName = `${this.clName}.getByName()`;
71
+ // Validate
72
+ if (name == null) {
73
+ console.error(`${fnName}: id is null and name is null`);
74
+ throw 'Prisma error';
75
+ }
76
+ // Query record
77
+ var chatSettings = undefined;
78
+ try {
79
+ chatSettings = await prisma.chatSettings.findUnique({
80
+ where: {
81
+ name: name
82
+ }
83
+ });
84
+ }
85
+ catch (error) {
86
+ if (!(error instanceof error.NotFound)) {
87
+ console.error(`${fnName}: error: ${error}`);
88
+ throw 'Prisma error';
89
+ }
90
+ }
91
+ // Return OK
92
+ return chatSettings;
93
+ }
94
+ async getByBaseChatSettingsId(prisma, baseChatSettingsId) {
95
+ // Debug
96
+ const fnName = `${this.clName}.getByBaseChatSettingsId()`;
97
+ // Query records
98
+ try {
99
+ return await prisma.chatSettings.findMany({
100
+ where: {
101
+ baseChatSettingsId: baseChatSettingsId
102
+ }
103
+ });
104
+ }
105
+ catch (error) {
106
+ console.error(`${fnName}: error: ${error}`);
107
+ throw 'Prisma error';
108
+ }
109
+ }
110
+ async getUnused(prisma) {
111
+ // Debug
112
+ const fnName = `${this.clName}.getByBaseChatSettingsId()`;
113
+ // Query records
114
+ try {
115
+ return await prisma.chatSettings.findMany({
116
+ where: {
117
+ isPinned: false,
118
+ ofChatSessions: {
119
+ none: {}
120
+ }
121
+ }
122
+ });
123
+ }
124
+ catch (error) {
125
+ console.error(`${fnName}: error: ${error}`);
126
+ throw 'Prisma error';
127
+ }
128
+ }
129
+ async update(prisma, id, baseChatSettingsId, status, isEncryptedAtRest, isJsonMode, isPinned, name, agentUserId, prompt, appCustom, createdById) {
130
+ // Debug
131
+ const fnName = `${this.clName}.update()`;
132
+ // Update record
133
+ try {
134
+ return await prisma.chatSettings.update({
135
+ data: {
136
+ baseChatSettings: baseChatSettingsId != null ? {
137
+ connect: {
138
+ id: baseChatSettingsId
139
+ }
140
+ } : undefined,
141
+ status: status,
142
+ isEncryptedAtRest: isEncryptedAtRest,
143
+ isJsonMode: isJsonMode,
144
+ isPinned: isPinned,
145
+ name: name,
146
+ agentUser: agentUserId != null ? {
147
+ connect: {
148
+ id: agentUserId
149
+ }
150
+ } : undefined,
151
+ prompt: prompt,
152
+ appCustom: appCustom,
153
+ createdByUserProfile: createdById != null ? {
154
+ connect: {
155
+ id: createdById
156
+ }
157
+ } : undefined
158
+ },
159
+ where: {
160
+ id: id
161
+ }
162
+ });
163
+ }
164
+ catch (error) {
165
+ console.error(`${fnName}: error: ${error}`);
166
+ throw 'Prisma error';
167
+ }
168
+ }
169
+ async upsert(prisma, id, baseChatSettingsId, status, isEncryptedAtRest, isJsonMode, isPinned, name, agentUserId, prompt, appCustom, createdById) {
170
+ // Debug
171
+ const fnName = `${this.clName}.upsert()`;
172
+ // console.log(`${fnName}: starting..`)
173
+ // Get by name if id not specified
174
+ if (id == null &&
175
+ name != null) {
176
+ const chatSettings = await this.getByName(prisma, name);
177
+ if (chatSettings != null) {
178
+ id = chatSettings.id;
179
+ }
180
+ }
181
+ // Upsert
182
+ if (id == null) {
183
+ // Validate for create (mainly for type validation of the create call)
184
+ if (baseChatSettingsId === undefined) {
185
+ console.error(`${fnName}: id is null and baseChatSettingsId is undefined`);
186
+ throw 'Prisma error';
187
+ }
188
+ if (status == null) {
189
+ console.error(`${fnName}: id is null and status is null`);
190
+ throw 'Prisma error';
191
+ }
192
+ if (isEncryptedAtRest == null) {
193
+ console.error(`${fnName}: id is null and isEncryptedAtRest is null`);
194
+ throw 'Prisma error';
195
+ }
196
+ if (isJsonMode == null) {
197
+ console.error(`${fnName}: id is null and isJsonMode is null`);
198
+ throw 'Prisma error';
199
+ }
200
+ if (isPinned == null) {
201
+ console.error(`${fnName}: id is null and isPinned is null`);
202
+ throw 'Prisma error';
203
+ }
204
+ if (name === undefined) {
205
+ console.error(`${fnName}: id is null and name is undefined`);
206
+ throw 'Prisma error';
207
+ }
208
+ if (agentUserId == null) {
209
+ console.error(`${fnName}: id is null and agentUserId is null`);
210
+ throw 'Prisma error';
211
+ }
212
+ if (prompt === undefined) {
213
+ console.error(`${fnName}: id is null and prompt is undefined`);
214
+ throw 'Prisma error';
215
+ }
216
+ if (appCustom === undefined) {
217
+ console.error(`${fnName}: id is null and appCustom is undefined`);
218
+ throw 'Prisma error';
219
+ }
220
+ if (createdById == null) {
221
+ console.error(`${fnName}: id is null and createdById is null`);
222
+ throw 'Prisma error';
223
+ }
224
+ return await this.create(prisma, baseChatSettingsId, status, isEncryptedAtRest, isJsonMode, isPinned, name, agentUserId, prompt, appCustom, createdById);
225
+ }
226
+ else {
227
+ return await this.update(prisma, id, baseChatSettingsId, status, isEncryptedAtRest, isJsonMode, isPinned, name, agentUserId, prompt, appCustom, createdById);
228
+ }
229
+ }
230
+ }