mm-share-lib 0.0.5 → 0.0.7

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 (325) hide show
  1. package/dist/src/auth/apple/apple.module.d.ts +2 -0
  2. package/dist/src/auth/apple/apple.module.js +22 -0
  3. package/dist/src/auth/apple/apple.module.js.map +1 -0
  4. package/dist/src/auth/apple/apple.service.d.ts +9 -0
  5. package/dist/src/auth/apple/apple.service.js +38 -0
  6. package/dist/src/auth/apple/apple.service.js.map +1 -0
  7. package/dist/src/auth/apple/dto/apple-login.dto.d.ts +5 -0
  8. package/dist/src/auth/apple/dto/apple-login.dto.js +33 -0
  9. package/dist/src/auth/apple/dto/apple-login.dto.js.map +1 -0
  10. package/dist/src/auth/apple/dto/index.d.ts +1 -0
  11. package/dist/src/auth/apple/dto/index.js +18 -0
  12. package/dist/src/auth/apple/dto/index.js.map +1 -0
  13. package/dist/src/auth/apple/index.d.ts +3 -0
  14. package/dist/src/auth/apple/index.js +20 -0
  15. package/dist/src/auth/apple/index.js.map +1 -0
  16. package/dist/src/auth/config/apple.config.d.ts +3 -0
  17. package/dist/src/auth/config/apple.config.js +29 -0
  18. package/dist/src/auth/config/apple.config.js.map +1 -0
  19. package/dist/src/auth/config/auth.config.d.ts +3 -0
  20. package/dist/src/auth/config/auth.config.js +42 -0
  21. package/dist/src/auth/config/auth.config.js.map +1 -0
  22. package/dist/src/auth/config/facebook.config.d.ts +3 -0
  23. package/dist/src/auth/config/facebook.config.js +34 -0
  24. package/dist/src/auth/config/facebook.config.js.map +1 -0
  25. package/dist/src/auth/config/file.config.d.ts +3 -0
  26. package/dist/src/auth/config/file.config.js +66 -0
  27. package/dist/src/auth/config/file.config.js.map +1 -0
  28. package/dist/src/auth/config/google.config.d.ts +3 -0
  29. package/dist/src/auth/config/google.config.js +34 -0
  30. package/dist/src/auth/config/google.config.js.map +1 -0
  31. package/dist/src/auth/config/index.d.ts +6 -0
  32. package/dist/src/auth/config/index.js +23 -0
  33. package/dist/src/auth/config/index.js.map +1 -0
  34. package/dist/src/auth/config/twitter.config.d.ts +8 -0
  35. package/dist/src/auth/config/twitter.config.js +34 -0
  36. package/dist/src/auth/config/twitter.config.js.map +1 -0
  37. package/dist/src/auth/facebook/dto/facebook-login.dto.d.ts +3 -0
  38. package/dist/src/auth/facebook/dto/facebook-login.dto.js +23 -0
  39. package/dist/src/auth/facebook/dto/facebook-login.dto.js.map +1 -0
  40. package/dist/src/auth/facebook/dto/index.d.ts +1 -0
  41. package/dist/src/auth/facebook/dto/index.js +18 -0
  42. package/dist/src/auth/facebook/dto/index.js.map +1 -0
  43. package/dist/src/auth/facebook/facebook.module.d.ts +2 -0
  44. package/dist/src/auth/facebook/facebook.module.js +23 -0
  45. package/dist/src/auth/facebook/facebook.module.js.map +1 -0
  46. package/dist/src/auth/facebook/facebook.service.d.ts +10 -0
  47. package/dist/src/auth/facebook/facebook.service.js +50 -0
  48. package/dist/src/auth/facebook/facebook.service.js.map +1 -0
  49. package/dist/src/auth/facebook/index.d.ts +4 -0
  50. package/dist/src/auth/facebook/index.js +21 -0
  51. package/dist/src/auth/facebook/index.js.map +1 -0
  52. package/dist/src/auth/facebook/interface/facebook.interface.d.ts +6 -0
  53. package/dist/src/auth/facebook/interface/facebook.interface.js +3 -0
  54. package/dist/src/auth/facebook/interface/facebook.interface.js.map +1 -0
  55. package/dist/src/auth/facebook/interface/index.d.ts +1 -0
  56. package/dist/src/auth/facebook/interface/index.js +18 -0
  57. package/dist/src/auth/facebook/interface/index.js.map +1 -0
  58. package/dist/src/auth/google/dto/google-login.dto.d.ts +3 -0
  59. package/dist/src/auth/google/dto/google-login.dto.js +23 -0
  60. package/dist/src/auth/google/dto/google-login.dto.js.map +1 -0
  61. package/dist/src/auth/google/dto/index.d.ts +1 -0
  62. package/dist/src/auth/google/dto/index.js +18 -0
  63. package/dist/src/auth/google/dto/index.js.map +1 -0
  64. package/dist/src/auth/google/google.module.d.ts +2 -0
  65. package/dist/src/auth/google/google.module.js +22 -0
  66. package/dist/src/auth/google/google.module.js.map +1 -0
  67. package/dist/src/auth/google/google.service.d.ts +10 -0
  68. package/dist/src/auth/google/google.service.js +49 -0
  69. package/dist/src/auth/google/google.service.js.map +1 -0
  70. package/dist/src/auth/google/index.d.ts +3 -0
  71. package/dist/src/auth/google/index.js +20 -0
  72. package/dist/src/auth/google/index.js.map +1 -0
  73. package/dist/src/auth/index.d.ts +5 -0
  74. package/dist/src/auth/index.js +22 -0
  75. package/dist/src/auth/index.js.map +1 -0
  76. package/dist/src/auth/twitter/dto/index.d.ts +1 -0
  77. package/dist/src/auth/twitter/dto/index.js +18 -0
  78. package/dist/src/auth/twitter/dto/index.js.map +1 -0
  79. package/dist/src/auth/twitter/dto/twitter-login.dto.d.ts +4 -0
  80. package/dist/src/auth/twitter/dto/twitter-login.dto.js +28 -0
  81. package/dist/src/auth/twitter/dto/twitter-login.dto.js.map +1 -0
  82. package/dist/src/auth/twitter/index.d.ts +3 -0
  83. package/dist/src/auth/twitter/index.js +20 -0
  84. package/dist/src/auth/twitter/index.js.map +1 -0
  85. package/dist/src/auth/twitter/twitter.module.d.ts +2 -0
  86. package/dist/src/auth/twitter/twitter.module.js +23 -0
  87. package/dist/src/auth/twitter/twitter.module.js.map +1 -0
  88. package/dist/src/auth/twitter/twitter.service.d.ts +9 -0
  89. package/dist/src/auth/twitter/twitter.service.js +49 -0
  90. package/dist/src/auth/twitter/twitter.service.js.map +1 -0
  91. package/dist/src/config/index.d.ts +1 -0
  92. package/dist/src/config/index.js +18 -0
  93. package/dist/src/config/index.js.map +1 -0
  94. package/dist/src/config/type.config.d.ts +79 -0
  95. package/dist/src/config/type.config.js +3 -0
  96. package/dist/src/config/type.config.js.map +1 -0
  97. package/dist/src/dto/pagination.dto.d.ts +3 -2
  98. package/dist/src/dto/pagination.dto.js +26 -0
  99. package/dist/src/dto/pagination.dto.js.map +1 -1
  100. package/dist/src/filter/rpc-exception.filter.d.ts +6 -0
  101. package/dist/src/filter/rpc-exception.filter.js +21 -0
  102. package/dist/src/filter/rpc-exception.filter.js.map +1 -0
  103. package/dist/src/index.d.ts +1 -0
  104. package/dist/src/index.js +1 -0
  105. package/dist/src/index.js.map +1 -1
  106. package/dist/src/interface/index.d.ts +1 -0
  107. package/dist/src/interface/index.js +18 -0
  108. package/dist/src/interface/index.js.map +1 -0
  109. package/dist/src/interface/social.interface.d.ts +6 -0
  110. package/dist/src/interface/social.interface.js +3 -0
  111. package/dist/src/interface/social.interface.js.map +1 -0
  112. package/dist/src/lib/index.d.ts +2 -0
  113. package/dist/src/lib/index.js +2 -0
  114. package/dist/src/lib/index.js.map +1 -1
  115. package/dist/src/lib/mailer/config/index.d.ts +1 -0
  116. package/dist/src/lib/mailer/config/index.js +18 -0
  117. package/dist/src/lib/mailer/config/index.js.map +1 -0
  118. package/dist/src/lib/mailer/config/mailer.config.d.ts +3 -0
  119. package/dist/src/lib/mailer/config/mailer.config.js +72 -0
  120. package/dist/src/lib/mailer/config/mailer.config.js.map +1 -0
  121. package/dist/src/lib/mailer/index.d.ts +2 -0
  122. package/dist/src/lib/mailer/index.js +19 -0
  123. package/dist/src/lib/mailer/index.js.map +1 -0
  124. package/dist/src/lib/mailer/mailer.module.d.ts +2 -0
  125. package/dist/src/lib/mailer/mailer.module.js +20 -0
  126. package/dist/src/lib/mailer/mailer.module.js.map +1 -0
  127. package/dist/src/lib/mailer/mailer.service.d.ts +12 -0
  128. package/dist/src/lib/mailer/mailer.service.js +66 -0
  129. package/dist/src/lib/mailer/mailer.service.js.map +1 -0
  130. package/dist/src/lib/redis/index.d.ts +0 -0
  131. package/dist/src/lib/redis/index.js +1 -0
  132. package/dist/src/lib/redis/index.js.map +1 -0
  133. package/dist/src/lib/search-engine/document/base.document.d.ts +1 -1
  134. package/dist/src/lib/search-engine/interface/search-document.interface.d.ts +1 -1
  135. package/dist/src/lib/search-engine/typesense/collection/index.d.ts +1 -0
  136. package/dist/src/lib/search-engine/typesense/collection/index.js +18 -0
  137. package/dist/src/lib/search-engine/typesense/collection/index.js.map +1 -0
  138. package/dist/src/lib/search-engine/typesense/document/index.d.ts +1 -0
  139. package/dist/src/lib/search-engine/typesense/document/index.js +18 -0
  140. package/dist/src/lib/search-engine/typesense/document/index.js.map +1 -0
  141. package/dist/src/lib/search-engine/typesense/index.d.ts +1 -0
  142. package/dist/src/lib/search-engine/typesense/index.js +1 -0
  143. package/dist/src/lib/search-engine/typesense/index.js.map +1 -1
  144. package/dist/src/lib/search-engine/typesense/service/client.service.d.ts +3 -2
  145. package/dist/src/lib/search-engine/typesense/service/client.service.js +4 -1
  146. package/dist/src/lib/search-engine/typesense/service/client.service.js.map +1 -1
  147. package/dist/src/lib/storage/index.d.ts +0 -0
  148. package/dist/src/lib/storage/index.js +1 -0
  149. package/dist/src/lib/storage/index.js.map +1 -0
  150. package/dist/src/lib/typesense/client/index.d.ts +1 -0
  151. package/dist/src/lib/typesense/client/index.js +6 -0
  152. package/dist/src/lib/typesense/client/index.js.map +1 -0
  153. package/dist/src/lib/typesense/collection/index.d.ts +1 -0
  154. package/dist/src/lib/typesense/collection/index.js +18 -0
  155. package/dist/src/lib/typesense/collection/index.js.map +1 -0
  156. package/dist/src/lib/typesense/collection/typesense-colletctions.creator.d.ts +10 -0
  157. package/dist/src/lib/typesense/collection/typesense-colletctions.creator.js +42 -0
  158. package/dist/src/lib/typesense/collection/typesense-colletctions.creator.js.map +1 -0
  159. package/dist/src/lib/typesense/decorator/field.decorator.d.ts +9 -0
  160. package/dist/src/lib/typesense/decorator/field.decorator.js +15 -0
  161. package/dist/src/lib/typesense/decorator/field.decorator.js.map +1 -0
  162. package/dist/src/lib/typesense/decorator/index.d.ts +2 -0
  163. package/dist/src/lib/typesense/decorator/index.js +19 -0
  164. package/dist/src/lib/typesense/decorator/index.js.map +1 -0
  165. package/dist/src/lib/typesense/decorator/schema.decorator.d.ts +7 -0
  166. package/dist/src/lib/typesense/decorator/schema.decorator.js +16 -0
  167. package/dist/src/lib/typesense/decorator/schema.decorator.js.map +1 -0
  168. package/dist/src/lib/typesense/document/base.document.d.ts +3 -0
  169. package/dist/src/lib/typesense/document/base.document.js +7 -0
  170. package/dist/src/lib/typesense/document/base.document.js.map +1 -0
  171. package/dist/src/lib/typesense/document/index.d.ts +1 -0
  172. package/dist/src/lib/typesense/document/index.js +18 -0
  173. package/dist/src/lib/typesense/document/index.js.map +1 -0
  174. package/dist/src/lib/typesense/index.d.ts +4 -0
  175. package/dist/src/lib/typesense/index.js +21 -0
  176. package/dist/src/lib/typesense/index.js.map +1 -0
  177. package/dist/src/lib/typesense/metadata/index.d.ts +4 -0
  178. package/dist/src/lib/typesense/metadata/index.js +21 -0
  179. package/dist/src/lib/typesense/metadata/index.js.map +1 -0
  180. package/dist/src/lib/typesense/metadata/schema.metadata.d.ts +19 -0
  181. package/dist/src/lib/typesense/metadata/schema.metadata.js +3 -0
  182. package/dist/src/lib/typesense/metadata/schema.metadata.js.map +1 -0
  183. package/dist/src/lib/typesense/metadata/typesense.metadata-accessor.d.ts +7 -0
  184. package/dist/src/lib/typesense/metadata/typesense.metadata-accessor.js +47 -0
  185. package/dist/src/lib/typesense/metadata/typesense.metadata-accessor.js.map +1 -0
  186. package/dist/src/lib/typesense/metadata/typesense.metadata-explorer.d.ts +14 -0
  187. package/dist/src/lib/typesense/metadata/typesense.metadata-explorer.js +50 -0
  188. package/dist/src/lib/typesense/metadata/typesense.metadata-explorer.js.map +1 -0
  189. package/dist/src/lib/typesense/metadata/typesense.metadata-registry.d.ts +10 -0
  190. package/dist/src/lib/typesense/metadata/typesense.metadata-registry.js +33 -0
  191. package/dist/src/lib/typesense/metadata/typesense.metadata-registry.js.map +1 -0
  192. package/dist/src/lib/typesense/module/index.d.ts +4 -0
  193. package/dist/src/lib/typesense/module/index.js +21 -0
  194. package/dist/src/lib/typesense/module/index.js.map +1 -0
  195. package/dist/src/lib/typesense/module/interface.module.d.ts +27 -0
  196. package/dist/src/lib/typesense/module/interface.module.js +3 -0
  197. package/dist/src/lib/typesense/module/interface.module.js.map +1 -0
  198. package/dist/src/lib/typesense/module/typesense.constant.d.ts +1 -0
  199. package/dist/src/lib/typesense/module/typesense.constant.js +5 -0
  200. package/dist/src/lib/typesense/module/typesense.constant.js.map +1 -0
  201. package/dist/src/lib/typesense/module/typesense.module.d.ts +8 -0
  202. package/dist/src/lib/typesense/module/typesense.module.js +74 -0
  203. package/dist/src/lib/typesense/module/typesense.module.js.map +1 -0
  204. package/dist/src/lib/typesense/module/typesense.provider.d.ts +5 -0
  205. package/dist/src/lib/typesense/module/typesense.provider.js +48 -0
  206. package/dist/src/lib/typesense/module/typesense.provider.js.map +1 -0
  207. package/dist/src/response/base-entity.response.d.ts +3 -0
  208. package/dist/src/response/base-entity.response.js +23 -0
  209. package/dist/src/response/base-entity.response.js.map +1 -0
  210. package/dist/src/response/index.d.ts +1 -0
  211. package/dist/src/response/index.js +1 -0
  212. package/dist/src/response/index.js.map +1 -1
  213. package/dist/src/response/login.response.d.ts +0 -0
  214. package/dist/src/response/login.response.js +1 -0
  215. package/dist/src/response/login.response.js.map +1 -0
  216. package/dist/src/response/pagination.response.d.ts +5 -5
  217. package/dist/src/response/pagination.response.js +39 -0
  218. package/dist/src/response/pagination.response.js.map +1 -1
  219. package/dist/src/util/index.d.ts +1 -0
  220. package/dist/src/util/index.js +1 -0
  221. package/dist/src/util/index.js.map +1 -1
  222. package/dist/src/util/validate-config.d.ts +2 -0
  223. package/dist/src/util/validate-config.js +19 -0
  224. package/dist/src/util/validate-config.js.map +1 -0
  225. package/dist/tsconfig.build.tsbuildinfo +1 -1
  226. package/package.json +12 -2
  227. package/src/auth/apple/apple.module.ts +10 -0
  228. package/src/auth/apple/apple.service.ts +28 -0
  229. package/src/auth/apple/dto/apple-login.dto.ts +16 -0
  230. package/src/auth/apple/dto/index.ts +1 -0
  231. package/src/auth/apple/index.ts +3 -0
  232. package/src/auth/config/apple.config.ts +18 -0
  233. package/src/auth/config/auth.config.ts +29 -0
  234. package/src/auth/config/facebook.config.ts +23 -0
  235. package/src/auth/config/file.config.ts +50 -0
  236. package/src/auth/config/google.config.ts +23 -0
  237. package/src/auth/config/index.ts +6 -0
  238. package/src/auth/config/twitter.config.ts +22 -0
  239. package/src/auth/facebook/dto/facebook-login.dto.ts +8 -0
  240. package/src/auth/facebook/dto/index.ts +1 -0
  241. package/src/auth/facebook/facebook.module.ts +11 -0
  242. package/src/auth/facebook/facebook.service.ts +51 -0
  243. package/src/auth/facebook/index.ts +4 -0
  244. package/src/auth/facebook/interface/facebook.interface.ts +6 -0
  245. package/src/auth/facebook/interface/index.ts +1 -0
  246. package/src/auth/google/dto/google-login.dto.ts +8 -0
  247. package/src/auth/google/dto/index.ts +1 -0
  248. package/src/auth/google/google.module.ts +10 -0
  249. package/src/auth/google/google.service.ts +49 -0
  250. package/src/auth/google/index.ts +3 -0
  251. package/src/auth/index.ts +5 -0
  252. package/src/auth/twitter/dto/index.ts +1 -0
  253. package/src/auth/twitter/dto/twitter-login.dto.ts +12 -0
  254. package/src/auth/twitter/index.ts +3 -0
  255. package/src/auth/twitter/twitter.module.ts +11 -0
  256. package/src/auth/twitter/twitter.service.ts +43 -0
  257. package/src/config/index.ts +1 -0
  258. package/src/config/type.config.ts +88 -0
  259. package/src/dto/base-filter.dto.ts +4 -4
  260. package/src/dto/pagination.dto.ts +16 -4
  261. package/src/exception/bad-request-error.exception.spec.ts +24 -24
  262. package/src/exception/bad-request-error.exception.ts +8 -8
  263. package/src/exception/base.exception.ts +36 -36
  264. package/src/exception/conflict-error.exception.spec.ts +23 -23
  265. package/src/exception/conflict-error.exception.ts +8 -8
  266. package/src/exception/forbidden-error.exception.spec.ts +23 -23
  267. package/src/exception/forbidden-error.exception.ts +8 -8
  268. package/src/exception/index.ts +7 -7
  269. package/src/exception/internal-server-error.exception.spec.ts +23 -23
  270. package/src/exception/internal-server-error.exception.ts +12 -12
  271. package/src/exception/not-found-error.exception.spec.ts +23 -23
  272. package/src/exception/not-found-error.exception.ts +8 -8
  273. package/src/exception/unauthorized-error.exception.spec.ts +23 -23
  274. package/src/exception/unauthorized-error.exception.ts +12 -12
  275. package/src/filter/http-exception.filter.ts +23 -23
  276. package/src/filter/rpc-exception.filter.ts +15 -0
  277. package/src/index.ts +1 -0
  278. package/src/interface/index.ts +1 -0
  279. package/src/interface/social.interface.ts +6 -0
  280. package/src/lib/index.ts +2 -0
  281. package/src/lib/mailer/config/index.ts +1 -0
  282. package/src/lib/mailer/config/mailer.config.ts +62 -0
  283. package/src/lib/mailer/index.ts +2 -0
  284. package/src/lib/mailer/mailer.module.ts +8 -0
  285. package/src/lib/mailer/mailer.service.ts +53 -0
  286. package/src/lib/redis/index.ts +0 -0
  287. package/src/lib/search-engine/document/base.document.ts +2 -2
  288. package/src/lib/search-engine/interface/search-document.interface.ts +10 -2
  289. package/src/lib/search-engine/schema/generic.schema.ts +1 -1
  290. package/src/lib/search-engine/schema/index.ts +1 -1
  291. package/src/lib/search-engine/typesense/collection/index.ts +1 -0
  292. package/src/lib/search-engine/typesense/document/index.ts +1 -0
  293. package/src/lib/search-engine/typesense/index.ts +4 -3
  294. package/src/lib/search-engine/typesense/service/client.service.ts +260 -258
  295. package/src/lib/storage/index.ts +0 -0
  296. package/src/lib/typesense/client/index.ts +1 -0
  297. package/src/lib/typesense/collection/index.ts +1 -0
  298. package/src/lib/typesense/collection/typesense-colletctions.creator.ts +29 -0
  299. package/src/lib/typesense/decorator/field.decorator.spec.ts +89 -0
  300. package/src/lib/typesense/decorator/field.decorator.ts +44 -0
  301. package/src/lib/typesense/decorator/index.ts +2 -0
  302. package/src/lib/typesense/decorator/schema.decorator.ts +23 -0
  303. package/src/lib/typesense/document/base.document.ts +3 -0
  304. package/src/lib/typesense/document/index.ts +1 -0
  305. package/src/lib/typesense/index.ts +6 -0
  306. package/src/lib/typesense/metadata/index.ts +4 -0
  307. package/src/lib/typesense/metadata/schema.metadata.ts +21 -0
  308. package/src/lib/typesense/metadata/typesense.metadata-accessor.ts +37 -0
  309. package/src/lib/typesense/metadata/typesense.metadata-explorer.spec.ts +56 -0
  310. package/src/lib/typesense/metadata/typesense.metadata-explorer.ts +41 -0
  311. package/src/lib/typesense/metadata/typesense.metadata-registry.ts +28 -0
  312. package/src/lib/typesense/module/index.ts +4 -0
  313. package/src/lib/typesense/module/interface.module.ts +36 -0
  314. package/src/lib/typesense/module/typesense.constant.ts +1 -0
  315. package/src/lib/typesense/module/typesense.module.spec.ts +94 -0
  316. package/src/lib/typesense/module/typesense.module.ts +87 -0
  317. package/src/lib/typesense/module/typesense.provider.ts +54 -0
  318. package/src/response/base-entity.response.ts +8 -0
  319. package/src/response/index.ts +2 -1
  320. package/src/response/login.response.ts +0 -0
  321. package/src/response/pagination.response.ts +52 -37
  322. package/src/setup/microservice.setup.ts +29 -29
  323. package/src/util/app.utils.ts +18 -18
  324. package/src/util/index.ts +1 -0
  325. package/src/util/validate-config.ts +20 -0
@@ -0,0 +1,2 @@
1
+ export * from './mailer.module';
2
+ export * from './mailer.service';
@@ -0,0 +1,8 @@
1
+ import { Module } from '@nestjs/common';
2
+ import { MailerService } from './mailer.service';
3
+
4
+ @Module({
5
+ providers: [MailerService],
6
+ exports: [MailerService],
7
+ })
8
+ export class MailerModule {}
@@ -0,0 +1,53 @@
1
+ import fs from 'node:fs/promises';
2
+ import Handlebars from 'handlebars';
3
+ import nodemailer from 'nodemailer';
4
+ import { Injectable } from '@nestjs/common';
5
+ import { ConfigService } from '@nestjs/config';
6
+ import { AllConfigType } from '../../config';
7
+
8
+ @Injectable()
9
+ export class MailerService {
10
+ private readonly transporter: nodemailer.Transporter;
11
+ constructor(private readonly configService: ConfigService<AllConfigType>) {
12
+ this.transporter = nodemailer.createTransport({
13
+ host: configService.get('mail.host', { infer: true }),
14
+ port: configService.get('mail.port', { infer: true }),
15
+ ignoreTLS: configService.get('mail.ignoreTLS', { infer: true }),
16
+ secure: configService.get('mail.secure', { infer: true }),
17
+ requireTLS: configService.get('mail.requireTLS', { infer: true }),
18
+ auth: {
19
+ user: configService.get('mail.user', { infer: true }),
20
+ pass: configService.get('mail.password', { infer: true }),
21
+ },
22
+ });
23
+ }
24
+
25
+ async sendMail({
26
+ templatePath,
27
+ context,
28
+ ...mailOptions
29
+ }: nodemailer.SendMailOptions & {
30
+ templatePath: string;
31
+ context: Record<string, unknown>;
32
+ }): Promise<void> {
33
+ let html: string | undefined;
34
+ if (templatePath) {
35
+ const template = await fs.readFile(templatePath, 'utf-8');
36
+ html = Handlebars.compile(template, {
37
+ strict: true,
38
+ })(context);
39
+ }
40
+
41
+ await this.transporter.sendMail({
42
+ ...mailOptions,
43
+ from: mailOptions.from
44
+ ? mailOptions.from
45
+ : `"${this.configService.get('mail.defaultName', {
46
+ infer: true,
47
+ })}" <${this.configService.get('mail.defaultEmail', {
48
+ infer: true,
49
+ })}>`,
50
+ html: mailOptions.html ? mailOptions.html : html,
51
+ });
52
+ }
53
+ }
File without changes
@@ -1,3 +1,3 @@
1
1
  export class BaseDocument {
2
- id: string;
3
- }
2
+ id?: string;
3
+ }
@@ -1,5 +1,13 @@
1
- import { SearchOptions, SearchParams, SearchResponse, DocumentSchema } from 'typesense/lib/Typesense/Documents';
1
+ import {
2
+ SearchOptions,
3
+ SearchParams,
4
+ SearchResponse,
5
+ DocumentSchema,
6
+ } from 'typesense/lib/Typesense/Documents';
2
7
 
3
8
  export interface SearchDocumentService<Document extends DocumentSchema> {
4
- searchDocument(searchParameters: SearchParams, options: SearchOptions): Promise<SearchResponse<any>>;
9
+ searchDocument(
10
+ searchParameters: SearchParams,
11
+ options: SearchOptions,
12
+ ): Promise<SearchResponse<Document>>;
5
13
  }
@@ -1 +1 @@
1
- export class GenericSchema {}
1
+ export class GenericSchema {}
@@ -1 +1 @@
1
- export * from './generic.schema';
1
+ export * from './generic.schema';
@@ -0,0 +1 @@
1
+ export * from 'typesense/lib/Typesense/Collections';
@@ -0,0 +1 @@
1
+ export * from 'typesense/lib/Typesense/Documents';
@@ -1,3 +1,4 @@
1
- export * from './typesense.module';
2
- export * from './metadata';
3
- export * from './service';
1
+ export * from './typesense.module';
2
+ export * from './metadata';
3
+ export * from './service';
4
+ export * from './document';
@@ -1,258 +1,260 @@
1
- import { Client } from 'typesense';
2
- import { Logger, Type } from '@nestjs/common';
3
- import { plainToClass } from 'class-transformer';
4
- import { CollectionCreateSchema } from 'typesense/lib/Typesense/Collections';
5
- import {
6
- SearchParams,
7
- SearchOptions,
8
- SearchResponse,
9
- DeleteResponse,
10
- ImportResponse,
11
- } from 'typesense/lib/Typesense/Documents';
12
- import { BaseDocument } from '../../document';
13
- import { SearchDocumentService } from '../../interface';
14
- import { EntityGeneric } from '../../../../generic';
15
- import { PaginationResponse } from '../../../../response';
16
-
17
- export abstract class ClientService<
18
- Document extends BaseDocument,
19
- Entity extends EntityGeneric,
20
- > implements SearchDocumentService<Document>
21
- {
22
- protected readonly entity: Type<Entity>;
23
- protected abstract cache_s: number;
24
- protected readonly skipCheckSchema: boolean = false;
25
- constructor(
26
- protected readonly client: Client,
27
- protected readonly schema: CollectionCreateSchema,
28
- protected readonly prefix: string,
29
- ) {
30
- if (!this.skipCheckSchema && schema != null) {
31
- this.ensureCollection();
32
- }
33
- }
34
-
35
- // searchDocument(searchParameters: SearchParams, options: SearchOptions) {
36
- // const {
37
- // per_page = 25,
38
- // filter_by,
39
- // archived = false,
40
- // } = { ...searchParameters };
41
- // searchParameters.per_page = per_page;
42
- // return this.client.collections(this?.schema?.name || this.prefix).documents().search(searchParameters, options);
43
- // }
44
-
45
- async searchDocument(
46
- searchParameters: SearchParams,
47
- options: SearchOptions,
48
- ): Promise<SearchResponse<any>> {
49
- try {
50
- const { includeIds = [], per_page = 25 } = { ...searchParameters };
51
- // TODO: should be support with include/exclude ids.
52
- const includeDocuments = [];
53
- if (includeIds.length > 0) {
54
- const includeOpts = {
55
- ...searchParameters,
56
- filter_by: `id:=[${includeIds.join(', ')}]`,
57
- };
58
- const includeDocs = await this.client
59
- .collections(this?.schema?.name || this.prefix)
60
- .documents()
61
- .search(includeOpts, options);
62
- if (includeDocs?.hits?.length > 0) {
63
- const names = includeDocs.hits.map(
64
- (data: Record<string, any>) => data.document.name,
65
- );
66
- searchParameters.filter_by =
67
- searchParameters.filter_by == null
68
- ? `name:!=[${names.join(', ')}]`
69
- : `${searchParameters.filter_by} && name:!=[${names.join(', ')}]`;
70
- searchParameters.per_page = per_page - names.length;
71
- }
72
- includeDocuments.push(...includeDocs?.hits);
73
- }
74
- const documents = await this.client
75
- .collections(this?.schema?.name || this.prefix)
76
- .documents()
77
- .search(searchParameters, options);
78
- if (includeDocuments.length > 0) {
79
- documents.hits.push(...includeDocuments);
80
- documents.request_params.per_page = per_page;
81
- }
82
- return documents;
83
- } catch (error) {
84
- return null;
85
- }
86
- }
87
-
88
- getAllRawDocs = async (
89
- searchParameters: SearchParams,
90
- options: SearchOptions,
91
- ) => {
92
- searchParameters.per_page = searchParameters.per_page ?? 250;
93
- options.cacheSearchResultsForSeconds = 1;
94
- const response = await this.searchDocument(searchParameters, options);
95
- const { hits = [], found = 0, page = 1 } = response;
96
- let documents = hits;
97
- const hasNext = hits.length * page < found;
98
- if (hasNext) {
99
- searchParameters.page = page + 1;
100
- documents = await this.getAllRawDocs(searchParameters, options);
101
- }
102
- return documents;
103
- };
104
-
105
- async importIndex(data: Document[]): Promise<ImportResponse[]> {
106
- if (data.length > 0) {
107
- try {
108
- return this.client
109
- .collections(this?.schema?.name || this.prefix)
110
- .documents()
111
- .import(data, { action: 'upsert' });
112
- } catch (error) {
113
- console.log(error);
114
- }
115
- }
116
- }
117
-
118
- async deleteOutOfDate(data: string[] | number[], key: string): Promise<any> {
119
- if (data?.length > 0) {
120
- const deleteParameters = {
121
- filter_by: `${key}:!=[${data.join(', ')}]`,
122
- };
123
- return await this.client
124
- .collections(this?.schema?.name || this.prefix)
125
- .documents()
126
- .delete(deleteParameters);
127
- }
128
- }
129
-
130
- async insertIndex(data: Document): Promise<any> {
131
- return this.client
132
- .collections(this?.schema?.name || this.prefix)
133
- .documents()
134
- .create(data, { action: 'upsert' });
135
- }
136
-
137
- async updateIndex(data: Document): Promise<any> {
138
- return this.client
139
- .collections(this?.schema?.name || this.prefix)
140
- .documents()
141
- .upsert(data, { action: 'upsert' });
142
- }
143
-
144
- updateDocumentById = async (data: Document) => {
145
- if (data?.id) {
146
- const exist = await this.client
147
- .collections(this?.schema?.name || this.prefix)
148
- .documents(data.id)
149
- .retrieve();
150
- if (exist) {
151
- return this.client
152
- .collections(this?.schema?.name || this.prefix)
153
- .documents(data.id)
154
- .update(data);
155
- }
156
- }
157
- };
158
-
159
- async upsertOrDeleteIndex(datas: Document) {
160
- throw new Error('Method is not implement.');
161
- }
162
-
163
- async deleteIndex(data: Document): Promise<DeleteResponse> {
164
- return this.client
165
- .collections(this?.schema?.name || this.prefix)
166
- .documents()
167
- .delete({ filter_by: `id: ${data.id}` });
168
- }
169
-
170
- async deleteBatchIndex(ids: string[]): Promise<DeleteResponse> {
171
- return this.client
172
- .collections(this?.schema?.name || this.prefix)
173
- .documents()
174
- .delete({ filter_by: `id: [${ids.join(',')}]` });
175
- }
176
-
177
- async deleteIndexByKeyValue(
178
- key = 'id',
179
- value: number,
180
- ): Promise<DeleteResponse> {
181
- return this.client
182
- .collections(this?.schema?.name || this.prefix)
183
- .documents()
184
- .delete({ filter_by: `${key}:=${value}` });
185
- }
186
-
187
- transforms = (
188
- searchResponse: SearchResponse<Record<string, unknown>>,
189
- ): Entity[] => {
190
- const entities: Entity[] = [];
191
- const { hits = [] } = { ...searchResponse };
192
- for (const hit of hits) {
193
- const document = hit?.document;
194
- if (document) {
195
- const entity = plainToClass(this.entity, document);
196
- entity.id = Number(document.id);
197
- entities.push(entity);
198
- }
199
- }
200
- return entities;
201
- };
202
-
203
- transform = (
204
- searchResponse: SearchResponse<Record<string, unknown>>,
205
- ): Entity => {
206
- let entity: Entity = null;
207
- const { hits = [] } = { ...searchResponse };
208
- for (const hit of hits) {
209
- const document = hit?.document;
210
- if (document) {
211
- entity = plainToClass(this.entity, document);
212
- entity.id = Number(document.id);
213
- }
214
- break;
215
- }
216
- return entity;
217
- };
218
-
219
- responseList = (
220
- searchResponse: SearchResponse<Record<string, unknown>>,
221
- offset = 0,
222
- ): PaginationResponse<Entity> => {
223
- const entities: Entity[] = [];
224
- const {
225
- hits = [],
226
- found = 0,
227
- page = 1,
228
- request_params,
229
- } = { ...searchResponse };
230
- for (const hit of hits) {
231
- const document = hit?.document;
232
- if (document) {
233
- const entity = plainToClass(this.entity, document);
234
- entity.id = Number(document.id);
235
- entities.push(entity);
236
- }
237
- }
238
-
239
- const limit = request_params?.per_page;
240
-
241
- // offset = offset ?? (page - 1) * limit;
242
-
243
- return new PaginationResponse(entities, found, limit, offset);
244
- };
245
-
246
- private ensureCollection = async (): Promise<void> => {
247
- this.checkSchemaName();
248
- const exists = await this.client.collections(this.schema.name).exists();
249
- if (!exists) {
250
- await this.client.collections().create(this.schema);
251
- }
252
- };
253
-
254
- private checkSchemaName = (): void => {
255
- const schemaName = this.schema.name.replace(/.*?\_/gi, '');
256
- this.schema.name = `${this.prefix}_${schemaName}`;
257
- };
258
- }
1
+ import { Client } from 'typesense';
2
+ import { Logger, Type } from '@nestjs/common';
3
+ import { plainToClass } from 'class-transformer';
4
+ import { CollectionCreateSchema } from '../collection';
5
+ import {
6
+ SearchParams,
7
+ SearchOptions,
8
+ SearchResponse,
9
+ DeleteResponse,
10
+ ImportResponse,
11
+ } from '../document';
12
+ import { BaseDocument } from '../../document';
13
+ import { SearchDocumentService } from '../../interface';
14
+ import { EntityGeneric } from '../../../../generic';
15
+ import { PaginationResponse } from '../../../../response';
16
+
17
+ export abstract class ClientService<
18
+ Document extends BaseDocument,
19
+ Entity extends EntityGeneric,
20
+ > implements SearchDocumentService<Document>
21
+ {
22
+ private readonly logger = new Logger(ClientService.name);
23
+ protected readonly entity: Type<Entity>;
24
+ protected abstract cache_s: number;
25
+ protected readonly skipCheckSchema: boolean = false;
26
+ constructor(
27
+ protected readonly client: Client,
28
+ protected readonly schema: CollectionCreateSchema,
29
+ protected readonly prefix: string,
30
+ ) {
31
+ if (!this.skipCheckSchema && schema != null) {
32
+ this.ensureCollection();
33
+ }
34
+ }
35
+
36
+ // searchDocument(searchParameters: SearchParams, options: SearchOptions) {
37
+ // const {
38
+ // per_page = 25,
39
+ // filter_by,
40
+ // archived = false,
41
+ // } = { ...searchParameters };
42
+ // searchParameters.per_page = per_page;
43
+ // return this.client.collections(this?.schema?.name || this.prefix).documents().search(searchParameters, options);
44
+ // }
45
+
46
+ async searchDocument(
47
+ searchParameters: SearchParams,
48
+ options: SearchOptions,
49
+ ): Promise<SearchResponse<any>> {
50
+ try {
51
+ const { includeIds = [], per_page = 25 } = { ...searchParameters };
52
+ // TODO: should be support with include/exclude ids.
53
+ const includeDocuments = [];
54
+ if (includeIds.length > 0) {
55
+ const includeOpts = {
56
+ ...searchParameters,
57
+ filter_by: `id:=[${includeIds.join(', ')}]`,
58
+ };
59
+ const includeDocs = await this.client
60
+ .collections(this?.schema?.name || this.prefix)
61
+ .documents()
62
+ .search(includeOpts, options);
63
+ if (includeDocs?.hits?.length > 0) {
64
+ const names = includeDocs.hits.map(
65
+ (data: Record<string, any>) => data.document.name,
66
+ );
67
+ searchParameters.filter_by =
68
+ searchParameters.filter_by == null
69
+ ? `name:!=[${names.join(', ')}]`
70
+ : `${searchParameters.filter_by} && name:!=[${names.join(', ')}]`;
71
+ searchParameters.per_page = per_page - names.length;
72
+ }
73
+ includeDocuments.push(...includeDocs?.hits);
74
+ }
75
+ const documents = await this.client
76
+ .collections(this?.schema?.name || this.prefix)
77
+ .documents()
78
+ .search(searchParameters, options);
79
+ if (includeDocuments.length > 0) {
80
+ documents.hits.push(...includeDocuments);
81
+ documents.request_params.per_page = per_page;
82
+ }
83
+ return documents;
84
+ } catch (error) {
85
+ this.logger.error(error);
86
+ return null;
87
+ }
88
+ }
89
+
90
+ getAllRawDocs = async (
91
+ searchParameters: SearchParams,
92
+ options: SearchOptions,
93
+ ) => {
94
+ searchParameters.per_page = searchParameters.per_page ?? 250;
95
+ options.cacheSearchResultsForSeconds = 1;
96
+ const response = await this.searchDocument(searchParameters, options);
97
+ const { hits = [], found = 0, page = 1 } = response;
98
+ let documents = hits;
99
+ const hasNext = hits.length * page < found;
100
+ if (hasNext) {
101
+ searchParameters.page = page + 1;
102
+ documents = await this.getAllRawDocs(searchParameters, options);
103
+ }
104
+ return documents;
105
+ };
106
+
107
+ async importIndex(data: Document[]): Promise<ImportResponse[]> {
108
+ if (data.length > 0) {
109
+ try {
110
+ return this.client
111
+ .collections(this?.schema?.name || this.prefix)
112
+ .documents()
113
+ .import(data, { action: 'upsert' });
114
+ } catch (error) {
115
+ this.logger.error(error);
116
+ }
117
+ }
118
+ }
119
+
120
+ async deleteOutOfDate(data: string[] | number[], key: string): Promise<any> {
121
+ if (data?.length > 0) {
122
+ const deleteParameters = {
123
+ filter_by: `${key}:!=[${data.join(', ')}]`,
124
+ };
125
+ return await this.client
126
+ .collections(this?.schema?.name || this.prefix)
127
+ .documents()
128
+ .delete(deleteParameters);
129
+ }
130
+ }
131
+
132
+ async insertIndex(data: Document): Promise<any> {
133
+ return this.client
134
+ .collections(this?.schema?.name || this.prefix)
135
+ .documents()
136
+ .create(data, { action: 'upsert' });
137
+ }
138
+
139
+ async updateIndex(data: Document): Promise<any> {
140
+ return this.client
141
+ .collections(this?.schema?.name || this.prefix)
142
+ .documents()
143
+ .upsert(data, { action: 'upsert' });
144
+ }
145
+
146
+ updateDocumentById = async (data: Document) => {
147
+ if (data?.id) {
148
+ const exist = await this.client
149
+ .collections(this?.schema?.name || this.prefix)
150
+ .documents(data.id)
151
+ .retrieve();
152
+ if (exist) {
153
+ return this.client
154
+ .collections(this?.schema?.name || this.prefix)
155
+ .documents(data.id)
156
+ .update(data);
157
+ }
158
+ }
159
+ };
160
+
161
+ async upsertOrDeleteIndex(datas: Document) {
162
+ throw new Error('Method is not implement.');
163
+ }
164
+
165
+ async deleteIndex(data: Document): Promise<DeleteResponse> {
166
+ return this.client
167
+ .collections(this?.schema?.name || this.prefix)
168
+ .documents()
169
+ .delete({ filter_by: `id: ${data.id}` });
170
+ }
171
+
172
+ async deleteBatchIndex(ids: string[]): Promise<DeleteResponse> {
173
+ return this.client
174
+ .collections(this?.schema?.name || this.prefix)
175
+ .documents()
176
+ .delete({ filter_by: `id: [${ids.join(',')}]` });
177
+ }
178
+
179
+ async deleteIndexByKeyValue(
180
+ key = 'id',
181
+ value: number,
182
+ ): Promise<DeleteResponse> {
183
+ return this.client
184
+ .collections(this?.schema?.name || this.prefix)
185
+ .documents()
186
+ .delete({ filter_by: `${key}:=${value}` });
187
+ }
188
+
189
+ transforms = (
190
+ searchResponse: SearchResponse<Record<string, unknown>>,
191
+ ): Entity[] => {
192
+ const entities: Entity[] = [];
193
+ const { hits = [] } = { ...searchResponse };
194
+ for (const hit of hits) {
195
+ const document = hit?.document;
196
+ if (document) {
197
+ const entity = plainToClass(this.entity, document);
198
+ entity.id = Number(document.id);
199
+ entities.push(entity);
200
+ }
201
+ }
202
+ return entities;
203
+ };
204
+
205
+ transform = (
206
+ searchResponse: SearchResponse<Record<string, unknown>>,
207
+ ): Entity => {
208
+ let entity: Entity = null;
209
+ const { hits = [] } = { ...searchResponse };
210
+ for (const hit of hits) {
211
+ const document = hit?.document;
212
+ if (document) {
213
+ entity = plainToClass(this.entity, document);
214
+ entity.id = Number(document.id);
215
+ }
216
+ break;
217
+ }
218
+ return entity;
219
+ };
220
+
221
+ responseList = (
222
+ searchResponse: SearchResponse<Record<string, unknown>>,
223
+ offset = 0,
224
+ ): PaginationResponse<Entity> => {
225
+ const entities: Entity[] = [];
226
+ const {
227
+ hits = [],
228
+ found = 0,
229
+ page = 1,
230
+ request_params,
231
+ } = { ...searchResponse };
232
+ for (const hit of hits) {
233
+ const document = hit?.document;
234
+ if (document) {
235
+ const entity = plainToClass(this.entity, document);
236
+ entity.id = Number(document.id);
237
+ entities.push(entity);
238
+ }
239
+ }
240
+
241
+ const limit = request_params?.per_page;
242
+
243
+ // offset = offset ?? (page - 1) * limit;
244
+
245
+ return new PaginationResponse(entities, found, limit, offset);
246
+ };
247
+
248
+ private ensureCollection = async (): Promise<void> => {
249
+ this.checkSchemaName();
250
+ const exists = await this.client.collections(this.schema.name).exists();
251
+ if (!exists) {
252
+ await this.client.collections().create(this.schema);
253
+ }
254
+ };
255
+
256
+ private checkSchemaName = (): void => {
257
+ const schemaName = this.schema.name.replace(/.*?\_/gi, '');
258
+ this.schema.name = `${this.prefix}_${schemaName}`;
259
+ };
260
+ }
File without changes
@@ -0,0 +1 @@
1
+ export { Client } from 'typesense';
@@ -0,0 +1 @@
1
+ export * from './typesense-colletctions.creator';